Skip to:
Content
Pages
Categories
Search
Top
Bottom

Add forum roles


  • anallabres
    Participant

    @anallabres

    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)

  • John James Jacoby
    Keymaster

    @johnjamesjacoby

    • 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

    @anallabres

    Thanks for the answer John.

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

    Thanks again!


    graemeviljoen
    Participant

    @graemeviljoen

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

    the file to edit is called capabilities.php


    John James Jacoby
    Keymaster

    @johnjamesjacoby

    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.


    Justin Tadlock
    Participant

    @greenshady

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


    AzureNinja99
    Participant

    @azureninja99

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


    blg002
    Participant

    @blg002

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


    blg002
    Participant

    @blg002

    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

    @janhoos

    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

    @blg002

    @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

    @janhoos

    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

    @janhoos

    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

    @arno8

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


    joop.stringer
    Participant

    @joopstringer

    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

    @sam-rohn

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

    WordPress theme function files

    sam


    joop.stringer
    Participant

    @joopstringer

    Got it running now, thanks !!

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