Skip to content

Instantly share code, notes, and snippets.

@dparker1005
Created August 22, 2017 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dparker1005/5f1a26414735423936487bdb26b2a22a to your computer and use it in GitHub Desktop.
Save dparker1005/5f1a26414735423936487bdb26b2a22a to your computer and use it in GitHub Desktop.
Redirects non-users from blog to levels page in PMPro
/*
Redirect away from certain URLs with PMPro.
Be careful, the code will redirect any URL *containing* the strings in the $urls array.
So e.g., if /not-locked/about/ is public and you have /about/ in the list, it will still be locked down to non-members.
*/
function pmpro_hide_urls()
{
//make sure PMPro is activated
if(!function_exists('pmpro_hasMembershipLevel'))
return;
elseif(pmpro_hasMembershipLevel()) //or if they have any membership level, let them in
return;
//get URI
$uri = $_SERVER['REQUEST_URI'];
//update this array
$not_allowed = array(
"/blog/", //the location of the blog
);
//check them
foreach($not_allowed as $check)
{
if(strpos(strtolower($uri), strtolower($check)) !== false)
{
wp_redirect(pmpro_url('levels'));
exit;
}
}
}
add_action("init", "pmpro_hide_urls");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment