WordPress无插件实现禁止全英文和链接垃圾评论方法

2018-07-2211:24:43网站建设与开发Comments2,827 views字数 868阅读模式

WordPress垃圾评论插件常用的有:SI CAPTCHA Anti-Spam、Akismet,但是本着少用插件的原则,我们可以从一些小的代码实现禁止一些特定的评论问题。比如我们发现大部分群发垃圾评论会带有链接,以及一些英文群发软件内容全是英文,我们可以特定的限制。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/4258.html

WordPress无插件实现禁止全英文和链接垃圾评论方法文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/4258.html

第一、需要内容带有中文、不能是日文文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/4258.html

// 评论中需要有中文 itbulu.com
function wp_refused_spam_comments($comment_data) {
$pattern = '/[一-龥]/u';
$jpattern = '/[ぁ-ん]+|[ァ-ヴ]+/u';
if (!preg_match($pattern, $comment_data['comment_content'])) {
err(__('评论中需要有一个汉字!'));
}
if (preg_match($jpattern, $comment_data['comment_content'])) {
err(__('不能有日文!'));
}
return ($comment_data);
}
add_filter('preprocess_comment', 'wp_refused_spam_comments');文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/4258.html

禁止全英文或者日文的评论,可以限制一些全英文发帖机器。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/4258.html

第二、禁止评论内容带有链接文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/4258.html

//禁止发链接 itbulu.com
function wp_comment_post( $incoming_comment ) {
$http = '/[href="|rel="nofollow"|http:\/\/|<\/a>]/u';
if(preg_match($http, $incoming_comment['comment_content'])) {
err( "禁止发链接地址!" );
}
return( $incoming_comment );
}
add_filter('preprocess_comment', 'wp_comment_post');文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/4258.html

根据需要,将两处代码添加到当前主题Functions.php中,可以在一定程度上比默认评论垃圾评论好一些。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/4258.html

  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/cms/4258.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定