其实伦家不想这么快就发新文章的, 把美丽动人的玉照都顶下去了. 大家知道wordpress黑名单的评论会被自动标记为垃圾评论, 这个做法我感觉挺浪费资源的, 毕竟垃圾评论还是写入了数据库, 如果集中时间段被大量spam攻击, 这种黑名单机制对保护数据库无济于事, 然
其实伦家不想这么快就发新文章的, 把美丽动人的玉照都顶下去了.
大家知道wordpress黑名单的评论会被自动标记为垃圾评论, 这个做法我感觉挺浪费资源的, 毕竟垃圾评论还是写入了数据库, 如果集中时间段被大量spam攻击, 这种黑名单机制对保护数据库无济于事,
然后我写了个函数, 效果是直接拒绝符合黑名单条件的评论发表, 评论不会写入数据库
方法a : 以下代码扔到functions.php
function xhd_fuckspam($comment) {
if( is_user_logged_in()){ return $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");
exit('草你麻痹垃圾评论滚粗');
} else {
return $comment;
}
}
add_filter('preprocess_comment', 'xhd_fuckspam');方法B : 以下代码扔到comments-ajax.php (随便找个地方,比如检查评论太快那段函数后面)
if( wp_blacklist_check($comment_author,$comment_author_email,$comment_author_url, $comment_content )&&!is_user_logged_in()){//登录用户还是无压力...
err(__('草你麻痹垃圾评论滚粗'));
}两个方法效果和原理略有不同,
缺点: 由于comments-ajax是从表单内直接提取$_POST的的字段,所以无法匹配IP和agent类黑名单
fuck-spam is coded by xiaohudie. Any posts here is one hundred percent original, so please keep my link so as not to hurt this pretty girl
全网最新最细最实用WPS零基础入门到精通全套教程!带你真正掌握WPS办公! 内含Excel基础操作、函数设计、数据透视表等
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号