Skip to:
Content
Pages
Categories
Search
Top
Bottom

Custom Roles & Capabilities


  • kc9wwh
    Participant

    @kc9wwh

    Hello Everyone,

    So I’ve been working to get some custom permissions setup for our site and are running into some issues…I’ve followed the document located here and in turn have added the following code to my functions.php file in my child theme:

    //code to add members and board roles
     
    function add_new_roles( $bbp_roles )
    {
        /* Add a role called member */
        $bbp_roles['bbp_member'] = array(
            'name' => 'Member',
            'capabilities' => custom_capabilities( 'bbp_member' )
            );
     
        /* Add a role called board */
        $bbp_roles['bbp_board'] = array(
            'name' => 'Board Member',
            'capabilities' => custom_capabilities( 'bbp_board' )
            );
     
        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_member' )
            $caps = custom_capabilities( $role );
     
        if( $role == 'bbp_board' )
            $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 'Member' role */
            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'        => 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 'Board Member' role */
            case 'bbp_board':
                return array(
                    // Primary caps
                    'spectate'              => true,
                    'participate'           => true,
                    'moderate'              => true,
                    'throttle'              => true,
                    'view_trash'            => false,
     
                    // Forum caps
                    'publish_forums'        => true,
                    'edit_forums'           => true,
                    'edit_others_forums'    => true,
                    'delete_forums'         => true,
                    'delete_others_forums'  => true,
                    '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;
        }
    }

    The problem I am running into is that the bbp_member role can’t seem to read and private topics, even though I have that capability set to true…? The bbp_board role works just as expected and in playing with the bbp_member role it seems to come down to the “moderate” capability…which I really don’t want on for our regular members.

    Any help on this would be greatly appreciated.

    I have the latest versions of WP, bbPress and BuddyPress installed.

    Thank you

