Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
Created November 5, 2014 22:49
Show Gist options
  • Save strangerstudios/82cf0a970bcf82b64572 to your computer and use it in GitHub Desktop.
Save strangerstudios/82cf0a970bcf82b64572 to your computer and use it in GitHub Desktop.
Redirect away from certain URLs with PMPro.
/*
Redirect away from certain URLs with PMPro.
Becareful, 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.
*/
//hide some pages in buddypress
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(
"/members/",
"/groups/",
"/groups/create/"
);
//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