Created
October 13, 2015 00:36
-
-
Save greathmaster/0608b216fe916cc7d80d to your computer and use it in GitHub Desktop.
Only show levels on levels page which the original referral page belonged to.
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
/* | |
Only show levels on level page which the original content belonged to. For example if a site has 3 levels: Bronze, Silver, Gold and | |
a post is restricted to Silver and Gold, clicking on the "Register" button will lead them to the levels page showing only Silver and Gold levels. | |
To use: employ the shortcode [my_level_link] under Memberships >> Advanced >> Message for Logged-out Users (or Message for Logged-in Non-members) | |
Ex: | |
This content is for !!levels!! members only.<br /><a href="http://example.com/wp-login.php">Log In</a> <a href="[my_level_link]">Register</a> | |
*/ | |
function my_level_link() | |
{ | |
global $post; | |
$hasAccess = pmpro_has_membership_access($post->ID, null, true); | |
$access = site_url()."/membership-account/membership-levels/?"; | |
foreach($hasAccess[1] as $key => $value) | |
{ | |
$access = $access."levels[]=".$value."&"; | |
} | |
return $access; | |
} | |
add_shortcode('my_level_link', 'my_level_link'); | |
function my_pmpro_levels_array($levels) | |
{ | |
$allowed_levels = $_REQUEST['levels']; | |
$newlevels = array(); | |
foreach($levels as $level) | |
{ | |
if(in_array($level->id, $allowed_levels)) | |
$newlevels[] = $level; | |
} | |
return $newlevels; | |
} | |
add_filter("pmpro_levels_array", "my_pmpro_levels_array"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Forked to add a check if going to levels page from a direct link no on a protected page https://gist.github.com/kimwhite/2ff0eff060badbbebbddfcf20cc74269