Skip to content

Commit

Permalink
Enable native WP shortcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
kasparsd committed Jan 20, 2025
1 parent f980e97 commit 60343cd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/class-cf7-extras-form-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
34 changes: 34 additions & 0 deletions src/class-cf7-extras.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
Expand Down Expand Up @@ -233,6 +235,20 @@ public function wpcf7_metabox( $cf7 ) {
__( 'Same as <code>define( \'WPCF7_AUTOP\', false );</code>.', '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(
'<label>
<input id="extra-enable-shortcodes" name="extra[enable-shortcodes]" value="1" %s type="checkbox" />
<span>%s</span>
</label>
<p class="desc">%s</p>',
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/',
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit 60343cd

Please sign in to comment.