Skip to:
Content
Pages
Categories
Search
Top
Bottom

Add forum roles

  • @anallabres

    Participant

    I have read the whole ‘Roles and Capabilities in bbPress 2.2’ thread but still not sure if there is a way of adding new forum roles.

    I’ve got groups of people answering members questions and I want them to be identified by their expertise (ie. Mentor, Advisor, …) to know how reliable is the answer.

    Is it possible?

    Thanks!

Viewing 16 replies - 1 through 16 (of 16 total)
  • @johnjamesjacoby

    Keymaster
    • Filter the results of `bbp_get_dynamic_roles()` to add the role.
    • Filter the results of `bbp_get_caps_for_role()` to set the capabilities for that role.

    @anallabres

    Participant

    Thanks for the answer John.

    Just not sure… where should I do that???

    Thanks again!

    @graemeviljoen

    Participant

    Edit the file in wp-content/plugins/bbpress/includes/core

    the file to edit is called capabilities.php

    @johnjamesjacoby

    Keymaster

    Edit the file in wp-content/plugins/bbpress/includes/core

    the file to edit is called capabilities.php

    Incorrect; *never* edit any files in bbPress’s directory; you’ll lose those edits when software updates come in.


    @anallabres
    – Research how WordPress’s actions/filters/plugins work. It’s a little dizzying at first, but a few lines of code can get you up and running.

    @greenshady

    Participant

    Add new roles with a roles plugin. You don’t have to use code. See: https://wordpress.org/extend/plugins/members

    @azureninja99

    Participant

    @greenshady Doesn’t that plugin make WordPress groups, not BBPress forum roles? I’m trying to do the same thing too.

    @blg002

    Participant

    wondering if anyone has a quick snippet of code that answers @anallabres initial question.

    @blg002

    Participant

    For posterities sake, i think i figured this out thanks to this article. I was close just had few things I didn’t know about, hopefully I’m not doing anything too terrible.

    
    function add_custom_role( $bbp_roles ) {
      $bbp_roles['my_custom_role'] = array( 
        'name' => 'My Custom User',
        'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() ) // i just want them to have the same capabilities as participants
      );
    
      return $bbp_roles;
    }   
    add_filter( 'bbp_get_dynamic_roles', 'add_custom_role', 1 );
    

    @janhoos

    Participant

    Cool! Where did you add that? Did you download a plug-in that lets you create simple plugins? Or did you add that to a functions file somewhere?

    Whats the safest place? Cause I know a few ways of adding this in 😛

    @blg002

    Participant

    @janhoos i just added it to functions.php

    However, this didn’t end of completely working for me. I would save and the role would not be saved, i believe.

    @janhoos

    Participant

    Hi Blg002,

    It worked for me! Added it to the theme functions and changed the function to add in 3 more roles.

    Can probably optimise it but it works like this right now:

    function add_custom_role( $bbp_roles ) {
    $bbp_roles[‘my_custom_role’] = array(
    ‘name’ => ‘ACN Lid’,
    ‘capabilities’ => bbp_get_caps_for_role( bbp_get_participant_role() ) // i just want them to have the same capabilities as participants

    );
    $bbp_roles[‘my_custom_role2’] = array(
    ‘name’ => ‘ACN Aspirant’,
    ‘capabilities’ => bbp_get_caps_for_role( bbp_get_participant_role() ) // i just want them to have the same capabilities as participants

    );
    $bbp_roles[‘my_custom_role3’] = array(
    ‘name’ => ‘ACN Lid admin’,
    ‘capabilities’ => bbp_get_caps_for_role( bbp_get_keymaster_role() ) // i just want them to have the same capabilities as participants

    );

    return $bbp_roles;
    }
    add_filter( ‘bbp_get_dynamic_roles’, ‘add_custom_role’, 1 );

    @janhoos

    Participant

    Is there a way to give a custom role a custom set of capabilities?

    Like the ones found on the capabilities.php file?

    // 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’ => false,

    // Reply caps
    ‘publish_replies’ => true,
    ‘edit_replies’ => true,
    ‘edit_others_replies’ => false,
    ‘delete_replies’ => false,
    ‘delete_others_replies’ => false,
    ‘read_private_replies’ => false,

    // Topic tag caps
    ‘manage_topic_tags’ => false,
    ‘edit_topic_tags’ => false,
    ‘delete_topic_tags’ => false,
    ‘assign_topic_tags’ => true,

    Using the code above, I don’t know where to put the capabilities.

    @arno8

    Participant

    I used this code, and added a few new ones but when i try assignem them it only shows 1

    @joopstringer

    Participant

    Hey guys,

    Can you please explain me where to put the functions.php file ?
    If I put it in the child theme directory,my whole site goes blank …

    
    <?php
    /**
     * Functions .. additional to all the programs
     *
     * @package WordPress
     * @subpackage Twenty_Fourteen
     * @since Twenty Fourteen 1.0
     */
    
    function add_custom_role( $bbp_roles ) {
    
    	$bbp_roles['DDC Member'] = array(
    	'name' => 'DDC Member',
    	'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() ) // i just want them to have the same capabilities as participants );
    
    	$bbp_roles['Forumlid'] = array(
    	'name' => 'Forumlid',
    	'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() ) // i just want them to have the same capabilities as participants );
    
    	$bbp_roles['DDC Bestuur'] = array(
    	'name' => 'DDC Bestuur',
    	'capabilities' => bbp_get_caps_for_role( bbp_get_keymaster_role() ) // i just want them to have the same capabilities as participants ); 
    
    	return $bbp_roles;
    }
    
    add_filter( 'bbp_get_dynamic_roles', 'add_custom_role', 1 );
    
    ?>
    

    @sam-rohn

    Participant

    there is an excellent article here on using wordpress functions.php file

    WordPress theme function files

    sam

    @joopstringer

    Participant

    Got it running now, thanks !!

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