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 */ diff --git a/readme.txt.md b/readme.txt.md index 14b342f..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. @@ -103,11 +104,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. 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 c756007..3a214bd 100644 --- a/src/class-cf7-extras.php +++ b/src/class-cf7-extras.php @@ -108,7 +108,16 @@ 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 ); + + add_filter( 'wpcf7_form_elements', array( $this, 'maybe_enable_shortcodes' ) ); $integrations = array( new Cf7_Extras_Integration_TablePress(), @@ -172,6 +181,29 @@ 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, + array( + 'a' => array( + 'href' => array(), + 'target' => array(), + ), + 'strong' => array(), + 'em' => array(), + 'span' => array(), + 'code' => array(), + ) + ); + } + /** * Display our custom form settings. * @@ -195,7 +227,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( @@ -209,7 +241,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( @@ -223,7 +255,21 @@ 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( + '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( @@ -668,9 +714,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(); @@ -697,6 +743,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. *