iaincrossley (@iaincrossley)

Forum Replies Created

Viewing 1 replies (of 1 total)

  • iaincrossley
    Participant

    @iaincrossley

    Just replying to myself on here, given the lack of interaction, with the solution to this.

    Place the following code in your theme’s functions.php – this will allow mapping of a particular WLM membership level to the bbPress Participant level:

    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');

    I used the Members plugin to create a platinumplus user role that then mapped to the WLM level of the same name, and the above code then mapped that role to the appropriate bbPress one. Obvs, any instances of ‘platinumplus’ have to be amended to the role you are intending to map.

Viewing 1 replies (of 1 total)