Skip to content

Commit

Permalink
✨ 增加评论内容中必须含有中文字符支持
Browse files Browse the repository at this point in the history
  • Loading branch information
Licoy committed Apr 10, 2024
1 parent c75c2d9 commit 8b16ac6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions inc/fun/comment-ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions inc/setting/options/OptionValidate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 8b16ac6

Please sign in to comment.