I considered Buddypress, but it’s way more robust than what I’m needing, and installing it was breaking my custom theme (jquery conflict somewhere).
Thanks for looking at this.
For anyone else out there, here’s my solution for restricting bbPress access using s2member. In short, this checks if the current user has access to the most distant ancestor of the current page. For example:
Level 1 Forum/Category > Subforum1 > Subcategory > Subforum2 > Current Topic
No matter which page they arrive at in the tree, they must have access via s2member to the top-most level. Then it’s a simple matter of assigning a ccap to that Forum, or a membership level.
1. Include the following in your functions.php file
2. Include a call to the function in EACH of your bbPress template files BEFORE the template calls for the forum content. Match the HTML structure of the error message to suit your theme. You need to include closing tags for any open divs.
3. Test!
/******* bbPress Forum Access *******/
function checkForumAccess() {
if(get_post_type() == 'forum' OR get_post_type() == 'topic' OR get_post_type() == 'reply') { // check if user is viewing a forum page. If so, continue.
//check if they have access to the top-most parent forum/category (both are Pages in wordpress). If not, show the error verbiage. If they have access, continue and show the content like normal
$parent = array_reverse(get_post_ancestors($post->ID)); // get an array of all the parent pages in order from most distant to closest.
$first_parent = get_page($parent[0]); //get the first page in the array, which is the most distant parent
$int = apply_filters(‘the_ID’, $first_parent->ID); //filter the $first_parent to get only the wordpress page/post ID, which is an integer like 49 or 565. store it as a variable $int
if (!is_page_permitted_by_s2member($int)) { // this is an s2member function. Check if the current user can access the $first_parent, via the stored page/post ID in the $int variable
// here comes your custom error message. Remember to escape any apostrophes
echo ‘
<div>
<h1 class=”entry-title”>Sorry!</h1>
<div class=”entry-content”>
<p>It looks like you don’t have access to this forum.</p>
<p>If this is an error and you should have access, please contact us here: (contact URL)
</div>
</div><!–.postWrapper–>
</div><!– #content –>
</div><!– #contentWrapper –>
</div><!– #primary –>
‘;
get_sidebar();
get_footer();
exit; // Important. This prevents the rest of the page (the secure forum content) from displaying
}
}
}