Skip to:
Content
Pages
Categories
Search
Top
Bottom

New role not available in version 2.5.12


  • Chad R. Schulz
    Participant

    @chadschulz

    I’ve added a dynamic role to my forums that no longer appears in any display user role capacity.
    I used the bbp_get_dynamic_roles hook as before.

    However, the capabilities from this role do transfer over–just not the name.

    I’m using custom functions that require this role’s name be defined. So basically this update breaks my site.

    Any attempt to role back to an earlier version of bbPress seems to crash the site.

    Help!?

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

  • Chad R. Schulz
    Participant

    @chadschulz

    OK. Well after some harrowing attempts to rebuild from older versions of bbPress and WordPress I ended up reverting back to the most recent of both, 4.7 and 2.5.12, respectively.

    And presto! Everything is now as it should be. WTF?!

    Maybe something got fouled up in the DB conversion or I simply needed to kick something loose.

    Anyway, nevermind.

    Thanks.

    Can you share your code for how you’re defining your custom roles please?

    If you’d rather keep the code private you could join the #bbPress channel in Slack

    You can sign up for WordPress Slack here: https://chat.wordpress.org


    Chad R. Schulz
    Participant

    @chadschulz

    Sure,

    I’ve been going with Star Trek ranks;-)

    function my_custom_roles( $role, $user_id ) {
      if($role){
        switch ($role) {
          case 'Participant': $role = 'Ensign'; break;
          case 'Keymaster': $role = 'Captain'; break;
          case 'Moderator': $role = 'Commander'; break;
          case 'Blocked': $role = 'Banned'; break;
          case 'Spectator': $role = 'Visitor'; break;  
        }
      }
      return $role;  
    }
    add_filter( 'bbp_get_user_display_role', 'my_custom_roles', 10, 2 );
    
    function add_new_roles( $bbp_roles )
    {
        /* Add a role called lieutenant */
        $bbp_roles['bbp_lieutenant'] = array(
            'name' => 'Lieutenant',
            'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() ),
            );
     
        return $bbp_roles;
    } 
    add_filter( 'bbp_get_dynamic_roles', 'add_new_roles',  1 );

    As I said, things are all working properly now without any issues.

    But, maybe there’s a deeper problem during the update process that might be affecting others as well.

    Anyhoo, Thanks.
    Chad

    Thanks @chadschulz is this more along the lines of what you are after?

    A quick modification of your code above, with some tweaks via https://codex.bbpress.org/custom-capabilities/

    
    function chadschulz_bbpress_customized_roles( $bbp_roles ) {
    	// Keymaster -> Captain
    	$bbp_roles['bbp_keymaster'] = array(
    		'name'         => 'Captain',
    		'capabilities' => bbp_get_caps_for_role( bbp_get_keymaster_role() )
    	);
    	// Moderator -> Commander
    	$bbp_roles['bbp_moderator'] = array(
    		'name'         => 'Commander',
    		'capabilities' => bbp_get_caps_for_role( bbp_get_moderator_role() )
    	);
    	// Participant -> Ensign
    	$bbp_roles['bbp_participant'] = array(
    		'name'         => 'Ensign',
    		'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() )
    	);
    	// Spectator -> Visitor
    	$bbp_roles['bbp_spectator'] = array(
    		'name'         => 'Visitor',
    		'capabilities' => bbp_get_caps_for_role( bbp_get_spectator_role() )
    	);
    	// Blocked -> Banned
    	$bbp_roles['bbp_blocked'] = array(
    		'name'         => 'Banned',
    		'capabilities' => bbp_get_caps_for_role( bbp_get_blocked_role() )
    	);
    	// Lieutenant (Based on Participant role caps)
    	$bbp_roles['bbp_lieutenant'] = array(
    		'name' => 'Lieutenant',
    		'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() )
    	);
    	return $bbp_roles;
    }
    add_filter( 'bbp_get_dynamic_roles', 'chadschulz_bbpress_customized_roles' );
    

    Chad R. Schulz
    Participant

    @chadschulz

    A much appreciated restructuring.

    This simplifies a lot by renaming the core roles from within both front-end and back-end user role editors.

    Love learning new code/tricks.

    Thanks,
    Chad

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