From 60343cd9cf85f60d8a0d8bca7513752661f5dcf8 Mon Sep 17 00:00:00 2001 From: Kaspars Dambis Date: Mon, 20 Jan 2025 17:49:55 +0200 Subject: [PATCH] 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. *