Force assign Wishlist Member level to bbPress user role?

Hi,

Not sure if I can ask this here with my current membership level, so here goes nothing :wink:

I am working on a live project at the moment which is requiring the addition of BuddyPress and bbPress functionality to a membership site running on Wishlist Member. Specs for the site as follows:

WP: 3.6.1
bbPress: 2.4
BuddyPress: 1.8.1
Wishlist Member: 2.71.1440
Site URL: http://www.thelawofattraction.com

Because of the way in which WLM works it has also been necessary to install the Change Roles For WLM extension to make the upgrade to paid process work properly. This checks on login which role is assigned to an individual user and makes sure to map them to the upgraded role if they have paid.

The paid level is Platinum+ which I created a separate role for - platinumplus, and the default role for bbPress is set to Blocked to keep out everyone else.

I used the following code in my theme's functions.php to map platinumplus membership level to the participant role:

add_filter('bbp_get_user_role_map','custom_bbPress_role_map');
function custom_bbPress_role_map($role_map){
$role_map['platinumplus'] = bbp_get_participant_role();
return $role_map;
}

I then output the result of the following code to the screen:

$role_map  = bbp_get_user_role_map();
print_r($role_map);
global $current_user;
get_currentuserinfo();
echo 'User ID: ' . $current_user->ID;
$role = bbp_get_user_role( $current_user->ID );
echo $role;
$role_caps = bbp_get_caps_for_role( $current_user->ID );
print_r( $role_caps );

and get this:

Array ( [administrator] => bbp_keymaster [editor] => bbp_blocked [author] => bbp_blocked [contributor] => bbp_blocked [subscriber] => bbp_blocked [platinumplus] => bbp_participant ) User ID: 695
bbp_blocked
Array ( [spectate] => 1 [participate] => 1 [read_private_forums] => 1 [publish_topics] => 1 [edit_topics] => 1 [publish_replies] => 1 [edit_replies] => 1 [assign_topic_tags] => 1 )

So, it would appear that a user is getting remapped by the WLM extension to the default role of bbp_blocked on login.

My question therefore is this - is there a way in which I can force the role platinumplus to occupy the participant user role on login? All users are redirected to a membership dashboard on login and it is feasible for me to have some code fire on this page to make sure that the bbPress participant role gets assigned to Platinum+ members as it should be. Just don't know how to go about this.

Anyway, apologies for a possible wall of text - just wanted to be as thorough as possible in my first post :slight_smile: Any help at all would be much appreciated.

Best,
Iain

  • Iain

    Hi @aristath!

    Thanks for the reply - yeah, I've already approached them in this regard and am waiting for a reply, just thought I would see if anyone on here had any experience similar to my own. A longshot I appreciate, but Wishlist support tend to palm off (in my experience at least) any questions that relate to their plugin's interaction with plugins of the nature of bbPress and so on.

    Also, I don't seem to be able to post a new topic in the official bbPress forums at the moment :disappointed:

    I'll post here if I get a resolution to the issue just in case it helps anyone else in the future.

    Best,
    Iain

  • Iain

    Well, turns out that one of the devs at Wishlist was able to help out once my support ticket was escalated to him. Fel Jun - super helpful guy :slight_smile:

    Anyway, I'm going to post the solution that he provided below:

    function map_bbpress_user_role(){
    	//get the user class
    	$cu = wp_get_current_user();
    	$cu_roles = $cu->roles; //get the user roles
    	if(in_array("administrator", $cu_roles)) return; //disregard if admin
    
    	$isplatinumplus =  in_array("platinumplus", $cu_roles); //check if it has platinumplus role
    	$isblocked = array_search(bbp_get_blocked_role(),$cu_roles); //check if it has bbp_blocked role
    
    	if($isplatinumplus){ //if it has platinumplus role
    		$cu->add_role(bbp_get_participant_role()); //add aparticipant role
    
    		if($isblocked !== false){ //if it has bbp_blocked role
    			$cu->remove_role(bbp_get_blocked_role()); //remove it
    		}
    	}elseif($isblocked === false){ //if he is not platinumplus and dont have bbp_blocked
    		/*
    		* 	This part makes sure that only platinumplus roles have access to the forum
    		*/
    		$cu->add_role(bbp_get_blocked_role()); //add bbp_blocked
    	}
    }
    add_action('init','map_bbpress_user_role');

    This goes in your theme's functions.php - all instances of 'platinumplus' will need replacing with the user role you are mapping to the Participant role. Works like a charm for me, so maybe someone else will find it helpful in the future.

    Best,
    Iain

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.