Skip to:
Content
Pages
Categories
Search
Top
Bottom

Can’t give users custom roles.


  • ankylol
    Participant

    @ankylol

    Hello,

    Robin i added the tutor code to my functions file.As you can see in this link –> https://prnt.sc/l5mmhh i can see the role while editing users forum role.But the thing is when i try to give the user that Tutor role and save user profile.The forum role of the user is being -No roles for this forums- so i can’t give the custom role. Also i tried the other custom name functions thing.I created a role and gived it participant perms but couldn’t give that role to user too.

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

  • Robin W
    Moderator

    @robin-w

    ok, when I get a moment I’ll take a look


    ankylol
    Participant

    @ankylol

    Thank you, i will be waiting for it.


    Robin W
    Moderator

    @robin-w

    ok, I presume you meant this code

    //code to add tutor role 
     
    function add_new_roles( $bbp_roles )
    {
        /* Add a role called tutor */
        $bbp_roles['bbp_tutor'] = array(
            'name' => 'Tutor',
            'capabilities' => custom_capabilities( 'bbp_tutor' )
            );
     
        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_tutor' )
            $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_tutor':
                return array(
                    // Primary caps
                    'spectate'              => true,
                    'participate'           => true,
                    'moderate'              => false,
                    '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'    => false,
     
                    // Topic caps
                    'publish_topics'        => true,
                    'edit_topics'           => true,
                    'edit_others_topics'    => false,
                    'delete_topics'         => false,
                    'delete_others_topics'  => false,
                    'read_private_topics'   => true,
     
                    // Reply caps
                    'publish_replies'       => true,
                    'edit_replies'          => true,
                    'edit_others_replies'   => false,
                    'delete_replies'        => false,
                    'delete_others_replies' => false,
                    'read_private_replies'  => true,
     
                    // Topic tag caps
                    'manage_topic_tags'     => false,
                    'edit_topic_tags'       => false,
                    'delete_topic_tags'     => false,
                    'assign_topic_tags'     => true,
                );
     
                break;
     
            default :
                return $role;
        }
    }

    so with that code loaded to my site, if I go to

    dashboard>users>all users and edit a user, I can change them to the tutor role, and back again and it saves.

    Can you confirm you are using the above code, and that it does not save if you perform the above ?


    liyacaty
    Participant

    @liyacaty

    Creating a new role
    Select “Roles” from the “Settings” menu at the top of the screen (this menu is only available to space administrators).
    Find a role in the list that is similar to the role you’d like to create, click “…”, and select “Duplicate role”.
    On this new screen you can customize the rules that will apply to users who are assigned this role.


    9march
    Participant

    @9march

    Hi robin,

    I have the same issue on my site, I added the code as it is but when i give a user the ‘tutor’ role, After saving the role disappears and the user has no bbpress role assigned to them.Even i i signup as a subscriber, If the default role is set to be ‘tutor’ The newly registered user ends up with no bbpress role.

    Thanks,


    The Stash House
    Participant

    @stashhouse

    Hi Robin,

    I have the same issue as 9march using this code in my functions.php :

    /**
     * BBPress : add new role with custom capabilities
     * https://codex.bbpress.org/custom-capabilities/
     */
    
    //code to add "client" role
    
    function add_new_roles( $bbp_roles )
    {
        /* Add a role called tutor */
        $bbp_roles['bbp_client'] = array(
            'name' => 'Client',
            'capabilities' => custom_capabilities( 'bbp_client' )
        );
    
        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_client' )
            $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 'client' role */
            case 'bbp_client':
                return array(
                    // Primary caps
                    'spectate'              => true,
                    'participate'           => true,
                    'moderate'              => false,
                    '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'    => false,
    
                    // Topic caps
                    'publish_topics'        => false,
                    'edit_topics'           => false,
                    'edit_others_topics'    => false,
                    'delete_topics'         => false,
                    'delete_others_topics'  => false,
                    'read_private_topics'   => true,
    
                    // Reply caps
                    'publish_replies'       => true,
                    'edit_replies'          => true,
                    'edit_others_replies'   => false,
                    'delete_replies'        => false,
                    'delete_others_replies' => false,
                    'read_private_replies'  => true,
    
                    // Topic tag caps
                    'manage_topic_tags'     => false,
                    'edit_topic_tags'       => false,
                    'delete_topic_tags'     => false,
                    'assign_topic_tags'     => true,
                );
    
                break;
    
            default :
                return $role;
        }
    }

    always ending with “-No roles for this forums-” like the new role for the newly registered user was not saved.

    Regards,

    David


    The Stash House
    Participant

    @stashhouse

    PS : it’s the same when I’m trying with your “tutor” code

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