Spam Comments Linking to Suspicious Domains
Sends comments to spam when the commenter's website field points to a domain ending you have chosen to distrust, such as .xyz, .top or .click.
Opens WPIDE on
Code
$wpide_spam_tlds = array( 'xyz', 'top', 'click', 'loan', 'work', 'icu', 'buzz', 'cam', 'rest' );
add_filter( 'pre_comment_approved', function ( $approved, $commentdata ) use ( $wpide_spam_tlds ) {
if ( 'spam' === $approved || empty( $commentdata['comment_author_url'] ) ) {
return $approved;
}
$host = strtolower( (string) wp_parse_url( $commentdata['comment_author_url'], PHP_URL_HOST ) );
$tld = substr( strrchr( '.' . $host, '.' ), 1 );
return in_array( $tld, $wpide_spam_tlds, true ) ? 'spam' : $approved;
}, 20, 2 );
Notes
Edit the endings at the top to match the spam you actually receive.
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.