对于开启wordpress评论回复,如果没有限制设置,每天都会有很多垃圾评论,特别是一些英文、url、邮件评论等。wordpress 总是被人垃圾评论,可以通过相关插件、验证码等来防止恶意的垃圾评论攻击。将以下代码添加到你主题的模板函数 (functions.php)下可过滤外文评论、屏蔽关键词,email,url,ip等。
//屏蔽关键词,email,url,ip if (git_get_option('git_spam_keywords') && !is_user_logged_in()): function Googlofuckspam($comment) { if (wp_blacklist_check($comment['comment_author'], $comment['comment_author_email'], $comment['comment_author_url'], $comment['comment_content'], $comment['comment_author_IP'], $comment['comment_agent'])) { header("Content-type: text/html; charset=utf-8"); err(__('不好意思,您的评论违反本站评论规则')); } else { return $comment; } } add_filter('preprocess_comment', 'Googlofuckspam');
//过滤外文评论 if (git_get_option('git_spam_lang') && !is_user_logged_in()): function refused_spam_comments($comment_data) { $pattern = '/[一-龥]/u'; $jpattern = '/[ぁ-ん]+|[ァ-ヴ]+/u'; if (!preg_match($pattern, $comment_data['comment_content'])) { err(__('写点汉字吧,博主外语很捉急!You should type some Chinese word!')); } if (preg_match($jpattern, $comment_data['comment_content'])) { err(__('日文滚粗!Japanese Get out!日本语出て行け! You should type some Chinese word!')); } return ($comment_data); } add_filter('preprocess_comment', 'refused_spam_comments');
评论