bbPress: Only Staff Can Start Topics in Announcement Forums
Stops regular members from creating new topics in chosen forums, such as Announcements, while still letting them reply.
Opens WPIDE on
Code
if ( ! function_exists( 'bbp_get_forum_id' ) ) {
return;
}
// Forum IDs where only staff start topics.
$wpide_bbp_staff_forums = array( 123 );
$wpide_bbp_allow_replies = true;
add_filter( 'bbp_current_user_can_access_create_topic_form', function ( $can ) use ( $wpide_bbp_staff_forums ) {
if ( current_user_can( 'moderate' ) ) {
return $can;
}
return in_array( (int) bbp_get_forum_id(), $wpide_bbp_staff_forums, true ) ? false : $can;
} );
add_filter( 'bbp_current_user_can_access_create_reply_form', function ( $can ) use ( $wpide_bbp_staff_forums, $wpide_bbp_allow_replies ) {
if ( $wpide_bbp_allow_replies || current_user_can( 'moderate' ) ) {
return $can;
}
return in_array( (int) bbp_get_topic_forum_id( bbp_get_topic_id() ), $wpide_bbp_staff_forums, true ) ? false : $can;
} );
// Also refuse topics posted to those forums directly.
add_filter( 'bbp_new_topic_pre_content', function ( $content ) use ( $wpide_bbp_staff_forums ) {
$forum_id = isset( $_POST['bbp_forum_id'] ) ? absint( $_POST['bbp_forum_id'] ) : 0;
if ( ! current_user_can( 'moderate' ) && in_array( $forum_id, $wpide_bbp_staff_forums, true ) ) {
bbp_add_error( 'wpide_bbp_staff_only', '<strong>Error:</strong> Only staff can start topics in this forum.' );
}
return $content;
} );
Notes
Staff means anyone with bbPress moderator rights. Set $wpide_bbp_allow_replies to false to block replies too.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.