Skip to:
Content
Pages
Categories
Search
Top
Bottom

Help with Forum Roles


  • techinbermudas
    Participant

    @techinbermudas

    Hello.

    So i’m developing a tech website but for some reason i can’t make the created forum roles to appear on users.

    Roles Created:
    Member – Participant rules but can’t create topics, only reply to existent ones.
    GCam Dev – with same permissions as Member but can create threads.
    ROM Dev – with same permissions as Member but can create threads.
    Kernel Dev – with same permissions as Member but can create threads.
    Modder – with same permissions as Member but can create threads.

    I’ve been searching and used this code below for it:

    //code to add tutor role 
     
    function add_new_roles( $bbp_roles )
    {
        $bbp_roles['bbp_gcamdev'] = array(
            'name' => 'GCam Developer',
            'capabilities' => custom_capabilities( 'bbp_gcamdev' )
            );
         $bbp_roles['bbp_romdev'] = array(
            'name' => 'ROM Developer',
            'capabilities' => custom_capabilities( 'bbp_romdev' )
            );
        $bbp_roles['bbp_kerneldev'] = array(
            'name' => 'Kernel Developer',
            'capabilities' => custom_capabilities( 'bbp_kerneldev' )
            );
        $bbp_roles['bbp_modder'] = array(
            'name' => 'Modder',
            'capabilities' => custom_capabilities( 'bbp_modder' )
            );
        $bbp_roles['bbp_member'] = array(
            'name' => 'Member',
            'capabilities' => custom_capabilities( 'bbp_member' )
            );
     
        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_gcamdev' )
            $caps = custom_capabilities( $role );
     
        if( $role == 'bbp_romdev' )
            $caps = custom_capabilities( $role );
     
        if( $role == 'bbp_kerneldev' )
            $caps = custom_capabilities( $role );
    
        if( $role == 'bbp_modder' )
            $caps = custom_capabilities( $role );
    
        if( $role == 'bbp_member' )
            $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 )
        {
            case 'bbp_gcamdev':
                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,
                );
    
            case 'bbp_romdev':
                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,
                );
    
            case 'bbp_kerneldev':
                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,
                );
    
            case 'bbp_modder':
                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,
                );
     
    
            case 'bbp_member':
                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;
        }
    }

    The Forum Roles appear on the Users menu but when i select it and Save Changes the role is removed. Am i missing anything?

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

  • mairag
    Participant

    @mairag

    I’m having the same issue, I’ve created a new role as I don’t want participants to create new topics, but the new role is not saved in the Settings and hence is not being applied to the users.

    I hope someone can chime in.


    Robin W
    Moderator

    @robin-w

    @techinbermudas @mairag where are you putting this code?


    mairag
    Participant

    @mairag

    Hi Robin, I’m placing it in functions.php…


    Robin W
    Moderator

    @robin-w

    of your theme?


    mairag
    Participant

    @mairag

    Yes, I’m using a Genesis child theme, added the plugin compatibility for Genesis too. Also, disabled all my plugins to check for any incompatibility but the problem is still there.
    The user role is created and can be assigned in the Forum settings but is not assigned to the new users and it always says – No role for these forums – when I select the new role in the user profile and save the change.


    Robin W
    Moderator

    @robin-w

    ok, thanks.

    It is a load order issue, so we need to add the filters once everything is loaded.

    So for @techinbermudas example we would have

    add_action ('wp_loaded' , 'load_new_roles') ;
    
    function load_new_roles () {
    	add_filter( 'bbp_get_dynamic_roles', 'add_new_roles', 1 );
    	add_filter( 'bbp_get_caps_for_role', 'add_role_caps_filter', 10, 2 );
    }
    
    function add_new_roles( $bbp_roles )
    {
        $bbp_roles['bbp_gcamdev'] = array(
            'name' => 'GCam Developer',
            'capabilities' => custom_capabilities( 'bbp_gcamdev' )
            );
         $bbp_roles['bbp_romdev'] = array(
            'name' => 'ROM Developer',
            'capabilities' => custom_capabilities( 'bbp_romdev' )
            );
        $bbp_roles['bbp_kerneldev'] = array(
            'name' => 'Kernel Developer',
            'capabilities' => custom_capabilities( 'bbp_kerneldev' )
            );
        $bbp_roles['bbp_modder'] = array(
            'name' => 'Modder',
            'capabilities' => custom_capabilities( 'bbp_modder' )
            );
        $bbp_roles['bbp_member'] = array(
            'name' => 'Member',
            'capabilities' => custom_capabilities( 'bbp_member' )
            );
     
        return $bbp_roles;
    }
    
    function add_role_caps_filter( $caps, $role )
    {
        /* Only filter for roles we are interested in! */
        if( $role == 'bbp_gcamdev' )
            $caps = custom_capabilities( $role );
     
        if( $role == 'bbp_romdev' )
            $caps = custom_capabilities( $role );
     
        if( $role == 'bbp_kerneldev' )
            $caps = custom_capabilities( $role );
    
        if( $role == 'bbp_modder' )
            $caps = custom_capabilities( $role );
    
        if( $role == 'bbp_member' )
            $caps = custom_capabilities( $role );
    
        return $caps;
    }
     
    
     
    function custom_capabilities( $role )
    {
        switch ( $role )
        {
            case 'bbp_gcamdev':
                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,
                );
    
            case 'bbp_romdev':
                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,
                );
    
            case 'bbp_kerneldev':
                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,
                );
    
            case 'bbp_modder':
                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,
                );
     
    
            case 'bbp_member':
                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;
        }
    }

    which adds the filter once the theme and all plugins are loaded.


    Robin W
    Moderator

    @robin-w

    If that is not clear, post your code and I’ll give back the correct version.


    Robin W
    Moderator

    @robin-w

    I’ve corrected the documentation 🙂


    mairag
    Participant

    @mairag

    Thank you Robin.

    I did the change but didn’t solve the issue, let’s see if OP had more luck.

    This is my updated code for the new role Crochetera.

    // bbPress custom role
    
    add_action ('wp_loaded' , 'load_new_roles') ;
    function load_new_roles () {
    	add_filter( 'bbp_get_dynamic_roles', 'add_new_roles', 1 );
    	add_filter( 'bbp_get_caps_for_role', 'add_role_caps_filter', 10, 2 );
    }
     
    function add_new_roles( $bbp_roles ){
        /* Add a role called crochetera */
        $bbp_roles['bbp_crochetera'] = array(
            'name' => 'Crochetera',
            'capabilities' => custom_capabilities( 'bbp_crochetera' )
            );
     
        return $bbp_roles;
    }
     
    function add_role_caps_filter( $caps, $role ) {
        /* Only filter for roles we are interested in! */
        if( $role == 'bbp_crochetera' )
            $caps = custom_capabilities( $role );
     
        return $caps;
    }
     
    function custom_capabilities( $role ){
        switch ( $role ) {
     
            /* Capabilities for 'crochetera' role */
            case 'bbp_crochetera':
                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'   => false,
                    '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'   => false,
     
                    // 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'     => false,
                );
     
                break;
     
            default :
                return $role;
        }
    }

    Robin W
    Moderator

    @robin-w

    ok, it is a load order issue – I’m digging further !!


    mairag
    Participant

    @mairag

    Ok, I’ll be waiting for an update.

    Thanks!


    techinbermudas
    Participant

    @techinbermudas

    Same here.
    The roles appear but when adding a user it doesn’t work.


    Robin W
    Moderator

    @robin-w

    ok, I’ve spent several hours trying to resolve this – I’m not a bbpress author, just a user

    so can you try the instructions here

    bbpress role adder


    techinbermudas
    Participant

    @techinbermudas

    it worked, thanks 😉


    Robin W
    Moderator

    @robin-w

    @techinbermudas – great – glad it worked


    mairag
    Participant

    @mairag

    It’s working for me too, thanks Robin!


    Robin W
    Moderator

    @robin-w

    @mairag – great – thanks for letting me know !! 🙂

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