-
-
Save shimondoodkin/4590833 to your computer and use it in GitHub Desktop.
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
/* | |
These next two functions work together to lock down bbPress forums based on PMPro membership level. | |
Check that the current user has access to this forum. Be sure to update the $restricted_forums array based on your needs. | |
*/ | |
function pmpro_check_forum() | |
{ | |
global $current_user; | |
/* | |
This array denotes which forums require which membership level. | |
The format is $restricted_forums[forum_id] = array(membership_id, membership_id, membership_id, etc) | |
*/ | |
$restricted_forums[207] = array(1,2); | |
//is this even a forum page at all? | |
if(!bbp_is_forum_archive() && pmpro_bbp_is_forum()) | |
{ | |
//now check this post | |
foreach($restricted_forums as $forum_id => $membership_levels) | |
{ | |
if(pmpro_bbp_is_forum($forum_id)) | |
{ | |
//we found the forum, now check the membership level | |
if(pmpro_hasMembershipLevel($membership_levels)) | |
return true; | |
else | |
{ | |
//need to redirect away | |
//wp_redirect("/forums/"); // not working headers already sent | |
while(ob_get_level())ob_end_clean(); | |
//fix to yours url where to redirect to | |
echo "<script type=\"text/javascript\">location.href='/membership-account/membership-levels'</script>"; | |
return false; | |
} | |
} | |
} | |
} | |
} | |
add_action("wp", "pmpro_check_forum"); | |
/* | |
Function to tell if the current forum, topic, or reply is a subpost of the forum_id passed. | |
If no forum_id is passed, it will return true if it is any forum, topic, or reply. | |
*/ | |
function pmpro_bbp_is_forum($forum_id = NULL) | |
{ | |
global $post; | |
if(bbp_is_forum($post->ID)) | |
{ | |
if($forum_id && $post->ID == $forum_id) | |
return true; | |
elseif(!$forum_id) | |
return true; | |
else | |
return false; | |
} | |
elseif(bbp_is_topic($post->ID)) | |
{ | |
if($forum_id && $post->post_parent == $forum_id) | |
return true; | |
elseif(!$forum_id) | |
return true; | |
else | |
return false; | |
} | |
elseif(bbp_is_reply($post->ID)) | |
{ | |
if($forum_id && in_array($forum_id, $post->ancestors)) | |
return true; | |
elseif(!$forum_id) | |
return true; | |
else | |
return false; | |
} | |
else | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i have added the contents of this file to the end of paid-memberships-pro/paid-memberships-pro.php