Skip to:
Content
Pages
Categories
Search
Top
Bottom

Custom Roles not assignable

  • @dominikb-1

    Participant

    Hi folks,
    I added 2 custom roles via

    function add_custom_role( $bbp_roles ) {
    
    $bbp_roles['my_custom_role1'] = array(
    'name' => 'Kursteilnehmer',
    'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() ) // the same capabilities as participants
    );
    $bbp_roles['my_custom_role2'] = array(
    'name' => 'Mentor',
    'capabilities' => bbp_get_caps_for_role( bbp_get_moderator_role() ) // the same capabilities as moderator
    );
    return $bbp_roles;
    }
    add_filter( 'bbp_get_dynamic_roles', 'add_custom_role', 1 );

    I tried to assign them via the WP-Users page, but they do not appear in the forum-roles dropdown.

    Whats going wrong here?

    Regards
    Dominik

Viewing 17 replies - 1 through 17 (of 17 total)
  • @dominikb-1

    Participant

    *push* an answer would be nice.

    @robin-w

    Moderator

    where did you put that code?

    @dominikb-1

    Participant

    In a custom-functions-file in the mu-plugins folder.

    @robin-w

    Moderator

    ok, sorry I don’t know much about MU and bbpress functions, so can’t say if that would work

    @dominikb-1

    Participant

    Changing the name of existing roles through MU works.

    But how would you recommend to handle it?

    @robin-w

    Moderator

    try it in the functions file of a specific installation

    @casiepa

    Moderator

    @dominikb-1,

    Did you read till the end of the codex page ?

    Custom Capabilities

    @dominikb-1

    Participant

    @robin-w
    I moved the code to the functions.php file now, still no reaction.


    @casiepa

    Yes, i followed the procedure for adding new names with existing capabilities, but they are not appearing.
    Is it possible, that you cant add an existing capability to multiple roles?

    @dominikb-1

    Participant

    now i added this to functions.php:

    
    //code to add forum-roles
    
    function add_new_roles( $bbp_roles )
    {
        /* Add a role called tutor */
        $bbp_roles['bbp_mentor'] = array(
            'name' => 'Mentor',
            'capabilities' => custom_capabilities( 'bbp_mentor' )
            );
    
        /* Add a role called pupil */
        $bbp_roles['bbp_kursteilnehmer'] = array(
            'name' => 'Kursteilnehmer',
            'capabilities' => custom_capabilities( 'bbp_kursteilnehmer' )
            );
    
        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_mentor' )
            $caps = custom_capabilities( $role );
    
        if( $role == 'bbp_kursteilnehmer' )
            $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 'mentor' role */
            case 'bbp_mentor':
                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,
                );
    
                /* Capabilities for 'kursteilnehmer' role */
            case 'bbp_kursteilnehmer':
                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;
        }
    }
    

    it still does not work.

    Any hints, whats wrong here?

    @dominikb-1

    Participant

    *push*

    @dominikb-1

    Participant

    ok, resolved.
    It was a conflict with another code, that renames the roles.

    @robin-w

    Moderator

    great – glad you are fixed !

    @negi15

    Participant

    where did you put that code?

    @realnsleo

    Participant

    Hi Dominikb. I am having the same trouble. COuld you please explain the steps you took to fix the problem?

    Regards,

    @dominikb-1

    Participant

    I put the code into a custom plugin.

    @dominikb-1

    Participant

    I realized, that i used another code mentioned in this forum, to change the original names of the roles, so i deleted this code and afterwards it just worked.

    @realnsleo

    Participant

    Thanks. That has helped! Let me get to work.

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