Skip to:
Content
Pages
Categories
Search
Top
Bottom

Add Custom User Roles


  • Alice Kaye
    Participant

    @alice-kaye

    Hi everyone,

    I’m working on creating some custom user roles and I was wondering if I could get assistance with it, because the code I modified kind of killed my site (so I took it out and it’s working fine again).

    I’m running a guild website, so we have specific titles (in order from left to right for hierarchy):
    Advisor (Keymaster) > Councilman (Moderator) > Artisan (Moderator) > Adept (Participant) > Journeyman (Participant) > Craftsman (Participant) > Apprentice (Participant)

    I was trying to follow this guide: http://codex.bbpress.org/custom-capabilities/

    /* bbPress Custom Roles */
    function add_custom_role( $bbp_roles ) {
     
    $bbp_roles['my_custom_role1'] = array(
    'name' => 'Apprentice',
    'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() ) // the same capabilities as participants
    );
    $bbp_roles['my_custom_role2'] = array(
    'name' => 'Craftsman',
    'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() ) // the same capabilities as participants
    );
    $bbp_roles['my_custom_role3'] = array(
    'name' => 'Journeyman',
    'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() ) // the same capabilities as participants
    );
    $bbp_roles['my_custom_role4'] = array(
    'name' => 'Adept',
    'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() ) // the same capabilities as participants
    );
    $bbp_roles['my_custom_role5'] = array(
    'name' => 'Artisan',
    'capabilities' => bbp_get_caps_for_role( bbp_get_moderator_role() ) // the same capabilities as keymaster
    );
    $bbp_roles['my_custom_role6'] = array(
    'name' => 'Councilman',
    'capabilities' => bbp_get_caps_for_role( bbp_get_moderator_role() ) // the same capabilities as keymaster
    );
    $bbp_roles['my_custom_role7'] = array(
    'name' => 'Advisor',
    'capabilities' => bbp_get_caps_for_role( bbp_get_keymaster_role() ) // the same capabilities as keymaster
    );
    return $bbp_roles;
    }
    add_filter( 'bbp_get_dynamic_roles', 'add_custom_role', 1 );
    /* bbPress Custom Roles */

    Can someone tell me where I might have gone wrong?

    Thanks in advance! 😀

Viewing 6 replies - 26 through 31 (of 31 total)

  • Alice Kaye
    Participant

    @alice-kaye

    Okay, so kind of resurrecting my old thread here, but with good reason, because something has gone wrong with the code. Today, I promoted someone (the first person to be promoted to this rank) Artisan, which I’ve hand coded into my functions.php file.

    The code:

    /* bbPress Custom Roles */
    function add_custom_role( $bbp_roles ) {
    
    $bbp_roles['bbp_craftsman'] = array(
    'name' => 'Craftsman',
    'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() ) // the same capabilities as participants
    );
    $bbp_roles['bbp_journeyman'] = array(
    'name' => 'Journeyman',
    'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() ) // the same capabilities as participants
    );
    $bbp_roles['bbp_adept'] = array(
    'name' => 'Adept',
    'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() ) // the same capabilities as participants
    );
    $bbp_roles['bbp_artisan'] = array(
    'name' => 'Artisan',
    'capabilities' => bbp_get_caps_for_role( bbp_get_moderator_role() ) // the same capabilities as moderator
    );
    $moderator = bbp_get_moderator_role() ;
    $bbp_roles[$moderator] = array(
    'name' => 'Councilman',
    'capabilities' => bbp_get_caps_for_role( bbp_get_moderator_role() ) // the same capabilities as moderator
    );
    $keymaster = bbp_get_keymaster_role() ;
    $bbp_roles[$keymaster] = array(
    'name' => 'Advisor',
    'capabilities' => bbp_get_caps_for_role( bbp_get_keymaster_role() ) // the same capabilities as keymaster
    );
    $apprentice = bbp_get_participant_role() ;
    $bbp_roles[$apprentice] = array(
    'name' => 'Apprentice',
    'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() ) // the same capabilities as participants
    );
    return $bbp_roles;
    }
    add_filter( 'bbp_get_dynamic_roles', 'add_custom_role', 1 );
    /* bbPress Custom Roles */

    As you can see, the way I’ve written it, I had Artisan and Councilman both as moderator roles. This is really how I need it set up.

    Currently I’ve adjusted Artisan to:

    $bbp_roles['bbp_artisan'] = array(
    'name' => 'Artisan',
    'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() ) // the same capabilities as participants
    );

    Because for whatever reason, when set to moderator, she could not see our forums at all.

    Is there a way to have two moderator ranks, or can there only be one? If so, where have I gone wrong with this? I’m quite confused over it now.

    Thanks in advance, you guys have been so helpful through all of my learning. 🙂


    Robin W
    Moderator

    @robin-w

    you can have multiple roles with the same capabilities, so the original code should be fine.

    So I would check

    1. that the moderator role which you have renamed Councilman works
    2. that if you set up a test user and give them Artisan, that that works (ie is it only her)


    Alice Kaye
    Participant

    @alice-kaye

    Hi @robin-w!

    Thanks for replying back about this. I’m sorry I failed to mention my troubleshooting. It definitely worked when I set up my husband’s account as a Councilman, and I tested every single rank on his account. He had the same results when set to an Artisan.

    At that point, I came here because I can’t see anything wrong with the code.

    Thanks again for the reply! 🙂


    Robin W
    Moderator

    @robin-w

    ok, I’ve just loaded that code to my test site and it all works fine, the artisan role gives moderator access.

    Not sure what has happened, what other changes have there been to your site?

    He had the same results when set to an Artisan

    Presume you mean he could not access, and by the by what do you mean by that? what happens when they try and access the forums, can they not see menu item, or what do they get when they try??


    Alice Kaye
    Participant

    @alice-kaye

    Hi @robin-w,

    Thanks for the response. Sorry for the slow response, I was away for the weekend.

    I’ll try to replace the code again today, but basically what happens is, when they go to the forums it displays a 404 error as if the page doesn’t exist. They can see the top menu, and the rest of the website’s look, but the forums aren’t visible at all.


    Robin W
    Moderator

    @robin-w

    ok, come back when you’ve re-tried

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