Hold Comments Written in All Capitals
Sends comments that are mostly in capital letters to the moderation queue instead of publishing them straight away.
Opens WPIDE on
Code
// Share of uppercase letters (0 to 1) above which a comment is held.
$wpide_caps_ratio = 0.7;
add_filter( 'pre_comment_approved', function ( $approved, $commentdata ) use ( $wpide_caps_ratio ) {
if ( 1 !== $approved && '1' !== $approved ) {
return $approved;
}
$letters = preg_replace( '/[^\p{L}]/u', '', (string) $commentdata['comment_content'] );
$upper = preg_replace( '/[^\p{Lu}]/u', '', $letters );
if ( strlen( $letters ) >= 20 && strlen( $upper ) / strlen( $letters ) > $wpide_caps_ratio ) {
return 0;
}
return $approved;
}, 20, 2 );
Notes
Short comments (under 20 letters) are never held.
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.