Created
March 11, 2019 14:43
-
-
Save rmpel/0c74d3dcb5bc83cc0afafe68b7717db0 to your computer and use it in GitHub Desktop.
Auto-balance HTML for ContactForm 7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* WHY? Because invalid HTML will break a page, will break visible form feedback. | |
* Still, WHY? Well, you are right, CF7 should do this all on their own. | |
*/ | |
add_action( 'wpcf7_save_contact_form', function(WPCF7_ContactForm $contact_form) { | |
// this is an action, contact_form not given as pointer, so get the pointer from CF7; | |
$cf = WPCF7_ContactForm::get_current(); | |
// get the properties, we need to change the form | |
$props = $cf->get_properties(); | |
// auto-balance HTML for the form data | |
$props['form'] = force_balance_tags( $props['form'] ); | |
// save the new properties | |
$cf->set_properties($props); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment