The new bbPress standalone plugin for WP is great. It makes sense for this to be implemented as a plugin, using custom post types as it does. One limitation to the current version of the plugin is that forums can be either public to all or private to all (based on role). If you don’t want to get into the mess of defining roles for your users to manage different forums or if you are already using Paid Memberships Pro, below is a good solution for locking down bbPress forums based on PMPro membership levels.

We have released a Paid Memberships Pro – bbPress Add On which replaces the recipe below. See the add on documentation here

To get this to work, you must have your forums and membership levels created. The forums should be set as “public” in bbPress. Then update the $restricted_forums array in the code below and place it in your functions.php or somewhere else where it will be run. Enjoy!


This entry was posted in General and tagged . Bookmark the permalink. Last updated:

Comments (29)

Author’s gravatar

What update do we have to do on the “$restricted_forums array” ?

Reply
Author’s gravatar

Here is the code from the sample:
$restricted_forums[207] = array(1,2);

This means restrict forum ID # 207 to membership levels 1 and 2.

So replace 207 with the ID of your forum. And replace 1,2 with a comma separated list of your membership levels.

If you have more than one forum you want to lock down. Then add an additional line. e.g.

$restricted_forums[207] = array(1); //the level 1 forum
$restricted_forums[208] = array(2); //the level 2 forum

Hope this helps.

Reply
Author’s gravatar

Click on the Forums link in your admin sidebar. Then click to edit the forum. Note the # where is says e.g. “?post=23”. That is the id of your forum. Good luck.

Author’s gravatar

This plugin is all I needed. Unfortunately it doesn’t work for me ๐Ÿ™

I’m using the latest versions of WP, PMP and BBpress. I’m sure the id and array levels in $restricted_forums are right. And it’s still viewable by users with no membership level or users not even logged in.

Reply
Author’s gravatar

Going through old comments here. Sorry I missed you. Did you ever get this working? Not sure what was happening on your site. You could sign up for support to get help.

Reply
Author’s gravatar

This has worked pretty good, thanks!

Question: The Forum listing is being blocked or the home page for the forums. Is there a way to add the bbPress homepage as well?

Reply
Author’s gravatar

Just did this for a client. Add this code to the bottom of _check_forum()

//lock down the archive also
if(bbp_is_forum_archive() && !pmpro_hasMembershipLevel(2))
{
	wp_redirect(pmpro_url("account"));
	exit;
}
Reply
Author’s gravatar

Jason, thanks for this. The code works well, but the functionality is a bit annoying for new visitors when they click on the forum link and are blindly redirected back to the forum page. It makes viewers think the site is broken.

What do you recommend as far as a message that the forums are for members only? Is there additional code that can be put in here, or should we change the forum slug on line 30 to redirect to the sales landing page?

Reply
Author’s gravatar

By default it redirects to the levels page. We are thinking the best bet is to throw an alert on this page saying which levels can access the forums. Something along the lines of “The forum you are trying to access is for level a, level b and level c users only. Please select a membership level below to gain access.”

Reply
Author’s gravatar

After adding this I am getting:
Warning: Cannot modify header information – headers already sent by…

Reply
Author’s gravatar

The rest of that error would be useful in figuring it out. I made a couple tweaks to the code that should avoid some warnings. Try it again.

Reply
Author’s gravatar

Added this code and a message at the top as an alert for non-members…one question.
Non-members can still click and see member profiles…is there any way to block that, as well?
I’d rather keep member profiles private to just students inside my class.
Thanks!

Reply
Author’s gravatar

You can lock that down by URL. See how we do it here with BuddyPress pages:
https://gist.github.com/strangerstudios/3111478#file-gistfile1-txt-L17

Same idea for bbPress pages and other times you want to lock down a URL or group of URLs.

Reply
Author’s gravatar

Thanks, Jason. Looking at the code now…Could you direct me to which line of code I would need to change to lockdown the member profiles? I’m having trouble finding where I would need ti put that.
Thanks so much!

Author’s gravatar

The code to restrict users from accessing bbpress with PMPro works great. How can I modify it to redirect users to a page saying “This content is for Free Membership, All Access Monthly and All Access (3 Months) members only.” etc., like my regular pages that I tack off “Require Membership” do? Thank you!

Reply
Author’s gravatar

See the line `wp_redirect(home_url(“/forums/”));`. You’ll want to change that to redirect to a page you make with the wording you want.

Reply
Author’s gravatar

is there a way you can set this up for me i am lost as hell or could you make a youtube tutoral step by step in how to lock down the latest version of this

Reply
Author’s gravatar

We’re working on a better plugin version of this. I’ll try to accelerate that to get it out this week. Stay tuned to the blog.

Reply
Author’s gravatar

Hi Jason,

I came across this snippet https://gist.github.com/strangerstudios/3111478#file-gistfile1-txt-L17
Because I want to avoid that a ‘Freemember’ has access to PM, Friend Requests, Blog, Forum etc…

How can I insert this?

I also came across this code but this doesn’t work at all

add_filter( ‘bp_rate_limit_pm_count’, ‘pmpro_message_limit_ehnhance’, 10, 2 );

function pmpro_message_limit_ehnhance( $limit, $user_id ){
//future proofing
if( !function_exists( ‘pmpro_hasMembershipLevel’ ) )
return $limit;

if( pmpro_hasMembershipLevel( ‘Level1’, $user_id ) )
$limit = 0;//change it
elseif( pmpro_hasMembershipLevel( ‘Level2’, $user_id ) )
$limit = 999999; //change it

elseif( pmpro_hasMembershipLevel( ‘Level3’, $user_id ) )
$limit = 999999;//change it

return $limit;
}

add_filter( ‘bp_limit_friendship_count’, ‘pmpro_friends_limit_ehnhance’, 10, 2 );

function pmpro_friends_limit_ehnhance( $limit, $user_id ){
//future proofing
if( !function_exists( ‘pmpro_hasMembershipLevel’ ) )
return $limit;

if( pmpro_hasMembershipLevel( ‘Level1’, $user_id ) )
$limit = 0;//change it
elseif( pmpro_hasMembershipLevel( ‘Level2’, $user_id ) )
$limit = 999999; //change it

elseif( pmpro_hasMembershipLevel( ‘Level3’, $user_id ) )
$limit = 999999;//change it

return $limit;
}

I thought I can restrict with this code that a Level1 Member can send messages or friend requests….but unfortunately not working.

Please help ๐Ÿ™

Reply
Author’s gravatar

Mad, sorry you’re having trouble. This isn’t a quick fix, but we can help you in the paid member forums. Post something there. Thanks.

Reply

Leave a Reply

Your email address will not be published. Required fields are marked *