将以下相应代码放到当前主题的 functions.php 文件最后一个 ?> 的前面即可。
1、屏蔽所有纯英语、日语、俄语、韩语、阿拉伯语、泰语评论
// 禁止全英日俄韩阿泰语评论
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( "思密达的世界你永远不懂!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');
2、屏蔽纯英语评论
// 禁止纯英文评论
function ssdax_comment_post( $incoming_comment ) {
$enpattern = '/[一-龥]/u';
if(!preg_match($enpattern, $incoming_comment['comment_content'])) {
err( "写点汉字吧,博主外语很捉急! Please write some chinese words!" );
}
return( $incoming_comment );
}
add_filter('preprocess_comment', 'ssdax_comment_post');
3、屏蔽纯日语评论
// 禁止日文评论
function ssdax_comment_jp_post( $incoming_comment ) {
$jpattern ='/[ぁ-ん]+|[ァ-ヴ]+/u';
if(preg_match($jpattern, $incoming_comment['comment_content'])){
err( "日文滚粗!Japanese Get out!日本語出て行け!" );
}
return( $incoming_comment );
}
add_filter('preprocess_comment', 'ssdax_comment_jp_post');
4、屏蔽纯俄语评论
//禁止北方野蛮人留言(俄语)
function ssdax_comment_ru_post( $incoming_comment ) {
$ruattern ='/[А-я]+/u';
if(preg_match($ruattern, $incoming_comment['comment_content'])){
err( "北方野人讲的话我们不欢迎!Russians, get away!Savage выйти из Русского Севера!" );
}
return( $incoming_comment );
}
add_filter('preprocess_comment', 'ssdax_comment_ru_post');
5、屏蔽纯韩语/朝鲜语评论
//禁止朝鲜半岛幸福人民留言(朝鲜语/韩语)
function ssdax_comment_kr_post( $incoming_comment ) {
$krattern ='/[갂-줎]+|[줐-쥯]+|[쥱-짛]+|[짞-쪧]+|[쪨-쬊]+|[쬋-쭬]+|[쵡-힝]+/u';
if(preg_match($krattern, $incoming_comment['comment_content'])){
err( "思密达的世界你永远不懂!Please do not use Korean!하시기 바랍니다 한국 / 한국어 사용하지 마십시오!" );
}
return( $incoming_comment );
}
add_filter('preprocess_comment', 'ssdax_comment_kr_post');
6、屏蔽纯阿拉伯语评论
//禁止阿拉伯语评论(部分)
function ssdax_comment_ar_post( $incoming_comment ) {
$arattern ='/[؟-ض]+|[ط-ل]+|[م-م]+/u';
if(preg_match($arattern, $incoming_comment['comment_content'])){
err( "禁止使用阿拉伯语!Please do not use Arabic!!من فضلك لا تستخدم اللغة العربية" );
}
return( $incoming_comment );
}
add_filter('preprocess_comment', 'ssdax_comment_ar_post');
7、屏蔽纯泰语评论
//禁止人妖部落留言(泰语)
function ssdax_comment_th_post( $incoming_comment ) {
$thattern ='/[ก-๛]+/u';
if(preg_match($thattern, $incoming_comment['comment_content'])){
err( "人妖你好,人妖再见!Please do not use Thai!กรุณาอย่าใช้ภาษาไทย!" );
}
return( $incoming_comment );
}
add_filter('preprocess_comment', 'ssdax_comment_th_post');
以上代码来自@伤逝的安详 – WordPress禁止非中文垃圾评论的方法(英日俄韩阿泰语)