Skip to:
Content
Pages
Categories
Search
Top
Bottom

User Roles – Adding/Renaming

  • @erich199

    Participant

    Hello,
    I’m trying to rename the current roles as well as ADD new roles. When I add the filter to change the current role name, it doesn’t add the new user role I’ve added. If I remove that code, then the new user role shows up.

    This is the code I’m using.

    //BBpress Custom Roles // 
    function add_new_roles( $bbp_roles )
    {
        /* Add a role called tutor */
        $bbp_roles['bbp_lead'] = array(
            'name' => 'Community Lead',
            'capabilities' => custom_capabilities( 'bbp_lead' )
            );
     
        return $bbp_roles;
    }
     
    add_filter( 'bbp_get_dynamic_roles', 'add_new_roles', 1 );
     
    function add_role_caps_filter( $caps, $role )
    {
        /* Only filter for roles we are interested in! */
        if( $role == 'bbp_lead' )
            $caps = custom_capabilities( $role );
     
        return $caps;
    }
     
    add_filter( 'bbp_get_caps_for_role', 'add_role_caps_filter', 10, 2 );
     
    function custom_capabilities( $role )
    {
        switch ( $role )
        {
     
            /* Capabilities for 'tutor' role */
            case 'bbp_lead':
                return array(
                    // Primary caps
                    'spectate'              => true,
                    'participate'           => true,
                    'moderate'              => true,
                    'throttle'              => false,
                    'view_trash'            => false,
     
                    // Forum caps
                    'publish_forums'        => false,
                    'edit_forums'           => false,
                    'edit_others_forums'    => false,
                    'delete_forums'         => false,
                    'delete_others_forums'  => false,
                    'read_private_forums'   => true,
                    'read_hidden_forums'    => true,
     
                    // Topic caps
                    'publish_topics'        => true,
                    'edit_topics'           => true,
                    'edit_others_topics'    => true,
                    'delete_topics'         => true,
                    'delete_others_topics'  => true,
                    'read_private_topics'   => true,
     
                    // Reply caps
                    'publish_replies'       => true,
                    'edit_replies'          => true,
                    'edit_others_replies'   => true,
                    'delete_replies'        => true,
                    'delete_others_replies' => true,
                    'read_private_replies'  => true,
     
                    // Topic tag caps
                    'manage_topic_tags'     => true,
                    'edit_topic_tags'       => true,
                    'delete_topic_tags'     => true,
                    'assign_topic_tags'     => true,
                );
     
                break;
     
            default :
                return $role;
        }
    }
    // End BBpress Custom Roles //
    
    //BBpress Rename Roles //
         /* BBPress Renaming Roles */
        add_filter( 'bbp_get_dynamic_roles', 'ntwb_bbpress_custom_role_names' );
        function ntwb_bbpress_custom_role_names() {
        return array(
        // Keymaster
        bbp_get_keymaster_role() => array(
        'name' => 'Administrator',
        'capabilities' => bbp_get_caps_for_role( bbp_get_keymaster_role() )
        ),
        // Moderator
        bbp_get_moderator_role() => array(
        'name' => 'Moderator',
        'capabilities' => bbp_get_caps_for_role( bbp_get_moderator_role() )
        ),
        // Participant
        bbp_get_participant_role() => array(
        'name' => 'Member',
        'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() )
        ),
        // Spectator
        bbp_get_spectator_role() => array(
        'name' => 'Spectator',
        'capabilities' => bbp_get_caps_for_role( bbp_get_spectator_role() )
        ),
        // Blocked
        bbp_get_blocked_role() => array(
        'name' => 'Blocked',
        'capabilities' => bbp_get_caps_for_role( bbp_get_blocked_role() )
        ));}
    //BBpress Rename Roles End //
