Products
GG网络技术分享 2025-03-18 16:15 0
此方法可以屏蔽特定的url、关键词、email等,非常方便。
首先登录后台,打开“设置 - 讨论”找到“禁止使用评论的关键字”,在里面添加需要屏蔽的字或词,一行一个。
首先打开主题文件(themes)下的function.php
文件,DUX主题是function_themes.php
,在文件里添加以下函数代码:
/* 评论验证 */function refused_spam_comments( $comment_data ) {
if( is_user_logged_in()){ return $comment_data;} //登录用户不验证
$pattern = '/[一-龥]/u'; //验证是否存在中文
if(!preg_match($pattern,$comment_data['comment_content'])) {
err('评论必须含中文!');
}
if( wp_blacklist_check($comment_data['comment_author'],$comment_data['comment_author_email'],$comment_data['comment_author_url'], $comment_data['comment_content'], $comment_data['comment_author_IP'], $comment_data['comment_agent'] )){
// header("Content-type: text/html; charset=utf-8");
err('你填写的某项信息或IP地址已被列入黑名单,无法进行评论,请文明评论!');
} else {
return $comment_data;
}
}
add_filter('preprocess_comment','refused_spam_comments');
如果修改之后提示报错就是位置放错了,一定要放到php的结束标签前,封装好的函数代码的后面或前面。
Demand feedback