| @@ -32,9 +32,9 @@ | ||
| 32 | 32 | * |
| 33 | 33 | * Integration for Contact Form 7. |
| 34 | 34 | * Handles opt-in creation, confirmation mail sending, and admin panel. |
| 35 | 35 | */ |
| 36 | -class CF7Integration extends AbstractFormIntegration implements AdminPanelInterface { | |
| 36 | +class CF7Integration extends AbstractFormIntegration implements AdminPanelInterface, FieldTextProviderInterface { | |
| 37 | 37 | |
| 38 | 38 | /** |
| 39 | 39 | * Current OptIn for mail attachment handling. |
| 40 | 40 | * |
| @@ -906,8 +906,45 @@ | ||
| 906 | 906 | } |
| 907 | 907 | } |
| 908 | 908 | |
| 909 | 909 | return $fields; |
| 910 | + } | |
| 911 | + | |
| 912 | + /** | |
| 913 | + * The text of each [acceptance]…[/acceptance] tag, as the visitor reads it. | |
| 914 | + * | |
| 915 | + * @param int|string $formId | |
| 916 | + * | |
| 917 | + * @return array<string, string> | |
| 918 | + */ | |
| 919 | + public function getFieldTexts( $formId ): array { | |
| 920 | + $formId = (int) $formId; | |
| 921 | + $post = get_post( $formId ); | |
| 922 | + if ( ! $post || $post->post_type !== 'wpcf7_contact_form' || ! class_exists( '\WPCF7_ContactForm' ) ) { | |
| 923 | + return array(); | |
| 924 | + } | |
| 925 | + | |
| 926 | + $contactForm = \WPCF7_ContactForm::get_instance( $formId ); | |
| 927 | + if ( ! $contactForm ) { | |
| 928 | + return array(); | |
| 929 | + } | |
| 930 | + | |
| 931 | + $texts = array(); | |
| 932 | + foreach ( $contactForm->scan_form_tags( array( 'basetype' => 'acceptance' ) ) as $tag ) { | |
| 933 | + $text = self::plainText( (string) ( $tag->content ?? '' ) ); | |
| 934 | + if ( ! empty( $tag->name ) && $text !== '' ) { | |
| 935 | + $texts[ (string) $tag->name ] = $text; | |
| 936 | + } | |
| 937 | + } | |
| 938 | + return $texts; | |
| 939 | + } | |
| 940 | + | |
| 941 | + /** | |
| 942 | + * Markup as the visitor reads it: tags removed, whitespace collapsed. | |
| 943 | + */ | |
| 944 | + public static function plainText( string $html ): string { | |
| 945 | + $text = html_entity_decode( wp_strip_all_tags( $html ), ENT_QUOTES, 'UTF-8' ); | |
| 946 | + return trim( (string) preg_replace( '/\s+/u', ' ', $text ) ); | |
| 910 | 947 | } |
| 911 | 948 | |
| 912 | 949 | /** |
| 913 | 950 | * Add editor panel to CF7. |