Viewing 25 replies - 1 through 25 (of 27 total)

  • Robin W
    Moderator

    @robin-w

    what other plugins do you have?


    kc9wwh
    Participant

    @kc9wwh

    Here is the list of plugins installed and activated…

    • bbPress
    • bbPress Pencil Unread
    • BuddyPress
    • Buddypress Xprofile Custom Fields Type
    • GD bbPress Attachments
    • GD bbPress Tools
    • If Menu
    • Jetpack by WordPress.com
    • Login Logo
    • The Events Calendar
    • Theme Logo
    • WPFront User Role Editor
    • WP Maintenance Mode

    Robin W
    Moderator

    @robin-w

    Hmmm.. I’ve just spent some time playing with this code, and it’s not really working.

    It is quoted in lots of sites inc http://gawainlynch.com/customising-dynamic-roles-in-bbpress-2-2/

    But as far as I can see you get the member role, but the site default role capabilities – can’t work out why at the moment. What is you site default, and would that make sense?


    kc9wwh
    Participant

    @kc9wwh

    I do have the “Member” role set at the default under Settings > Forum.

    One other thing I noticed is to make sure that when editing the user the Secondary Roles would become checked when switching to different roles and I had to make sure that only the one selected under Forum Role was the one selected under Secondary Roles as well…

    Otherwise, like for the “board” role, it had Participant checked also along with Board Member and the Board Member roles never seemed to actually apply until I unchecked Participant.


    Robin W
    Moderator

    @robin-w

    it may be just me, it’s getting late but yes I can change the user to member, but it’s not altering the capabilites, I switched everything to false and I can still edit, but as I say it’s late and I’m probably not doing something right – I’ll take another look tomorrow.

    Also you’re using buddypress as well, does this give you the secondary roles you mention?


    kc9wwh
    Participant

    @kc9wwh

    No, I disabled BuddyPress and it was still there…looks like its coming from WPFront User Role Editor, which seems to get rid of that secondary role option. I also tried access the forums again and that didn’t seem to change anything either.


    Robin W
    Moderator

    @robin-w

    ok, not sure why, but my code is now working without me changing, but I did shutdown all browsers and reload from scratch and that seemed to fix.

    I can now change role capabilities at will, but initially like you the changes did not take effect.

    by the by if you have several sessions in one browser they will take capabiliites of another session, so have you admin in say IE and your user you are testing in say Chrome !


    Robin W
    Moderator

    @robin-w

    Come back if you rae still having problems tomorrow, but the code you posted works with bbpress !


    kc9wwh
    Participant

    @kc9wwh

    Thanks Robin,

    I’ve been using Safari to login with my test user and Firefox for admin, but even with clearing cookies and cache I’m seeing no improvements. I went through and disabled plugins one by one and didn’t see any change either…

    Could it be something with the theme? I’m using a Twenty Thirteen Child Theme.

    Thanks again!


    kc9wwh
    Participant

    @kc9wwh

    Its weird…I can change permissions for Posts and Pages and they come through instantly…its just with bbPress that I am noticing issues.

    Tomorrow I may just have to remove bbPress and try re-installing it and see what happens. Anyway, I’ll check back here tomorrow first.


    Robin W
    Moderator

    @robin-w

    will be at least tomorrow evening before I look at again, but the code does seem to work on my test stite with twenty ten, although I don’t know why it didn’t immediately !


    Robin W
    Moderator

    @robin-w

    ok, slept on it, and we have three ‘user role’ areas

    1. buddypress membership level of a group
    dashboard>groups>buddypress group member
    2. wordpress role
    Dashboard>users>all users and edit a user
    the wordpress role is at the top
    3. forum role
    Dashboard>users>all users and edit a user
    the forum role is right at the bottom

    It is no. 3 that you are changing to member and should be the one affecting

    Can you confirm that this is the one we are talking about, and that you have changed to member


    kc9wwh
    Participant

    @kc9wwh

    2 and 3 are correct, I am not using buddypress groups. Just use it for the profile fields and private messaging.


    Robin W
    Moderator

    @robin-w

    ok, so what are

    2. wordpress role
    and
    3. forum role

    set to for your test user?


    kc9wwh
    Participant

    @kc9wwh

    2. Subscriber
    3. Member


    kc9wwh
    Participant

    @kc9wwh

    And the fun part is I can get into the topic level…but can’t see any posts and/or replies…

    Welcome! › Forums › Introductions

    Subscribe
    This forum contains 1 topic, and was last updated by Profile photo of KC9WWH KC9WWH 2 weeks, 3 days ago.

    Oh bother! No topics were found here!


    kc9wwh
    Participant

    @kc9wwh

    …sorry I can see the forum level, but not the individual topics and replies.


    Robin W
    Moderator

    @robin-w

    can you try disabling

    ◾WPFront User Role Editor

    and see if that fixes?


    kc9wwh
    Participant

    @kc9wwh

    Tried that yesterday and it is still disabled with no changes.


    Robin W
    Moderator

    @robin-w

    ok, more drastic action required

    Plugins

    Deactivate all but bbpress and see if this fixes. if it does, re-enable one at a time to see which is causing the error.

    Themes

    If plugins don’t pinpoint the problem, as a test switch to a default theme such as twentytwelve, and see if this fixes.

    Sorry I’m running out of ideas beyond this … 🙂


    kc9wwh
    Participant

    @kc9wwh

    Yea….I did that last night and just did it again…disabling all plugins doesn’t fix the issue and neither did changing the template 🙁

    Thanks for your help…i’ll have to keep digging around, not sure what is causing this.


    kc9wwh
    Participant

    @kc9wwh

    Okay…so this is annoying…I decided to test out a theory…I went into the …/core/capabilities.php file and modified the participant role to see private threads and replies and even then, a user with the participant role could not view past the private forum level…wtf?

    All I can think of is something, somewhere is overriding the core capabilities…ugh…the question is what and where?


    Robin W
    Moderator

    @robin-w

    ok, do come back if you get it fixed – it should work, and something is stopping it !!


    kc9wwh
    Participant

    @kc9wwh

    So I have no clue what was causing this….but, I went ahead and just reset bbPress and viola! Everything is working as it should! lol…wish I knew what caused it, but at least there were not that many posts yet.


    Robin W
    Moderator

    @robin-w

    well there you go, sounds like something needs ‘resetting’ to get it to work

    so did you deactivate/activate bbppress or what did you do? I’ll then add this as a suggestion in the documentation !

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