Created
March 9, 2016 17:38
-
-
Save strangerstudios/9a125089ffe7eef2f34f to your computer and use it in GitHub Desktop.
Run PMPro shortcodes later to avoid issues with the_content filters/etc
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
/* | |
Run PMPro shortcodes later to avoid issues with the_content filters/etc | |
Add this code to your active theme's functions.php or a custom plugin. | |
You may need to change the priority of the add_filter calls below to get the desired result. | |
*/ | |
//this function removes the shortcodes to keep them from being messed with | |
function pmpro_shortcodes_later_prep($content) { | |
$shortcodes = array('pmpro_account', 'pmpro_billing', 'pmpro_cancel', 'pmpro_checkout', 'pmpro_confirmation', 'pmpro_invoice', 'pmpro_levels'); | |
foreach($shortcodes as $shortcode) { | |
$content = str_replace("[" . $shortcode . "]", "<!-- PMPROSHORTCODEREPLACE " . $shortcode . " PMPROSHORTCODEREPLACE -->", $content); | |
} | |
return $content; | |
} | |
add_filter('the_content', 'pmpro_shortcodes_later_prep', 1); | |
//this function adds the shortcodes back in later | |
function pmpro_shortcodes_later_restore($content) { | |
$shortcodes = array('pmpro_account', 'pmpro_billing', 'pmpro_cancel', 'pmpro_checkout', 'pmpro_confirmation', 'pmpro_invoice', 'pmpro_levels'); | |
foreach($shortcodes as $shortcode) { | |
$content = str_replace("<!-- PMPROSHORTCODEREPLACE " . $shortcode . " PMPROSHORTCODEREPLACE -->", do_shortcode("[" . $shortcode . "]"), $content); | |
} | |
return $content; | |
} | |
add_filter('the_content', 'pmpro_shortcodes_later_restore', 100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This recipe is included in the blog post on "Filter Members Only Content Later (for Page Builders and Certain Plugin Conflicts)" at Paid Memberships Pro here: https://www.paidmembershipspro.com/filter-members-only-content-later-for-page-builders-and/