akismet
11 months ago
constant-contact
9 months ago
recaptcha
9 months ago
sendinblue
9 months ago
stripe
9 months ago
turnstile
8 months ago
acceptance.php
11 months ago
checkbox.php
9 months ago
count.php
1 year ago
date.php
7 months ago
disallowed-list.php
9 months ago
doi-helper.php
4 years ago
file.php
11 months ago
flamingo.php
9 months ago
hidden.php
7 years ago
listo.php
2 years ago
number.php
7 months ago
quiz.php
11 months ago
really-simple-captcha.php
6 months ago
reflection.php
3 years ago
response.php
6 years ago
select.php
7 months ago
submit.php
11 months ago
text.php
7 months ago
textarea.php
7 months ago
reflection.php
119 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Reflection module |
| 4 | * |
| 5 | * @link https://contactform7.com/reflection/ |
| 6 | */ |
| 7 | |
| 8 | |
| 9 | add_action( 'wpcf7_init', 'wpcf7_add_form_tag_reflection', 10, 0 ); |
| 10 | |
| 11 | /** |
| 12 | * Registers reflection-related form-tag types. |
| 13 | */ |
| 14 | function wpcf7_add_form_tag_reflection() { |
| 15 | wpcf7_add_form_tag( 'reflection', |
| 16 | 'wpcf7_reflection_form_tag_handler', |
| 17 | array( |
| 18 | 'name-attr' => true, |
| 19 | 'display-block' => true, |
| 20 | 'not-for-mail' => true, |
| 21 | ) |
| 22 | ); |
| 23 | |
| 24 | wpcf7_add_form_tag( 'output', |
| 25 | 'wpcf7_output_form_tag_handler', |
| 26 | array( |
| 27 | 'name-attr' => true, |
| 28 | 'not-for-mail' => true, |
| 29 | ) |
| 30 | ); |
| 31 | } |
| 32 | |
| 33 | |
| 34 | /** |
| 35 | * The form-tag handler for the reflection type. |
| 36 | */ |
| 37 | function wpcf7_reflection_form_tag_handler( $tag ) { |
| 38 | if ( empty( $tag->name ) ) { |
| 39 | return ''; |
| 40 | } |
| 41 | |
| 42 | $values = $tag->values ? $tag->values : array( '' ); |
| 43 | |
| 44 | if ( ! wpcf7_get_validation_error( $tag->name ) ) { |
| 45 | $hangover = array_filter( (array) wpcf7_get_hangover( $tag->name ) ); |
| 46 | |
| 47 | if ( $hangover ) { |
| 48 | $values = $hangover; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | $content = array_reduce( |
| 53 | $values, |
| 54 | static function ( $carry, $item ) use ( $tag ) { |
| 55 | $output_tag = sprintf( |
| 56 | '<output %1$s>%2$s</output>', |
| 57 | wpcf7_format_atts( array( |
| 58 | 'name' => $tag->name, |
| 59 | 'data-default' => $item, |
| 60 | ) ), |
| 61 | ( '' !== $item ) ? esc_html( $item ) : ' ' |
| 62 | ); |
| 63 | |
| 64 | return $carry . $output_tag; |
| 65 | }, |
| 66 | '' |
| 67 | ); |
| 68 | |
| 69 | $html = sprintf( |
| 70 | '<fieldset %1$s>%2$s</fieldset>', |
| 71 | wpcf7_format_atts( array( |
| 72 | 'data-reflection-of' => $tag->name, |
| 73 | 'class' => $tag->get_class_option( |
| 74 | wpcf7_form_controls_class( $tag->type ) |
| 75 | ), |
| 76 | 'id' => $tag->get_id_option(), |
| 77 | ) ), |
| 78 | $content |
| 79 | ); |
| 80 | |
| 81 | return $html; |
| 82 | } |
| 83 | |
| 84 | |
| 85 | /** |
| 86 | * The form-tag handler for the output type. |
| 87 | */ |
| 88 | function wpcf7_output_form_tag_handler( $tag ) { |
| 89 | if ( empty( $tag->name ) ) { |
| 90 | return ''; |
| 91 | } |
| 92 | |
| 93 | $value = (string) reset( $tag->values ); |
| 94 | |
| 95 | if ( ! wpcf7_get_validation_error( $tag->name ) ) { |
| 96 | $hangover = array_filter( (array) wpcf7_get_hangover( $tag->name ) ); |
| 97 | |
| 98 | if ( $hangover ) { |
| 99 | $value = (string) reset( $hangover ); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | $html = sprintf( |
| 104 | '<output %1$s>%2$s</output>', |
| 105 | wpcf7_format_atts( array( |
| 106 | 'data-reflection-of' => $tag->name, |
| 107 | 'data-default' => $value, |
| 108 | 'name' => $tag->name, |
| 109 | 'class' => $tag->get_class_option( |
| 110 | wpcf7_form_controls_class( $tag->type ) |
| 111 | ), |
| 112 | 'id' => $tag->get_id_option(), |
| 113 | ) ), |
| 114 | esc_html( $value ) |
| 115 | ); |
| 116 | |
| 117 | return $html; |
| 118 | } |
| 119 |