How to quickly solve the problem of a large number of English comments being sent to WordPress through code

888u

Last update at :2024-01-29,Edit by888u

Many of our netizens have reported that during the process of building a WordPress website, they found that there are a lot of spam comments in the background comments every day, and it seems that these comments are not artificially sent in bulk. Indeed, we may encounter a lot of spam comments sent by software. For example, we may see a lot of English messages. This information will increase our daily deletion time cost, and it is also not good for the website. Is there any way we can solve this problem? Our most likely method is to add comment verification, which requires entering a verification code or other verification mechanisms when commenting. These are also good methods. Today, what we need to introduce is how to block these comments through two pieces of code.

1. Comment content needs to be in Chinese

What we see in the comments are all in English or other languages, not Chinese. Then we must comment in Chinese.

// Comments need to be in Chinese laobuluo.com function wp_refused_spam_comments($comment_data) { $pattern = '/[一-饥]/u'; $jpattern = '/[ぁ-ん]+|[ァ-ヴ]+/u'; if (!preg_match($pattern, $comment_data['comment_content'])) { err(__('There needs to be a Chinese character in the comment!')); } if (preg_match($jpattern, $comment_data['comment_content'])) { err(__('Cannot have Japanese!')); } return ($comment_data); } add_filter('preprocess_comment', 'wp_refused_spam_comments');

2. Links in comments are prohibited

Many people comment on the blog to promote the website. If we disable links, not many people will leave comments.

//It is forbidden to send links to laobuluo.com function wp_comment_post( $incoming_comment ) { $http = '/[href="|rel="nofollow"|http:\/\/|<\/a>]/u'; if(preg_match($http, $incoming_comment['comment_content'])) { err( "It is forbidden to send link address!" ); } return( $incoming_comment ); } add_filter('preprocess_comment', 'wp_comment_post');

It’s that simple, add two pieces of code to the Functions.php file in your current WordPress theme.

Recommended site searches: Hong Kong server, US ASP space, PHP space application, dynamic IP vps, free static space, virtual space host, domain name check, Chongqing virtual space, Hong Kong's best virtual host, website registration system,

p>

How to quickly solve the problem of a large number of English comments being sent to WordPress through code

All copyrights belong to 888u unless special state
取消
微信二维码
微信二维码
支付宝二维码