Skip to:
Content
Pages
Categories
Search
Top
Bottom

Correlating WP roles with BBPress roles


  • christopheran
    Participant

    @christopheran

    I’m setting up my BBPress forum right now.

    Looking at BBPress roles… is there a way to tie BBPress roles to WP user roles.

    For example, I would like my WP editors to automatically be BBPress moderators, and for contributors and subscribers to be BBPress participants.

    Is that possible?

    Chris

Viewing 7 replies - 1 through 7 (of 7 total)

  • Robin W
    Moderator

    @robin-w

    it would be code-able, but I don’t know of anything that does this already


    Robin W
    Moderator

    @robin-w

    not tested, but the following in your functions file should do it

    you’ll need to edit the code for which role does what

    add_action('wp_login', 'rew_assign_role_on_login', 10, 2);
    
    //this function assigns user to bbp roles on login
    function rew_assign_role_on_login($user_login, $user) {
    	$user_id = $user->ID ; 
    	$role = get_role($use_id) ; 
    	if (empty ($role)) return ; //has no role in the database
    	if ($role == 'administrator' )  $new_role = 'bbp_keymaster' ;
    	if ($role == 'editor' )  $new_role = 'bbp_moderator' ;
    	if ($role == 'author' )  $new_role = 'bbp_moderator' ;
    	if ($role == 'contributor' )  $new_role = 'bbp_participant' ;
    	if ($role == 'visitor' )  $new_role = 'bbp_blocked' ;
    	if ($role == 'subscriber' )  $new_role = 'bbp_spectator' ;
    	bbp_set_user_role( $user_id, $new_role) 
    	}

    Robkk
    Moderator

    @robkk

    I say edit Robin’s code and change

    if ($role == 'subscriber' ) $new_role = 'bbp_spectator' ;

    To this.

    if ($role == 'subscriber' ) $new_role = 'bbp_participant' ;

    And in my opinion you should not auto-assign moderators and just manually update the users roles for each of the users you trust to moderate the forums. Also I am not sure there is a visitor WordPress role.

    https://codex.wordpress.org/Roles_and_Capabilities#Summary_of_Roles


    Robin W
    Moderator

    @robin-w

    Also I am not sure there is a visitor WordPress role.

    oops… no there isn’t – old code left on my test site !

    and who gets what were just examples 🙂


    christopheran
    Participant

    @christopheran

    Thank you both very much – I am testing this out right now!


    Robin W
    Moderator

    @robin-w

    great – to help others please post back your solution if successful, or come back for further help !


    zirow
    Participant

    @zirow

    I’ve tried @robin-w snippit above but didnt work with my current wordpress version(latest one according to the date of my post) but i managed to get it working with this snippit if anyone needs it.

    Note: I’m a beginner to wordpress and bbpress so there might be other better ways of doing this.

    function change_role(){
    $user_id = $user->ID ;
    if( current_user_can(‘administrator’)){

    bbp_set_user_role( $user_id, ‘bbp_keymaster’ );

    }
    }
    add_action(‘wp_login’, ‘change_role’);

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.
Skip to toolbar