添加代码后,需要进行测试,防止不生效,或者与现有代码、插件冲突。if (!function_exists('block_non_chinese_comments_on_submit')) {
/**
* 阻止不包含中文的评论提交
* @param $comment_id
* @return void
*/
function block_non_chinese_comments_on_submit($commentdata)
{
// 确保评论内容存在且不为空
if (empty($commentdata['comment_content'])) {
wp_die(new WP_Error('comment_empty', '错误:评论内容不能为空。« 返回', 200));
}
$comment_content = $commentdata['comment_content'];
// 检查评论内容是否包含中文字符
// [\p{Han}] 匹配任何 Unicode 编码的汉字字符
// /u 是 Unicode 模式修饰符,确保正确处理 UTF-8 字符串
...
继续阅读
(5)