bbPress: Minimum Length for Topics and Replies
Refuses very short forum posts such as "thanks" or "+1" by requiring a minimum number of characters in topics and replies.
Opens WPIDE on
Code
if ( ! function_exists( 'bbp_add_error' ) ) {
return;
}
$wpide_bbp_min_topic = 40;
$wpide_bbp_min_reply = 10;
add_filter( 'bbp_new_topic_pre_content', function ( $content ) use ( $wpide_bbp_min_topic ) {
if ( mb_strlen( trim( wp_strip_all_tags( (string) $content ) ) ) < $wpide_bbp_min_topic ) {
bbp_add_error( 'wpide_bbp_short', sprintf( '<strong>Error:</strong> Please describe your topic in at least %d characters.', $wpide_bbp_min_topic ) );
}
return $content;
} );
add_filter( 'bbp_new_reply_pre_content', function ( $content ) use ( $wpide_bbp_min_reply ) {
if ( mb_strlen( trim( wp_strip_all_tags( (string) $content ) ) ) < $wpide_bbp_min_reply ) {
bbp_add_error( 'wpide_bbp_short', sprintf( '<strong>Error:</strong> Replies need at least %d characters.', $wpide_bbp_min_reply ) );
}
return $content;
} );
Notes
Set separate limits for topics and replies at the top.
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.