腾讯云服务器优惠活动华纳云香港服务器

WordPress如何使用纯代码禁止屏蔽英日俄韩阿泰语垃圾评论?

WordPress主题推荐
本站使用 comments-ajax.php 处理提交,用 err 输出错误信息,如果贵站没有使用 comments-ajax.php,那么请用 wp_die 输出错误信息!方法:将下面所有的 err 换成 wp_die,否则会出现 500 错误!

将以下相应代码放到当前主题的 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禁止非中文垃圾评论的方法(英日俄韩阿泰语)

本文地址:https://boke112.com/post/4650.html

赞 (2) 打赏
版权声明:本文内容来源于互联网资源,由 boke112百科 整理汇总!发布此文是出于传递更多信息之目的,若有来源标注错误或侵犯了您的合法权益,请联系我们,确认后马上更正或删除,谢谢!
香港云主机55元/年
wu