Custom Roles not assignable
-
Hi folks,
I added 2 custom roles viafunction add_custom_role( $bbp_roles ) { $bbp_roles['my_custom_role1'] = array( 'name' => 'Kursteilnehmer', 'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() ) // the same capabilities as participants ); $bbp_roles['my_custom_role2'] = array( 'name' => 'Mentor', 'capabilities' => bbp_get_caps_for_role( bbp_get_moderator_role() ) // the same capabilities as moderator ); return $bbp_roles; } add_filter( 'bbp_get_dynamic_roles', 'add_custom_role', 1 );
I tried to assign them via the WP-Users page, but they do not appear in the forum-roles dropdown.
Whats going wrong here?
Regards
Dominik
-
*push* an answer would be nice.
where did you put that code?
In a custom-functions-file in the mu-plugins folder.
ok, sorry I don’t know much about MU and bbpress functions, so can’t say if that would work
Changing the name of existing roles through MU works.
But how would you recommend to handle it?
try it in the functions file of a specific installation
now i added this to functions.php:
//code to add forum-roles function add_new_roles( $bbp_roles ) { /* Add a role called tutor */ $bbp_roles['bbp_mentor'] = array( 'name' => 'Mentor', 'capabilities' => custom_capabilities( 'bbp_mentor' ) ); /* Add a role called pupil */ $bbp_roles['bbp_kursteilnehmer'] = array( 'name' => 'Kursteilnehmer', 'capabilities' => custom_capabilities( 'bbp_kursteilnehmer' ) ); 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_mentor' ) $caps = custom_capabilities( $role ); if( $role == 'bbp_kursteilnehmer' ) $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 'mentor' role */ case 'bbp_mentor': 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 'kursteilnehmer' role */ case 'bbp_kursteilnehmer': 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, ); break; default : return $role; } }
it still does not work.
Any hints, whats wrong here?
*push*
ok, resolved.
It was a conflict with another code, that renames the roles.great – glad you are fixed !
where did you put that code?
Hi Dominikb. I am having the same trouble. COuld you please explain the steps you took to fix the problem?
Regards,
I put the code into a custom plugin.
I realized, that i used another code mentioned in this forum, to change the original names of the roles, so i deleted this code and afterwards it just worked.
Thanks. That has helped! Let me get to work.
- You must be logged in to reply to this topic.