wpcf7_quiz_form_tag_handler()
Хуков нет.
Возвращает
null. Ничего (null).
Использование
wpcf7_quiz_form_tag_handler( $tag );
- $tag(обязательный)
- .
Код wpcf7_quiz_form_tag_handler() wpcf7 quiz form tag handler CF7 6.1.6
function wpcf7_quiz_form_tag_handler( $tag ) {
if ( empty( $tag->name ) ) {
return '';
}
$validation_error = wpcf7_get_validation_error( $tag->name );
$class = wpcf7_form_controls_class( $tag->type );
if ( $validation_error ) {
$class .= ' wpcf7-not-valid';
}
$atts = array();
$atts['size'] = $tag->get_size_option( '40' );
$atts['maxlength'] = $tag->get_maxlength_option();
$atts['minlength'] = $tag->get_minlength_option();
if ( $atts['maxlength'] and $atts['minlength']
and $atts['maxlength'] < $atts['minlength'] ) {
unset( $atts['maxlength'], $atts['minlength'] );
}
$atts['class'] = $tag->get_class_option( $class );
$atts['id'] = $tag->get_id_option();
$atts['tabindex'] = $tag->get_option( 'tabindex', 'signed_int', true );
$atts['autocomplete'] = 'off';
$atts['aria-required'] = 'true';
if ( $validation_error ) {
$atts['aria-invalid'] = 'true';
$atts['aria-describedby'] = wpcf7_get_validation_error_reference(
$tag->name
);
} else {
$atts['aria-invalid'] = 'false';
}
$pipes = $tag->pipes;
if ( $pipes instanceof WPCF7_Pipes
and ! $pipes->zero() ) {
$pipe = $pipes->random_pipe();
$question = $pipe->before;
$answer = $pipe->after;
} else {
// default quiz
$question = '1+1=?';
$answer = '2';
}
$answer = wpcf7_canonicalize( $answer, array(
'strip_separators' => true,
) );
$atts['type'] = 'text';
$atts['name'] = $tag->name;
$html = sprintf(
'<span class="wpcf7-form-control-wrap" data-name="%1$s"><label><span class="wpcf7-quiz-label">%2$s</span> <input %3$s /></label><input type="hidden" name="_wpcf7_quiz_answer_%4$s" value="%5$s" />%6$s</span>',
esc_attr( $tag->name ),
esc_html( $question ),
wpcf7_format_atts( $atts ),
$tag->name,
wp_hash( $answer, 'wpcf7_quiz' ),
$validation_error
);
return $html;
}