Change WordPress user roles and capabilities › Forums › Restrict or Permit access inside WordPress – how to › Prevent bbpress Particapant role from creating topics
Tagged: BBPress, participant, prevent topic creation
- This topic has 3 replies, 2 voices, and was last updated 4 years, 6 months ago by Vladimir.
-
AuthorPosts
-
19/05/2020 at 21:59 #6853susanrangitschSpectator
I’m trying to prevent all users with the Participant (bbpress) role from being able to create topics. They should only be able to reply to existing topics.
I’ve unchecked the box for publish_topics but my test users can still post new topics. What am I missing?
20/05/2020 at 04:51 #6855VladimirKeymasterbbPress checks if user can create topic ising the function from the bbpress/includes/users/template.php, #2253
function bbp_current_user_can_access_create_topic_form() { // Users need to earn access $retval = false; // Always allow keymasters if ( bbp_is_user_keymaster() ) { $retval = true; // Looking at a single forum & forum is open } elseif ( ( bbp_is_single_forum() || is_page() || is_single() ) && bbp_is_forum_open() ) { $retval = bbp_current_user_can_publish_topics(); // User can edit this topic } else { $retval = current_user_can( 'edit_topic', bbp_get_topic_id() ); } // Filter & return return (bool) apply_filters( 'bbp_current_user_can_access_create_topic_form', (bool) $retval ); }
It shows that some time bbPress checks publish_topics, some times ‘edit_topics. But the good news that bbPress offers custom filter
bbp_current_user_can_access_create_topic_form
where you can check you own capability, like ‘create_topics’ and participant role will can not create topics until you will not grant ‘create_topics’ to it. Like below:add_filter( 'bbp_current_user_can_access_create_topic_form', 'bbp_current_user_can_create_topic', 10, 1 ); function bbp_current_user_can_create_topic( $ret_val ) { $ret_val = current_user_can( 'create_topics' ); return $ret_val; }
You may add this code to the active theme’s functions.php file of or setup it as a Must Use plugin.
20/05/2020 at 21:13 #6856susanrangitschSpectatorThanks for the reply. I’m a little confused… I thought that this was one of the capabilities of the pro version of the plugin. If I’m having to enter code, that does not seem like the case.
21/05/2020 at 03:01 #6857VladimirKeymasterbbPress checks capability to create topic own way, not as WordPress itself does for any post type:
if ( current_user_can( $post_type_object->cap->create_posts ) ) {
That’s why URE Pro currently does not change bbPress logic to use ‘create_topics’ as expected, even with correspondent option is turned ON at URE’s settings. I will include the fix to the next update.
Thank you for pointing me this. You may use the solution offered above as a temporal workaround until I will publish the version of URE Pro which will support this correctly.
-
AuthorPosts
- You must be logged in to reply to this topic.