From 8b16ac65e97da21d018dcee49b14076e25179ade Mon Sep 17 00:00:00 2001 From: licoy Date: Wed, 10 Apr 2024 10:47:39 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E5=A2=9E=E5=8A=A0=E8=AF=84?= =?UTF-8?q?=E8=AE=BA=E5=86=85=E5=AE=B9=E4=B8=AD=E5=BF=85=E9=A1=BB=E5=90=AB?= =?UTF-8?q?=E6=9C=89=E4=B8=AD=E6=96=87=E5=AD=97=E7=AC=A6=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/fun/comment-ajax.php | 12 ++++++++++++ inc/setting/options/OptionValidate.php | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/inc/fun/comment-ajax.php b/inc/fun/comment-ajax.php index 813189a3..c26d2893 100755 --- a/inc/fun/comment-ajax.php +++ b/inc/fun/comment-ajax.php @@ -17,6 +17,18 @@ function pk_comment_err($msg, $refresh_code = true) exit(); } +function pk_check_comment_for_chinese($comment) { + $pattern = '/[\x{4e00}-\x{9fa5}]/u'; + if (!preg_match($pattern, $comment)) { + pk_comment_err('您的评论必须包含至少一个中文字符'); + } + return $comment; +} +if(pk_is_checked('vd_comment_need_chinese')){ + add_filter('pre_comment_content', 'pk_check_comment_for_chinese'); +} + + function pk_comment_ajax() { global $wpdb; diff --git a/inc/setting/options/OptionValidate.php b/inc/setting/options/OptionValidate.php index 3b970223..bef4353d 100644 --- a/inc/setting/options/OptionValidate.php +++ b/inc/setting/options/OptionValidate.php @@ -53,6 +53,13 @@ function get_fields(): array ] ] ], + [ + 'id' => 'vd_comment_need_chinese', + 'label' => __('评论内容中必须含有中文字符', PUOCK), + 'type' => 'switch', + 'tips' => __('开启后,评论中必须含有至少1个中文字符,否则将会被拦截', PUOCK), + 'sdt' => false, + ], [ 'id' => 'vd_kwd_access_reject', 'label' => __('恶意统计关键字访问屏蔽', PUOCK),