如何禁止WordPress主題純英文評論教程

據(jù)觀察,WordPress 主題的博客中,大部分的垃圾評論都是全英文評論或者和含有日文字符的評論。
如果能夠禁止這些評論的提交,也就基本上達到了 WordPress 主題防止垃圾評論的目的了。
那么,有什么辦法可以讓W(xué)ordPress屏蔽純英文評論?
這里就記錄一種無插件純代碼實現(xiàn)禁止 WordPress 純外文垃圾評論的方法,只需要把所需的代碼復(fù)制到當(dāng)前主題的 functions.php 文件最后一個 ?> 的前面即可。
溫馨提示:如果主題更新,別忘了把代碼也重新添加一遍···
1、禁止全英文或者日文的評論
// 屏蔽純英文評論和純?nèi)瘴? function refused_english_comments($incoming_comment) { $pattern = '/[一-龥]/u'; // 禁止全英文評論 if(!preg_match($pattern, $incoming_comment['comment_content'])) { wp_die( "您的評論中必須包含漢字!" ); } $pattern = '/[あ-んア-ン]/u'; // 禁止日文評論 if(preg_match($pattern, $incoming_comment['comment_content'])) { wp_die( "評論禁止包含日文!" ); } return( $incoming_comment ); } add_filter('preprocess_comment', 'refused_english_comments');
2、禁止全英文、日文、俄文、韓文、阿拉伯文、泰文的評論
// 禁止全英日俄韓阿泰語評論 function ssdax_comment_all_post( $incoming_comment ) { $enpattern = '/[一-龥]/u'; $jpattern ='/[ぁ-ん]+|[ァ-ヴ]+/u'; $ruattern ='/[А-я]+/u'; $krattern ='/[?-?]+|[?-?]+|[?-?]+|[?-?]+|[?-?]+|[?-?]+|[?-?]+/u'; $arattern ='/[?-?]+|[?-?]+|[?-?]+/u'; $thattern ='/[?-?]+/u'; if(!preg_match($enpattern, $incoming_comment['comment_content'])) { err( "寫點漢字吧,博主外語很捉急! Please write some chinese words!" ); } if(preg_match($jpattern, $incoming_comment['comment_content'])){ err( "日文禁止!Japanese Get out!日本語出て行け!" ); } if(preg_match($ruattern, $incoming_comment['comment_content'])){ err( "禁止語種!Russians, get away!Savage выйти из Русского Севера!" ); } if(preg_match($krattern, $incoming_comment['comment_content'])){ err( "思密達的世界你永遠(yuǎn)不懂!Please do not use Korean!??? ???? ?? / ??? ???? ????!" ); } if(preg_match($arattern, $incoming_comment['comment_content'])){ err( "禁止使用阿拉伯語!Please do not use Arabic??!?? ???? ?? ?????? ????? ???????" ); } if(preg_match($thattern, $incoming_comment['comment_content'])){ err( "禁止泰語!Please do not use Thai!???????????????????!" ); } return( $incoming_comment ); } add_filter('preprocess_comment', 'ssdax_comment_all_post');
3、禁止評論內(nèi)容帶有鏈接
//禁止發(fā)鏈接 function wp_comment_post( $incoming_comment ) { $http = '/[href="|rel="nofollow"|http:\/\/|<\/a>]/u'; if(preg_match($http, $incoming_comment['comment_content'])) { err( "本站禁止發(fā)鏈接地址!" ); } return( $incoming_comment ); } add_filter('preprocess_comment', 'wp_comment_post');
? 版權(quán)聲明
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載。
相關(guān)文章
暫無評論...