WordPress实现自动拒绝垃圾评论的方法
框架(架构)  /  管理员 发布于 7年前   211
很多WordPress站长都经常受到垃圾评论的滋扰,针对这种情况,采用下面的代码可能会对你有所帮助。
将以下代码加入到functions.php页面中。
使用时任何包含在$bad_comment_content数组内的字符,都将会被自动拒绝留言。
复制代码代码如下:function in_comment_post_like($string, $array) {    
    foreach($array as $ref) { if(strstr($string, $ref)) { return true; } }    
    return false;   
}   
function drop_bad_comments() {   
    if (!empty($_POST['comment'])) {   
        $post_comment_content = $_POST['comment'];   
        $lower_case_comment = strtolower($_POST['comment']);   
        $bad_comment_content = array(   
'viagra',    
'hydrocodone',   
'hair loss',   
'xanax',   
'tramadol',   
'russian girls',   
'russian brides',   
'lorazepam',   
'adderall',   
'dexadrine',   
'no prescription',   
'oxycontin',   
'without a prescription',   
'sex pics',   
'family incest',   
'online casinos',   
'online dating',   
'cialis',   
'best forex',   
'amoxicillin'   
        );   
        if (in_comment_post_like($lower_case_comment, $bad_comment_content)) {   
$comment_box_text = wordwrap(trim($post_comment_content), 80, "\n  ", true);   
$txtdrop = fopen('/var/log/httpd/wp_post-logger/nullamatix.com-text-area_dropped.txt', 'a');   
fwrite($txtdrop, "  --------------\n  [COMMENT] = " . $post_comment_content . "\n  --------------\n");   
fwrite($txtdrop, "  [SOURCE_IP] = " . $_SERVER['REMOTE_ADDR'] . " @ " . date("F j, Y, g:i a") . "\n");   
fwrite($txtdrop, "  [USERAGENT] = " . $_SERVER['HTTP_USER_AGENT'] . "\n");   
fwrite($txtdrop, "  [REFERER  ] = " . $_SERVER['HTTP_REFERER'] . "\n");   
fwrite($txtdrop, "  [FILE_NAME] = " . $_SERVER['SCRIPT_NAME'] . " - [REQ_URI] = " . $_SERVER['REQUEST_URI'] . "\n");   
fwrite($txtdrop, '--------------**********------------------'."\n");   
header("HTTP/1.1 406 Not Acceptable");   
header("Status: 406 Not Acceptable");   
header("Connection: Close");   
wp_die( __('bang bang.') );   
        }   
    }   
}   
add_action('init', 'drop_bad_comments');
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
			Copyright·© 2019 侯体宗版权所有·
			粤ICP备20027696号
			 
			
