Tips for WordPress comments: How to quickly and effectively block non-Chinese spam comments with pure code

As an old WordPress user, I have also witnessed the continuous growth of WordPress. Many webmasters may first think of using WordPress when building their own websites. Wordpress is very suitable for newcomers in terms of security and ease of use. Although it is easy to build a website, non-Chinese spam comments appearing on the website must be a problem that many new webmasters must encounter, and today I will talk to you about the fast and effective WordPress pure code blocking non-Chinese comments tips.

There are many ways to block WordPress non-Chinese language comments on the Internet, and various masters have posted various methods and codes. Here is the code I collected on the Internet before and I am using it myself. I just wanted to share it when I was bored writing an article today, so that webmasters who have not blocked spam comments in time can quickly use it.

Add the following code to theme function.php

The code here uses the err method. If the theme you use cannot use the err method, you can replace err with the wp_die method. It depends on the method used by the theme in your website. Please use it reasonably.

 
 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

 $incoming_comment['comment_content'])){














err( "写点汉字吧!Please do not use Russians!Savage выйти из Русского Севера!" );
}
if(preg_match($krattern, $incoming_comment['comment_content'])){ err( "写点汉字吧!!Please do not use Korean!하시기 바랍니다 한국 / 한국어 사용하지 마십시 오!" ); } if(preg_match($arattern, $incoming_comment['comment_content'])){ err( "写点汉字吧!Please do not use Arabic!! Please do not use Arabic!" ); } if(preg_match($thattern, $incoming_comment['comment_content'])){ err( "写点汉字吧!Please do not use Thai!กรุณาอย่าใช้ภาษาไทย!" ); } return( $incoming_comment ); } add_filter('preprocess_comment', 'ssdax_comment_all_post'); ?>











Guess you like

Origin blog.csdn.net/winkexin/article/details/131801636