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 by Jason Coleman in General and tagged . Bookmark the permalink. Last updated: January 18, 2012. Titled Lockdown bbPress (WP Plugin) Forums Using Paid Memberships Pro

Comments (29)

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.

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.

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.

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?

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;
}

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?

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.”

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!

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!

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!

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 ๐Ÿ™

Leave a Reply

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