Created
August 22, 2017 18:25
-
-
Save dparker1005/5f1a26414735423936487bdb26b2a22a to your computer and use it in GitHub Desktop.
Redirects non-users from blog to levels page in 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
/* | |
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