Several main methods of wordpress filter Spam Comment Summary _php example

Source: Internet
Author: User
Tags comments

Because personal blog station space and MySQL space is often limited, shared server resources are limited, so spam comments must be intercepted in writing to the database.

More exasperating is to see the statistics of the space, very thousands of of IP access, but basically is this spam comment ip, so really can not endure

Find some methods on the Internet, there are mainly three, if the use of these three pieces can basically intercept most of the spam comments

first, the use of the Akismet plug-in (https://wordpress.org/plugins/akismet/), the background to apply for a free key, can intercept 99% of spam comments, but this plugin will still write spam comments to the database, A thousands of or even tens of thousands of spam comments, although you can set 15 days after the automatic deletion, but looked also awkward, and then add a second method.

Ii. Change of wp-comments-post.php name

This method is to first change wp-comments-post.php to casual name, and then in your subject document comments.php wp-comments-post.php to change the name you just changed

But now the spam robot is too strong, this method basically does not have any effect, the rubbish comment still will enter into backstage of rubbish comment, so take a third method, filter out the pure English rubbish comment, this kind of comment takes a large part of the rubbish comment

Third, filter pure english spam comments

Add the following code to the functions.php of your topic

 function refused_spam_comments ($comment _data) { 
  $pattern = '/[one-龥]/u '; 
  if (!preg_match ($pattern, $comment _data[' comment_content '))) { 
  Wp_die (' comments must contain Chinese! '); 
} 
  Return ($comment _data); 
Add_filter (' preprocess_comment ', ' refused_spam_comments ');

Where [A-龥] This regular expression represents all Chinese, then the pure english spam comment is filtered out, but there is another kind of spam comments, Japanese ...

Use the same method in Japanese, please write several common kana names into regular expressions ッ, ン, Superior, Industrial, グ, trade

 function Fuckjp_comment_post ($incoming _comment) {
  $http = '/[<|=|.| Friends | night | ktv|ッ|の|ン| | industry |グ| Trade |] /u ';
  if (Preg_match ($http, $incoming _comment[' comment_content ')) {
  Wp_die ("Japanese ad leave!");
}
  Return ($incoming _comment);
Add_filter (' preprocess_comment ', ' fuckjp_comment_post ');

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.