Viewing 2 replies - 1 through 2 (of 2 total)
  • @robin-w

    Moderator

    The 2nd function assumes that you only have the default roles.

    Put this first and it should work ie

    //BBpress Rename Roles //
         /* BBPress Renaming Roles */
        add_filter( 'bbp_get_dynamic_roles', 'ntwb_bbpress_custom_role_names' , 1);
        function ntwb_bbpress_custom_role_names() {
        return array(
        // Keymaster
        bbp_get_keymaster_role() => array(
        'name' => 'Administrator',
        'capabilities' => bbp_get_caps_for_role( bbp_get_keymaster_role() )
        ),
        // Moderator
        bbp_get_moderator_role() => array(
        'name' => 'Moderator',
        'capabilities' => bbp_get_caps_for_role( bbp_get_moderator_role() )
        ),
        // Participant
        bbp_get_participant_role() => array(
        'name' => 'Member',
        'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() )
        ),
        // Spectator
        bbp_get_spectator_role() => array(
        'name' => 'Spectator',
        'capabilities' => bbp_get_caps_for_role( bbp_get_spectator_role() )
        ),
        // Blocked
        bbp_get_blocked_role() => array(
        'name' => 'Blocked',
        'capabilities' => bbp_get_caps_for_role( bbp_get_blocked_role() )
        ));}
    //BBpress Rename Roles End //
    
    //BBpress Custom Roles // 
    function add_new_roles( $bbp_roles )
    {
        /* Add a role called tutor */
        $bbp_roles['bbp_lead'] = array(
            'name' => 'Community Lead',
            'capabilities' => custom_capabilities( 'bbp_lead' )
            );
     
        return $bbp_roles;
    }
     
    add_filter( 'bbp_get_dynamic_roles', 'add_new_roles', 1 );
     
    function add_role_caps_filter( $caps, $role )
    {
        /* Only filter for roles we are interested in! */
        if( $role == 'bbp_lead' )
            $caps = custom_capabilities( $role );
     
        return $caps;
    }
     
    add_filter( 'bbp_get_caps_for_role', 'add_role_caps_filter', 10, 2 );
     
    function custom_capabilities( $role )
    {
        switch ( $role )
        {
     
            /* Capabilities for 'tutor' role */
            case 'bbp_lead':
                return array(
                    // Primary caps
                    'spectate'              => true,
                    'participate'           => true,
                    'moderate'              => true,
                    'throttle'              => false,
                    'view_trash'            => false,
     
                    // Forum caps
                    'publish_forums'        => false,
                    'edit_forums'           => false,
                    'edit_others_forums'    => false,
                    'delete_forums'         => false,
                    'delete_others_forums'  => false,
                    'read_private_forums'   => true,
                    'read_hidden_forums'    => true,
     
                    // Topic caps
                    'publish_topics'        => true,
                    'edit_topics'           => true,
                    'edit_others_topics'    => true,
                    'delete_topics'         => true,
                    'delete_others_topics'  => true,
                    'read_private_topics'   => true,
     
                    // Reply caps
                    'publish_replies'       => true,
                    'edit_replies'          => true,
                    'edit_others_replies'   => true,
                    'delete_replies'        => true,
                    'delete_others_replies' => true,
                    'read_private_replies'  => true,
     
                    // Topic tag caps
                    'manage_topic_tags'     => true,
                    'edit_topic_tags'       => true,
                    'delete_topic_tags'     => true,
                    'assign_topic_tags'     => true,
                );
     
                break;
     
            default :
                return $role;
        }
    }
    // End BBpress Custom Roles //

    @erich199

    Participant

    Hi @robin-w,

    I managed to get this to work with this code
    I needed a custom role and I also needed to reorder it in my legend. This code made it work

    //BBpress Custom Roles // 
    function add_role_caps_filter( $caps, $role )
    {
        /* Only filter for roles we are interested in! */
        if( $role == 'bbp_lead' )
            $caps = custom_capabilities( $role );
     
        return $caps;
    }
     
    add_filter( 'bbp_get_caps_for_role', 'add_role_caps_filter', 10, 2 );
     
    function custom_capabilities( $role )
    {
        switch ( $role )
        {
     
            /* Capabilities for 'tutor' role */
            case 'bbp_lead':
                return array(
                    // Primary caps
                    'spectate'              => true,
                    'participate'           => true,
                    'moderate'              => true,
                    'throttle'              => false,
                    'view_trash'            => false,
     
                    // Forum caps
                    'publish_forums'        => false,
                    'edit_forums'           => false,
                    'edit_others_forums'    => false,
                    'delete_forums'         => false,
                    'delete_others_forums'  => false,
                    'read_private_forums'   => true,
                    'read_hidden_forums'    => true,
     
                    // Topic caps
                    'publish_topics'        => true,
                    'edit_topics'           => true,
                    'edit_others_topics'    => true,
                    'delete_topics'         => true,
                    'delete_others_topics'  => true,
                    'read_private_topics'   => true,
     
                    // Reply caps
                    'publish_replies'       => true,
                    'edit_replies'          => true,
                    'edit_others_replies'   => true,
                    'delete_replies'        => true,
                    'delete_others_replies' => true,
                    'read_private_replies'  => true,
     
                    // Topic tag caps
                    'manage_topic_tags'     => true,
                    'edit_topic_tags'       => true,
                    'delete_topic_tags'     => true,
                    'assign_topic_tags'     => true,
                );
     
                break;
     
            default :
                return $role;
        }
    }
    // End BBpress Custom Roles //
    
    //BBpress Rename Roles //
    add_filter( 'bbp_get_dynamic_roles', 'ntwb_bbpress_custom_role_names' );
    function ntwb_bbpress_custom_role_names() {
        return array(
    		// Keymaster
    		bbp_get_keymaster_role() => array(
    		'name' => 'Administrator',
    		'capabilities' => bbp_get_caps_for_role( bbp_get_keymaster_role() )
    		),
    		'bbp_lead' => array(
            'name' => 'Community Lead',
            'capabilities' => custom_capabilities( 'bbp_lead' )
            ),
    		// Moderator
    		bbp_get_moderator_role() => array(
    		'name' => 'Moderator',
    		'capabilities' => bbp_get_caps_for_role( bbp_get_moderator_role() )
    		),
    		// Participant
    		bbp_get_participant_role() => array(
    		'name' => 'Member',
    		'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() )
    		),
    		// Spectator
    		bbp_get_spectator_role() => array(
    		'name' => 'Spectator',
    		'capabilities' => bbp_get_caps_for_role( bbp_get_spectator_role() )
    		),
    		// Blocked
    		bbp_get_blocked_role() => array(
    		'name' => 'Blocked',
    		'capabilities' => bbp_get_caps_for_role( bbp_get_blocked_role() )
    		)
    	);
    }
    //BBpress Rename Roles End //
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar