From a38f1689099176bfd8a0e7bcdaf9c060eea22eb0 Mon Sep 17 00:00:00 2001 From: nanhaoluo <3075912108@qq.com> Date: Fri, 23 Jan 2026 18:32:54 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=A7=BB=E9=99=A4=E6=99=BA?= =?UTF-8?q?=E8=83=BD=E9=A2=84=E5=AE=A1=E6=9F=A5=EF=BC=8C=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E5=85=88=E4=BF=9D=E5=AD=98=E5=90=8E=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除所有智能预审查相关的设置和代码 - 评论先保存到数据库并标记为待审核状态 - AI 检测在评论保存后异步进行 - 检测完成后根据结果更新评论状态 - 避免误杀正常评论,提升用户体验 - 所有需要检测的评论都会显示为审核中 --- functions.php | 197 ++++++++++++-------------------------------------- settings.php | 35 +-------- 2 files changed, 48 insertions(+), 184 deletions(-) diff --git a/functions.php b/functions.php index cb71e3e..a7ac680 100644 --- a/functions.php +++ b/functions.php @@ -2836,18 +2836,18 @@ function post_comment_preprocessing($comment){ $comment['comment_content'] = comment_markdown_parse($comment['comment_content']); } - // AI 智能审查:在评论保存前进行检测和处理 + // AI 垃圾评论检测:如果启用了检测,将评论标记为待审核 if (get_option('argon_comment_spam_detection_enable', 'false') === 'true') { $mode = get_option('argon_comment_spam_detection_mode', 'manual'); - // 只有在启用了实时检测模式时才进行预审查 + // 只有在启用了实时检测模式时才需要审核 if ($mode !== 'manual') { // 检查是否为已登录用户(可跳过) $skip_logged_in = get_option('argon_comment_spam_detection_exclude_logged_in', 'true') === 'true'; $is_logged_in = is_user_logged_in(); if (!$is_logged_in || !$skip_logged_in) { - // 创建临时评论对象用于检测 + // 创建临时评论对象用于检查 $temp_comment = (object) [ 'comment_author' => $comment['comment_author'], 'comment_author_email' => $comment['comment_author_email'], @@ -2861,109 +2861,39 @@ function post_comment_preprocessing($comment){ // 检查白名单 if (!argon_is_comment_in_whitelist($temp_comment)) { $should_check = false; - $check_reason = ''; - // 优先级1:检查是否触发关键字 + // 检查是否触发关键字 $keyword_check = argon_check_spam_keywords($temp_comment); if ($keyword_check && $keyword_check['triggered']) { $should_check = true; - $check_reason = 'keyword'; } - // 优先级2:全量检测模式 + // 全量检测模式 elseif ($mode === 'all') { $should_check = true; - $check_reason = 'all'; } - // 优先级3:抽查模式(根据概率) + // 关键字必查模式(只检测触发关键字的) + elseif ($mode === 'keyword') { + // 已在上面检查过关键字 + } + // 抽查模式(根据概率) elseif ($mode === 'sample') { $check_probability = argon_get_user_spam_check_probability($temp_comment); if (rand(1, 100) <= $check_probability) { $should_check = true; - $check_reason = 'sample'; } } - // 如果需要检测,立即进行同步检测 + // 如果需要检测,将评论标记为待审核 if ($should_check) { - $result = argon_detect_spam_comment_sync($temp_comment); + // 强制设置为待审核状态 + $comment['comment_approved'] = 0; - if ($result && isset($result['is_spam'])) { - $content_spam = $result['is_spam']; - $username_invalid = isset($result['username_invalid']) ? $result['username_invalid'] : false; - $confidence = isset($result['confidence']) ? floatval($result['confidence']) : 0.8; - $suggestion = isset($result['suggestion']) ? $result['suggestion'] : 'auto'; - $confidence_threshold = floatval(get_option('argon_comment_spam_detection_confidence_threshold', 0.85)); - - // 情况1:内容违规且置信度高 - 直接拒绝评论 - if ($content_spam && $confidence >= $confidence_threshold && $suggestion === 'auto') { - wp_die( - '
-

⚠️ ' . __('评论审核未通过', 'argon') . '

-

' . __('您的评论因以下原因未能通过审核:', 'argon') . '

-
- ' . esc_html($result['reason']) . ' -
-

' . __('如果您认为这是误判,请联系网站管理员。', 'argon') . '

-
- ' . __('返回修改', 'argon') . ' -
-
', - __('评论审核未通过', 'argon'), - ['response' => 403, 'back_link' => true] - ); - } - - // 情况2:用户名违规且没有邮箱 - 直接拒绝评论 - if ($username_invalid && empty($comment['comment_author_email'])) { - wp_die( - '
-

⚠️ ' . __('用户名审核未通过', 'argon') . '

-

' . __('您的用户名因以下原因未能通过审核:', 'argon') . '

-
- ' . esc_html($result['username_reason']) . ' -
-

' . __('请修改用户名后重试,或填写邮箱以便我们为您自动生成合规的用户名。', 'argon') . '

-
- ' . __('返回修改', 'argon') . ' -
-
', - __('用户名审核未通过', 'argon'), - ['response' => 403, 'back_link' => true] - ); - } - - // 情况3:用户名违规但有邮箱 - 自动修改用户名 - if ($username_invalid && !empty($comment['comment_author_email'])) { - $original_username = $comment['comment_author']; - $new_username = argon_generate_unique_username( - $original_username, - $comment['comment_author_email'], - $comment['comment_author_IP'], - isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '' - ); - - // 修改评论数组中的用户名 - $comment['comment_author'] = $new_username; - - // 保存原始用户名和检测结果到 $_POST,稍后在 post_comment_updatemetas 中保存 - $_POST['_argon_original_username'] = $original_username; - $_POST['_argon_username_changed'] = 'true'; - $_POST['_argon_username_change_reason'] = $result['username_reason']; - $_POST['_argon_spam_detection_result'] = json_encode($result); - } - - // 情况4:内容违规但置信度不足 - 标记为待审核 - if ($content_spam && ($confidence < $confidence_threshold || $suggestion !== 'auto')) { - // 保存检测结果,稍后标记为待审核 - $_POST['_argon_spam_low_confidence'] = 'true'; - $_POST['_argon_spam_detection_result'] = json_encode($result); - } - - // 保存检测原因 - $_POST['_argon_spam_check_reason'] = $check_reason; - if ($keyword_check && $keyword_check['triggered']) { - $_POST['_argon_spam_triggered_keywords'] = json_encode($keyword_check['keywords']); - } + // 保存标记,表示需要 AI 检测 + $_POST['_argon_needs_spam_check'] = 'true'; + + // 保存触发的关键字 + if ($keyword_check && $keyword_check['triggered']) { + $_POST['_argon_spam_triggered_keywords'] = json_encode($keyword_check['keywords']); } } } @@ -3109,6 +3039,19 @@ function post_comment_updatemetas($id){ update_comment_meta($id, "qq_number", $_POST['qq']); } } + + // 保存 AI 垃圾评论检测相关的元数据 + if (isset($_POST['_argon_needs_spam_check']) && $_POST['_argon_needs_spam_check'] === 'true') { + update_comment_meta($id, '_argon_needs_spam_check', 'true'); + } + if (isset($_POST['_argon_spam_triggered_keywords'])) { + update_comment_meta($id, '_argon_spam_triggered_keywords', $_POST['_argon_spam_triggered_keywords']); + // 解析并保存检测原因 + $keywords = json_decode($_POST['_argon_spam_triggered_keywords'], true); + if (!empty($keywords)) { + update_comment_meta($id, '_argon_spam_check_reason', 'keyword'); + } + } } add_action('comment_post' , 'post_comment_updatemetas'); add_action('comment_unapproved_to_approved', 'comment_mail_notify'); @@ -8189,9 +8132,10 @@ function argon_auto_detect_spam_on_comment($comment_id, $comment_approved) { return; } - $mode = get_option('argon_comment_spam_detection_mode', 'manual'); - if ($mode === 'manual') { - return; + // 检查是否标记为需要检测 + $needs_check = get_comment_meta($comment_id, '_argon_needs_spam_check', true); + if ($needs_check !== 'true') { + return; // 没有标记,跳过 } $comment = get_comment($comment_id); @@ -8205,66 +8149,19 @@ function argon_auto_detect_spam_on_comment($comment_id, $comment_approved) { return; // 已检测过,跳过 } - // 跳过已登录用户 - if (get_option('argon_comment_spam_detection_exclude_logged_in', 'true') === 'true' && $comment->user_id > 0) { - return; + // 获取检测原因 + $check_reason = get_comment_meta($comment_id, '_argon_spam_check_reason', true); + if (empty($check_reason)) { + $check_reason = 'unknown'; } - // 检查白名单 - if (argon_is_comment_in_whitelist($comment)) { - return; - } - - // 判断是否需要检测 - $should_check = false; - $check_reason = ''; - - // 检查是否触发关键字 - $keyword_check = argon_check_spam_keywords($comment); - $keyword_triggered = $keyword_check && $keyword_check['triggered']; - - // 根据检测模式决定是否检测 - if ($mode === 'keyword') { - // 关键字必查模式:只检测触发关键字的评论 - if ($keyword_triggered) { - $should_check = true; - $check_reason = 'keyword'; - update_comment_meta($comment_id, '_argon_spam_triggered_keywords', $keyword_check['keywords']); - } - } elseif ($mode === 'all') { - // 全量检测模式:检测所有评论 - $should_check = true; - $check_reason = $keyword_triggered ? 'keyword' : 'all'; - if ($keyword_triggered) { - update_comment_meta($comment_id, '_argon_spam_triggered_keywords', $keyword_check['keywords']); - } - } elseif ($mode === 'sample') { - // 智能抽查模式:关键字触发或随机抽查 - if ($keyword_triggered) { - $should_check = true; - $check_reason = 'keyword'; - update_comment_meta($comment_id, '_argon_spam_triggered_keywords', $keyword_check['keywords']); - } else { - // 根据用户历史通过率动态调整概率 - $check_probability = argon_get_user_spam_check_probability($comment); - if (rand(1, 100) <= $check_probability) { - $should_check = true; - $check_reason = 'sample'; - } - } - } - - if ($should_check) { - // 保存检测原因 - update_comment_meta($comment_id, '_argon_spam_check_reason', $check_reason); - - // 如果是关键字触发,立即同步检测(不延迟) - if ($check_reason === 'keyword') { - argon_async_spam_detection_handler($comment_id); - } else { - // 其他情况异步检测(延迟 1 秒执行,让评论元数据先保存) - wp_schedule_single_event(time() + 1, 'argon_async_spam_detection', [$comment_id]); - } + // 立即进行异步检测 + // 如果是关键字触发,立即同步检测 + if ($check_reason === 'keyword') { + argon_async_spam_detection_handler($comment_id); + } else { + // 其他情况异步检测(延迟 1 秒执行,让评论元数据先保存) + wp_schedule_single_event(time() + 1, 'argon_async_spam_detection', [$comment_id]); } } add_action('comment_post', 'argon_auto_detect_spam_on_comment', 10, 2); diff --git a/settings.php b/settings.php index fe9591e..f678d21 100644 --- a/settings.php +++ b/settings.php @@ -3908,7 +3908,7 @@ window.pjaxLoaded = function(){

-
+
@@ -3920,18 +3920,6 @@ window.pjaxLoaded = function(){

- -
- - -

-
- -

-
@@ -4154,26 +4142,6 @@ window.pjaxLoaded = function(){ - - - - - -

-
-
-
-
-
-
- -

- - - @@ -6844,7 +6812,6 @@ function argon_update_themeoptions(){ argon_update_option_checkbox('argon_comment_spam_detection_exclude_logged_in'); argon_update_option('argon_comment_spam_detection_keywords'); argon_update_option_checkbox('argon_comment_spam_detection_ai_learn'); - argon_update_option_checkbox('argon_comment_spam_detection_pre_check'); }