Custom Roles resetting: “— No role for these forums —”
-
Hello,
I am running bbPress v2.5.12 on WordPress 4.7 with a child theme I’ve developed based on Imaginem Themes’ Sentric Theme.
The problem:
In my child theme’s functions, I have added the following code to make two custom roles, Professional and Member, for my Q&A/”Ask the Expert”-style forum called “Ask a Professional.” Essentially, Members can make threads asking questions, but only screened Professionals have the ability to reply and provide answers.I want everyone to automatically be assigned the Member role upon registration. Then I can manually “upgrade” their roles to Professional once they’ve been successfully screened. However, when a user registers and logs in, they inherit Member capabilities, but are not assigned the Member role. Manually selecting the user and assigning them the Member role doesn’t work; their role immediately reverts back to “— No role for these forums —”
When I select the user and manually assign the Participant role, the role “sticks” — meaning, it doesn’t revert back to “No Role.” However, the “Member” capabilities remain.
Does anyone know why this problem persists and how to fix it? This is the final thing that needs to be ironed out before my site goes live. 🙂 Thank you!
//code to add custom roles function add_new_roles( $bbp_roles ) { /* Add a role called professional */ $bbp_roles['bbp_professional'] = array( 'name' => 'Professional', 'capabilities' => custom_capabilities( 'bbp_professional' ) ); /* Add a role called member */ $bbp_roles['bbp_member'] = array( 'name' => 'Member', 'capabilities' => custom_capabilities( 'bbp_member' ) ); 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_professional' ) $caps = custom_capabilities( $role ); if( $role == 'bbp_member' ) $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 'professional' role */ case 'bbp_professional': return array( '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' => true, // Topic caps 'publish_topics' => true, 'edit_topics' => true, 'edit_others_topics' => false, 'delete_topics' => true, 'delete_others_topics' => true, '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' => true, 'edit_topic_tags' => true, 'delete_topic_tags' => true, 'assign_topic_tags' => true, ); /* 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' => false, 'edit_replies' => false, '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' => false, ); break; default : return $role; } }
Troubleshooting:
- I’ve tried to disable plugins and see if any of them are causing this issue. This hasn’t yielded any different results.
- I’ve checked with the Twenty Sixteen and Twenty Seventeen theme.
- You must be logged in to reply to this topic.