bbPress: Limit New Topics per Member per Day
Caps how many new topics a member can start in 24 hours, which stops spammers and over-eager posters from flooding the forums.
Opens WPIDE on
Code
if ( ! function_exists( 'bbp_add_error' ) ) {
return;
}
$wpide_bbp_topics_per_day = 5;
add_filter( 'bbp_new_topic_pre_content', function ( $content ) use ( $wpide_bbp_topics_per_day ) {
$user_id = get_current_user_id();
if ( ! $user_id || current_user_can( 'moderate' ) ) {
return $content;
}
$recent = get_posts( array(
'post_type' => bbp_get_topic_post_type(),
'post_status' => 'any',
'author' => $user_id,
'date_query' => array( array( 'after' => '24 hours ago', 'column' => 'post_date_gmt' ) ),
'numberposts' => $wpide_bbp_topics_per_day,
'fields' => 'ids',
'no_found_rows' => true,
) );
if ( count( $recent ) >= $wpide_bbp_topics_per_day ) {
bbp_add_error( 'wpide_bbp_flood', sprintf( '<strong>Error:</strong> You can start up to %d topics a day. Please try again tomorrow.', $wpide_bbp_topics_per_day ) );
}
return $content;
} );
Notes
Replies are not limited. Moderators are exempt.
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.