Skip to:
Content
Pages
Categories
Search
Top
Bottom

Can’t give users custom roles.

  • @ankylol

    Participant

    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 23 replies - 1 through 23 (of 23 total)
  • @robin-w

    Moderator

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

    @ankylol

    Participant

    Thank you, i will be waiting for it.

    @robin-w

    Moderator

    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

    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

    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,

    @stashhouse

    Participant

    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

    @stashhouse

    Participant

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

    @demonboy

    Participant

    Did anyone find a solution to this? I have am having the same issue and am using:

    function add_custom_role( $bbp_roles ) {
      $bbp_roles['my_custom_role'] = array( 
        'name' => 'Bosun',
        'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() ) // same capabilities as participants
      );
    
      return $bbp_roles;
    }   
    add_filter( 'bbp_get_dynamic_roles', 'add_custom_role', 1 );

    @demonboy

    Participant

    And, for the record, I tried Robin’s code too. This time the user was originally a ‘participant’. When adding Robin’s code and trying to save as my new forum user role, it reverts back to ‘participant’. Caching is turned off.

    @batteman

    Participant

    Good evening (in France, it’s 1:31 am ^^)

    Did you find an answer to these problem ? I’ve the same issue too with this “code” :

    
    /* Ajouts de rôles-clone à bbPress*/
    function add_revendeur_role( $bbp_roles ) 
    {
    $bbp_roles['bbp_revendeur'] = array(
    'name' => 'Revendeur',
    'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() )
    );
    return $bbp_roles;
    }
    add_filter( 'bbp_get_dynamic_roles', 'add_revendeur_role', 1 );

    I tried a few “codes” found on this forum without success.

    Thank you.

    @robin-w

    Moderator

    I just tried that code on my test site, and I made a user ‘revendeur’ and it worked fine.

    Can you describe what is not working – eg role is not showing in users profile, role showing but can’t allocate etc.

    Also where are you putting this code?

    @batteman

    Participant

    Hello Robin,

    First of all, thank you to answer me !

    I putted this code in the functions.php of the child theme.

    In fact, I have the same issue as above, since liyacaty : new role is showing in users profile, but I can’t allocate it to one user. If I do it, user have no role displayed (“-No roles for this forums-” displayed in the profile).

    Hope it can give you some hints.

    @robin-w

    Moderator

    hmmm….

    so in dashboard>users>edit user the rile shows – yes?
    but if you try to change it, when you save and immediately look back at it, what is it set to ?

    want other profile/bbpress/login related plugins do you have ?

    @batteman

    Participant

    Humm, I post my message but I think it has to much link in it (5) so it must be in “waiting approbation”… sorry.

    @batteman

    Participant

    Yes, the new role shows in “users” and in “edit users” (french grabs ^^) :
    http://batteman.free.fr/forum/bbPress1.jpg -> In “users”
    http://batteman.free.fr/forum/bbPress2.jpg -> In “edit users”

    If I choose “revendeur” for this test user, it was like it doesn’t have user role in bbPress http://batteman.free.fr/forum/bbPress3.jpg -> In “edit users”
    http://batteman.free.fr/forum/bbPress4.jpg -> In “users”

    I just notice this, in the “edit users” when I choose “revendeur” :
    http://batteman.free.fr/forum/bbPress5.jpg -> bbp_revendeur appears in “others permissions” of my user BatteTest !

    I installed “Private groups” recently but the problem was already here before I installed it.
    I also have “Buddy Press” and “bbPress topic count” and I’m using “graphene theme”.

    Thank you again.

    @robin-w

    Moderator

    I just notice this, in the “edit users” when I choose “revendeur” :
    http://batteman.free.fr/forum/bbPress5.jpg -> bbp_revendeur appears in “others permissions” of my user BatteTest !

    where exactly does this appear ?

    @batteman

    Participant

    It’s in “edit user”, under avatar, password and Wordfence login security. If I click on the “modify” link, it shows me “User Role Editor” for this user and you can see the “bbp revendeur” with an X in the right column :
    http://batteman.free.fr/forum/bbPress6.jpg

    @robin-w

    Moderator

    so presume you have user role editor as an additional plugin – yes ?

    @batteman

    Participant

    Oups, I forgot it… Yes, I’ve User Role Editor installed.

    @robin-w

    Moderator

    try deactivating it and see if that fixes – what are you using it for?

    @batteman

    Participant

    With ou without User Role Editor, same result.

    I’m not the “original webmaster” of our website, so idk why it was installed.

    @robin-w

    Moderator

    ok, not sure if I can help further – it works on my test site, so clearly something is amiss.

    Role editor may well change stuff in the database, so deactivating may be leaving stuff behind that may not help.

    @batteman

    Participant

    Thx for trying !

    Maybe the others admins who had same problems managed to create an other role… If they could tell us what they did.

    It’s not a big problem for me, but it would be great if I can do it 😉

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