本文實(shí)例講述了WordPress評(píng)論禁止針對(duì)指定內(nèi)容全英文的方法。分享給大家供大家參考。具體分析如下:
WordPress評(píng)論中第一要過(guò)濾的是全英文的垃圾內(nèi)容了,這個(gè)簡(jiǎn)單我們只要檢查包括漢字就可以了,還有時(shí)我們希望有些敏感字不讓提交,只要一個(gè)簡(jiǎn)單的過(guò)濾函數(shù)即可.
有很多朋友可能會(huì)發(fā)現(xiàn)有大量的英文垃圾論內(nèi)容,下面給個(gè)函數(shù),代碼如下:
復(fù)制代碼
代碼如下:<?php
function scp_comment_post( $incoming_comment ) {
$pattern = '/[一-?]/u';
// 禁止全英文評(píng)論
if(!preg_match($pattern, $incoming_comment['comment_content'])) {
wp_die( "You should type some Chinese word (like "你好") in your comment to pass the spam-check, thanks for your patience! 您的評(píng)論中必須包含漢字!" );
}
return( $incoming_comment );
}
?>
function scp_comment_post( $incoming_comment ) {
$pattern = '/[一-?]/u';
// 禁止全英文評(píng)論
if(!preg_match($pattern, $incoming_comment['comment_content'])) {
wp_die( "You should type some Chinese word (like "你好") in your comment to pass the spam-check, thanks for your patience! 您的評(píng)論中必須包含漢字!" );
}
return( $incoming_comment );
}
?>
以下代碼禁止許評(píng)論中包含 <a 隨便 href=" 或者rel="nofollow"或者h(yuǎn)ttp://,你也可以根據(jù)自己的需要修改,代碼如下:
復(fù)制代碼
代碼如下:function lianyue_comment_post( $incoming_comment ) {
$http = '/[href="|rel="nofollow"|http://|</a>]/u';
if(preg_match($http, $incoming_comment['comment_content'])) {
wp_die( "萬(wàn)惡的發(fā)貼機(jī)!" );
}
return( $incoming_comment );
}
add_filter('preprocess_comment', 'lianyue_comment_post');
$http = '/[href="|rel="nofollow"|http://|</a>]/u';
if(preg_match($http, $incoming_comment['comment_content'])) {
wp_die( "萬(wàn)惡的發(fā)貼機(jī)!" );
}
return( $incoming_comment );
}
add_filter('preprocess_comment', 'lianyue_comment_post');
希望本文所述對(duì)大家的WordPress建站有所幫助。
【網(wǎng)站聲明】本站除付費(fèi)源碼經(jīng)過(guò)測(cè)試外,其他素材未做測(cè)試,不保證完整性,網(wǎng)站上部分源碼僅限學(xué)習(xí)交流,請(qǐng)勿用于商業(yè)用途。如損害你的權(quán)益請(qǐng)聯(lián)系客服QQ:2655101040 給予處理,謝謝支持。