0 0 0

子比主题美化 – 评论正则拦截验证代码

 陈哥 V UID:1 地仙境创始人
2025-05-04 370  来自 仙界

子比主题美化 – 评论正则拦截验证代码

教程

将代码放到/wp-content/themes/zibll/func.php文件即可。注意 此方法评论必须带中文 禁止了纯数字、纯字母和纯表情。

//屏蔽纯英文评论
function refused_english_comments($incoming_comment) {
    // 获取评论内容
    $comment_content = $incoming_comment['comment_content'];
    
    // 去除评论内容中的 [g=xxx] xxx为任意字符串
    $comment_content = preg_replace('/\[g=[^\]]*\]/', '', $comment_content);
    
    // 检查评论内容是否为空 
    if (empty($comment_content)) {
        wp_die('{"error":1,"ys":"danger","msg":"评论不能是纯表情内容 <br/>Comments cannot be purely emoji content"}');
    }
    
    // 检查评论内容是否包含中文
    $pattern = '/[一-龥]/u';
    
    // 禁止全英文评论
    if (!preg_match($pattern, $comment_content)) {
        wp_die('{"error":1,"ys":"danger","msg":"评论必须包括中文 <br/>Comments must include Chinese"}');
    }
    
    return $incoming_comment;
}
add_filter('preprocess_comment', 'refused_english_comments');
 
 

附件详情

  • 说明: 每次点击下载扣除1金币
  • 附件名:
    加载中...
  • 附件分类:
  • 账户经验: 0 点 [排行]
  • 账户金币: 0 个 [兑换]
  • 账户灵石: 0 枚 [充值]
  • 上传用户:  陈哥 时间:2025-05-04
  • 下载地址:
看过的人 (0)
最新回复 (0)

    暂无评论

请先登录后发表评论!

返回
每日签到
今日共2人签到
请先登录
周一
周二
周三
周四
周五
周六
周日

2025年乙巳年蛇年
13:36:00
公历日期
9月26日
农历日期
八月初五
星期
星期五
下午好
金秋时节,愿您收获满满
距离国庆节还有5天
请先登录后发表评论!