The most effective code method for WordPress anti spam comments

WordPress anti spam comments are really necessary. Otherwise, a WP site with a little traffic will be given a list of spam comments. If you haven't logged into the WP background for a few days, it will be painful to delete it.

The free bar blog has been established for many years. The official Akismet anti spam plug-in of WP has been used before. To be honest, it has a certain anti spam comment effect, but the effect is still not obvious.

Later, the leisure bar installed several WP anti spam plug-ins, but they are the same as the Akismet anti spam plug-in. Many garbage comments escaped and were submitted to the WP background.

Now, free bar shares the simplest implementation method of WordPress anti spam comments. A few lines of code can solve the problem. Moreover, after free bar is enabled, there are almost no spam comments, and the time is clear.

WordPress anti garbage comment code:

/* refused spam */
function refused_spam_comments( $comment_data ) {
$pattern='/[one - 龥]/u';
$http = '/[href="|rel="nofollow"|http:\/\/|<\/a>]/u';
if(! Preg_match ($pattern, $comment_data ['comment_content ']) {wp_die ('Comments must contain Chinese!');}
Elseif (preg_match ($http, $comment_data ['comment_content '])) {wp_die ('Damned Poster!');}
return( $comment_data );
}
add_filter('preprocess_comment','refused_spam_comments');

The usage is very simple. Use the appearance management of the WP background to compile the functions.php in the enabled WP template style, add the above code to the back of the file, and then keep it.

If you cannot save it, you can modify it locally through FTP.

Remind me, if you change the WP style, remember to modify it again.

Copyright notice:
Author: Leisure Bar
Link: https://www.xianba.net/5045.html
Source: Xianba Resource Station
The copyright of this article belongs to the author. Please do not reprint it without permission.

THE END
share
QR code
< <Previous
Next>>