Change WordPress user roles and capabilities › Forums › Restrict or Permit access inside WordPress – how to › Prevent bbpress Particapant role from creating topics › Reply To: Prevent bbpress Particapant role from creating topics
bbPress 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.