本文实例讲述了Wordpress主动将蕴含长链接的评论标志为渣滓评论的办法。分享给大家供大家参考。详细剖析如下:
如今大量的机器能够间接对WordPress博客进行评论并带有大量的衔接,这些带链接评论咱们定为渣滓评论了,这里就来给大家引见几个主动将蕴含长链接的评论标志为渣滓评论的办法.
办法一:此办法照旧是来自 Willin Kan 巨匠(惋惜他曾经加入WordPress圈),折腾很简略,间接将上面的代码放到主题的functions.php文件的最初一个 ?>后面即可,代码如下:
// 渣滓评论阻拦
class anti_spam {
function anti_spam() {
if ( !current_user_can('level_0') ) {
add_action('template_redirect', array($this, 'w_tb'), 1);
add_action('init', array($this, 'gate'), 1);
add_action('preprocess_comment', array($this, 'sink'), 1);
}
}
function w_tb() {
if ( is_singular() ) {
ob_start(create_function('$input','return preg_replace("#textarea(.*?)name=(["'])comment(["'])(.+)/textarea>#",
"textarea$1name=$2w$3$4/textarea><textarea name="comment" cols="100%" rows="4" style="display:none"></textarea>",$input);') );
}
}
function gate() {
if ( !emptyempty($_POST['w']) && emptyempty($_POST['comment']) ) {
$_POST['comment'] = $_POST['w'];
} else {
$request = $_SERVER['REQUEST_URI'];
$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '瞒哄';
$IP = isset($_SERVER["HTTP_X_FORWARDED_FOR"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] . ' (透过代理)' : $_SERVER["REMOTE_ADDR"];
$way = isset($_POST['w']) ? '手动操作' : '未经评论表格';
$spamcom = isset($_POST['comment']) ? $_POST['comment'] : null;
$_POST['spam_confirmed'] = "申请: ". $request. "n去路: ". $referer. "nIP: ". $IP. "n形式: ". $way. "n?热? ". $spamcom. "n -- 记载胜利 --";
}
}
function sink( $comment ) {
if ( !emptyempty($_POST['spam_confirmed']) ) {
if ( in_array( $comment['comment_type'], array('pingback', 'trackback') ) ) return $comment;
//办法一: 间接挡掉, ? die(); 后面两斜线?h除即可.
die();
//办法二: 标志为 spam, 留在材料库反省能否误判.
//add_filter('pre_comment_approved', create_function('', 'return "spam";'));
//$comment['comment_content'] = "[ 小墙判别这是 Spam! ]n". $_POST['spam_confirmed'];
}
return $comment;
}
}
$anti_spam = new anti_spam();
办法二:主动回绝蕴含特定要害词的渣滓评论,将上面的代码增加到主题的functions.php文件,本人依据需求,修正 $ bad_comment_content 数组的内容,任何蕴含在$ 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 (!emptyempty($_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');
function rkv_url_spamcheck( $approved , $commentdata ) {
return ( strlen( $commentdata['comment_author_url'] ) > 50 ) ? 'spam' : $approved;
}
add_filter( 'pre_comment_approved', 'rkv_url_spamcheck', 99, 2 );
心愿本文所述对大家的WordPress建站有所协助。
以上就是安达网络工作室关于《Wordpress自动将包含长链接的评论标记为垃圾评论的方法》的一些看法。更多内容请查看本栏目更多内容!
自带的导航菜单性能是 WordPress 3.0+ 中惟一执得让人眼睛一亮的性能了,在新做主题的进程中再一次让我眼睛...
WordPress 的 Media 库治理器只能从客户端抉择文件上传,Dion Hulse 开发了一个 Add From Server 插件,支...
本文实例讲述了Wordpress主动提取内容中第一张图片作缩略图的办法。分享给大家供大家参考。详细剖析如下: ...
本文实例讲述了WordPress完成黑白标签云的办法。分享给大家供大家参考。详细剖析如下: 黑白标签云咱们在很...
Hana Flv Player 是一个在 WordPress 中使用比拟宽泛的播放器插件, 该插件内置了5种媒体播放器,其播放文件...
more标签 这种办法应该是最灵敏的一种办法,操作也很简略,只要要你在编辑文章的时分拔出more标签 或许应用...