From c28acba519d716e9ed93e5d164472b5edcd96fa4 Mon Sep 17 00:00:00 2001 From: Kaspars Dambis Date: Mon, 20 Jan 2025 17:32:32 +0200 Subject: [PATCH 1/8] =?UTF-8?q?Ensure=20we=20reset=20early=20so=20we=20don?= =?UTF-8?q?=E2=80=99t=20replace=20the=20work=20of=20others?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/class-cf7-extras.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/class-cf7-extras.php b/src/class-cf7-extras.php index c756007..392ba26 100644 --- a/src/class-cf7-extras.php +++ b/src/class-cf7-extras.php @@ -108,7 +108,14 @@ public function init() { add_action( 'wpcf7_submit', array( $this, 'wpcf7_submit' ), 987, 2 ); // TODO: Enable Google analytics tracking when AJAX is disabled. - add_filter( 'wpcf7_form_elements', array( $this, 'maybe_reset_autop' ) ); + + /** + * Use a filter instead of the WPCF7_AUTOP to disable formatting on specific forms only. + * + * Run very early since we're replacing the rendered form content with a fresh + * version that doesn't have the autop applied. + */ + add_filter( 'wpcf7_form_elements', array( $this, 'maybe_reset_autop' ), 1 ); $integrations = array( new Cf7_Extras_Integration_TablePress(), From f980e9702a4f7e9dbb8a4efc70c44ee589461a74 Mon Sep 17 00:00:00 2001 From: Kaspars Dambis Date: Mon, 20 Jan 2025 17:45:49 +0200 Subject: [PATCH 2/8] Match the actual input --- src/class-cf7-extras.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/class-cf7-extras.php b/src/class-cf7-extras.php index 392ba26..af2c5c3 100644 --- a/src/class-cf7-extras.php +++ b/src/class-cf7-extras.php @@ -675,9 +675,9 @@ public function wpcf7_submit( $form, $result ) { * Maybe disable WP core autop() on form email contents * by re-parsing the form content without the autop. * - * @param WPCF7_ContactForm $form Current CF7 form. + * @param string $form Current CF7 form. * - * @return WPCF7_ContactForm + * @return string */ public function maybe_reset_autop( $form ) { $form_instance = WPCF7_ContactForm::get_current(); From 60343cd9cf85f60d8a0d8bca7513752661f5dcf8 Mon Sep 17 00:00:00 2001 From: Kaspars Dambis Date: Mon, 20 Jan 2025 17:49:55 +0200 Subject: [PATCH 3/8] Enable native WP shortcodes --- src/class-cf7-extras-form-settings.php | 1 + src/class-cf7-extras.php | 34 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/class-cf7-extras-form-settings.php b/src/class-cf7-extras-form-settings.php index 8319693..43215ac 100644 --- a/src/class-cf7-extras-form-settings.php +++ b/src/class-cf7-extras-form-settings.php @@ -16,6 +16,7 @@ class Cf7_Extras_Form_Settings { 'html5-disable' => false, 'html5-fallback' => false, 'disable-autop' => false, + 'enable-shortcodes' => false, 'redirect-success' => false, 'track-ga-success' => false, 'track-ga-submit' => false, diff --git a/src/class-cf7-extras.php b/src/class-cf7-extras.php index af2c5c3..12f7c5c 100644 --- a/src/class-cf7-extras.php +++ b/src/class-cf7-extras.php @@ -117,6 +117,8 @@ public function init() { */ add_filter( 'wpcf7_form_elements', array( $this, 'maybe_reset_autop' ), 1 ); + add_filter( 'wpcf7_form_elements', array( $this, 'maybe_enable_shortcodes' ) ); + $integrations = array( new Cf7_Extras_Integration_TablePress(), ); @@ -233,6 +235,20 @@ public function wpcf7_metabox( $cf7 ) { __( 'Same as define( \'WPCF7_AUTOP\', false );.', 'contact-form-7-extras' ) ), ), + 'extra-enable-shortcodes' => array( + 'label' => __( 'Enable Shortcodes', 'contact-form-7-extras' ), + 'docs_url' => 'https://formcontrols.com/docs/enable-wordpress-shortcodes', + 'field' => sprintf( + ' +

%s

', + checked( $settings['enable-shortcodes'], true, false ), + esc_html__( 'Enable WordPress shortcodes', 'contact-form-7-extras' ), + esc_html__( 'Adds support for standard WordPress shortcodes in the form content.', 'contact-form-7-extras' ) + ), + ), 'extra-html5' => array( 'label' => __( 'HTML5 input types', 'contact-form-7-extras' ), 'docs_url' => 'http://contactform7.com/faq/does-contact-form-7-support-html5-input-types/', @@ -704,6 +720,24 @@ public function maybe_reset_autop( $form ) { return $form; } + /** + * Maybe enable WordPress shortcodes in the form content. + * + * @param string $form Current CF7 form content + * + * @return string + */ + public function maybe_enable_shortcodes( $form ) { + $form_instance = WPCF7_ContactForm::get_current(); + $enable_shortcodes = $this->get_form_settings( $form_instance, 'enable-shortcodes' ); + + if ( $enable_shortcodes ) { + $form = do_shortcode( $form ); + } + + return $form; + } + /** * Register an error for the current request. * From c9c5e5e3e06078fac469e60ca929765f68a921d6 Mon Sep 17 00:00:00 2001 From: Kaspars Dambis Date: Mon, 20 Jan 2025 17:54:59 +0200 Subject: [PATCH 4/8] Remove old notices --- readme.txt.md | 8 -------- 1 file changed, 8 deletions(-) diff --git a/readme.txt.md b/readme.txt.md index 14b342f..2144b89 100644 --- a/readme.txt.md +++ b/readme.txt.md @@ -103,11 +103,3 @@ The "[Storage for Contact Form 7](https://preseto.com/go/cf7-storage?utm_source= ### 0.9.0 New feature: enable storing form submissions in TablePress plugin tables. - -### 0.8.0 - -Use the suggested Google Global Site Tag (gtag.js) event structure. This will make the "Contact Form" events appear in both Google Analytics and Google Tag Manager. - -### 0.7.3 - -Compatibility with the Javascript event changes in the latest version 5.2 of the Contact Form 7 plugin. From 5a2b20712d4caa84b794cf11ee7fae7048a2348d Mon Sep 17 00:00:00 2001 From: Kaspars Dambis Date: Mon, 20 Jan 2025 17:55:06 +0200 Subject: [PATCH 5/8] Bump the version --- plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.php b/plugin.php index 542df30..55f7437 100644 --- a/plugin.php +++ b/plugin.php @@ -5,7 +5,7 @@ * Plugin URI: https://formcontrols.com * Author: Kaspars Dambis * Author URI: https://formcontrols.com - * Version: 0.9.0 + * Version: 0.10.0 * License: GPL2 * Text Domain: contact-form-7-extras */ From 8a890d00277fedb36149e2738a5a10a3c4d58807 Mon Sep 17 00:00:00 2001 From: Kaspars Dambis Date: Mon, 20 Jan 2025 18:03:27 +0200 Subject: [PATCH 6/8] Introduce a dedicated field rendered with some HTML --- src/class-cf7-extras.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/class-cf7-extras.php b/src/class-cf7-extras.php index 12f7c5c..c1211df 100644 --- a/src/class-cf7-extras.php +++ b/src/class-cf7-extras.php @@ -181,6 +181,22 @@ public function wpcf7_add_meta_boxes( $post_id ) { ); } + private function esc_field_label( $label ) { + return wp_kses( + $label, + array( + 'a' => array( + 'href' => array(), + 'target' => array(), + ), + 'strong' => array(), + 'em' => array(), + 'span' => array(), + 'code' => array(), + ) + ); + } + /** * Display our custom form settings. * @@ -204,7 +220,7 @@ public function wpcf7_metabox( $cf7 ) {

%s

', checked( $settings['disable-ajax'], true, false ), esc_html__( 'Disable AJAX for this form', 'contact-form-7-extras' ), - __( 'Same as define( \'WPCF7_LOAD_JS\', false );. Disabling AJAX will also disable Google Analytics event tracking and HTML5 input type fallback for this form.', 'contact-form-7-extras' ) + $this->esc_field_label( __( 'Same as define( \'WPCF7_LOAD_JS\', false );. Disabling AJAX will also disable Google Analytics event tracking and HTML5 input type fallback for this form.', 'contact-form-7-extras' ) ) ), ), 'extra-disable-css' => array( @@ -218,7 +234,7 @@ public function wpcf7_metabox( $cf7 ) {

%s

', checked( $settings['disable-css'], true, false ), esc_html__( 'Disable default CSS for this form', 'contact-form-7-extras' ), - __( 'Disables CSS that comes bundled with Contact Form 7. Same as define( \'WPCF7_LOAD_CSS\', false );.', 'contact-form-7-extras' ) + $this->esc_field_label( __( 'Disables CSS that comes bundled with Contact Form 7. Same as define( \'WPCF7_LOAD_CSS\', false );.', 'contact-form-7-extras' ) ) ), ), 'extra-disable-autop' => array( @@ -232,7 +248,7 @@ public function wpcf7_metabox( $cf7 ) {

%s

', checked( $settings['disable-autop'], true, false ), esc_html__( 'Disable automatic paragraph formatting in form output', 'contact-form-7-extras' ), - __( 'Same as define( \'WPCF7_AUTOP\', false );.', 'contact-form-7-extras' ) + $this->esc_field_label( __( 'Same as define( \'WPCF7_AUTOP\', false );.', 'contact-form-7-extras' ) ) ), ), 'extra-enable-shortcodes' => array( From 675b17caf5b4dfebead4182015ed63e629d84369 Mon Sep 17 00:00:00 2001 From: Kaspars Dambis Date: Mon, 20 Jan 2025 18:05:01 +0200 Subject: [PATCH 7/8] Describe the method --- src/class-cf7-extras.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/class-cf7-extras.php b/src/class-cf7-extras.php index c1211df..3a214bd 100644 --- a/src/class-cf7-extras.php +++ b/src/class-cf7-extras.php @@ -181,6 +181,13 @@ public function wpcf7_add_meta_boxes( $post_id ) { ); } + /** + * Sanitize the field label with a few allowed HTML tags. + * + * @param string $label Field label markup. + * + * @return string + */ private function esc_field_label( $label ) { return wp_kses( $label, @@ -739,7 +746,7 @@ public function maybe_reset_autop( $form ) { /** * Maybe enable WordPress shortcodes in the form content. * - * @param string $form Current CF7 form content + * @param string $form Current CF7 form content. * * @return string */ From fa6c531b5f41bbf9750d036d8085f829342357b7 Mon Sep 17 00:00:00 2001 From: Kaspars Dambis Date: Mon, 20 Jan 2025 18:06:39 +0200 Subject: [PATCH 8/8] Mention the shortcode support --- readme.txt.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/readme.txt.md b/readme.txt.md index 2144b89..0800aa1 100644 --- a/readme.txt.md +++ b/readme.txt.md @@ -18,12 +18,13 @@ Analytics, tracking, redirects and storage for Contact Form 7. This is an addon for the [Contact Form 7](https://wordpress.org/plugins/contact-form-7/) plugin with the following features: - [Track form submissions, errors and completions](https://formcontrols.com/docs) with Google Analytics (GA4), Google Tag (gtag.js), Google Tag Manager (GTM), Matomo (formerly Piwik) and Facebook Pixel. -- Redirect to URL on form submission -- Disable AJAX form submissions -- Disable default form CSS -- Disable automatic paragraph formatting -- Disable HTML5 input field types or enable the HTML5 input type fallback -- Specify the Google reCAPTCHA language +- Redirect to URL on form submission. +- Enable native WordPress shortcodes in form content. +- Disable AJAX form submissions. +- Disable default form CSS. +- Disable automatic paragraph formatting. +- Disable HTML5 input field types or enable the HTML5 input type fallback. +- Specify the Google reCAPTCHA language. - Store form submissions in [Storage for Contact Form 7](https://preseto.com/go/cf7-storage?utm_source=wporg) or [TablePress](https://wordpress.org/plugins/tablepress/). Please note that some settings work on the per-page level and will apply to all forms on the same page. For example, disabling AJAX form submissions for one form will disable AJAX submissions on all forms on the same page.