Last active
April 23, 2024 12:52
-
-
Save strangerstudios/e6838523a273cf744cfc to your computer and use it in GitHub Desktop.
Protect a specific page with PMPro
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
/* | |
Protect a specific page with PMPro | |
Edit the code below to check your specific page slug and membership level ID. | |
Add this code to your active theme's functions.php or a custom plugin. | |
*/ | |
function protect_specific_page() | |
{ | |
//make sure PMPro is active | |
if(!function_exists('pmpro_hasMembershipLevel')) | |
return; | |
if(is_page('my-page-slug']) && !pmpro_hasMembershipLevel()) //can add level id or array as parameter to check for specific level(s) | |
{ | |
wp_redirect(pmpro_url('levels')); | |
exit; | |
} | |
} | |
add_action('template_redirect', 'protect_specific_page'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment