Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
Last active April 23, 2024 12:52
Show Gist options
  • Save strangerstudios/e6838523a273cf744cfc to your computer and use it in GitHub Desktop.
Save strangerstudios/e6838523a273cf744cfc to your computer and use it in GitHub Desktop.
Protect a specific page with PMPro
/*
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