From 5150b67339e732880fbb759ab203ae55fc0d116e Mon Sep 17 00:00:00 2001 From: nanhaoluo <3075912108@qq.com> Date: Thu, 22 Jan 2026 13:01:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E5=96=84=20AI=20=E5=9E=83?= =?UTF-8?q?=E5=9C=BE=E8=AF=84=E8=AE=BA=E8=AF=86=E5=88=AB=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 抽查基础概率可配置(默认 20%,可调整 1-100%) - 新增自动处理方式选项(移入回收站/标记待审核/仅标记) - 新增白名单功能(支持邮箱和 IP 地址) - 新增提示词预设模板选择(默认/严格/宽松/极简) - 实现白名单检查逻辑,白名单中的评论不会被检测 - 根据自动处理方式设置处理垃圾评论(trash/hold/mark) - 保存所有新增设置项到数据库 --- functions.php | 72 ++++++++++++++++++++++++++---- settings.php | 120 +++++++++++++++++++++++++++++++++++++------------- 2 files changed, 153 insertions(+), 39 deletions(-) diff --git a/functions.php b/functions.php index b3dd471..a8278cc 100644 --- a/functions.php +++ b/functions.php @@ -7475,6 +7475,11 @@ function argon_auto_detect_spam_on_comment($comment_id, $comment_approved) { return; } + // 检查白名单 + if (argon_is_comment_in_whitelist($comment)) { + return; + } + // 判断是否需要检测 $should_check = false; @@ -7494,14 +7499,49 @@ function argon_auto_detect_spam_on_comment($comment_id, $comment_approved) { } add_action('comment_post', 'argon_auto_detect_spam_on_comment', 10, 2); +/** + * 检查评论是否在白名单中 + * @param object $comment 评论对象 + * @return bool 是否在白名单中 + */ +function argon_is_comment_in_whitelist($comment) { + $whitelist = get_option('argon_comment_spam_detection_whitelist', ''); + if (empty($whitelist)) { + return false; + } + + // 按行分割白名单 + $whitelist_items = array_filter(array_map('trim', explode("\n", $whitelist))); + if (empty($whitelist_items)) { + return false; + } + + $comment_email = strtolower(trim($comment->comment_author_email)); + $comment_ip = trim($comment->comment_author_IP); + + foreach ($whitelist_items as $item) { + $item = strtolower(trim($item)); + if (empty($item)) { + continue; + } + + // 检查是否匹配邮箱或 IP + if ($item === $comment_email || $item === $comment_ip) { + return true; + } + } + + return false; +} + /** * 获取用户的垃圾评论检测概率(动态调整) * @param object $comment 评论对象 * @return int 检测概率(1-100) */ function argon_get_user_spam_check_probability($comment) { - // 基础抽查概率 - $base_probability = 20; + // 基础抽查概率(从设置中获取) + $base_probability = intval(get_option('argon_comment_spam_detection_sample_rate', '20')); // 获取用户标识(邮箱或 IP) $user_identifier = !empty($comment->comment_author_email) @@ -7600,13 +7640,29 @@ function argon_async_spam_detection_handler($comment_id) { argon_update_user_spam_stats($comment, $result['is_spam']); if ($result['is_spam']) { - // 移入回收站 - wp_trash_comment($comment_id); + // 获取自动处理方式 + $auto_action = get_option('argon_comment_spam_detection_auto_action', 'trash'); - // 记录日志 - update_comment_meta($comment_id, '_argon_spam_auto_trashed', true); - update_comment_meta($comment_id, '_argon_spam_trash_reason', $result['reason']); - update_comment_meta($comment_id, '_argon_spam_trash_time', time()); + if ($auto_action === 'trash') { + // 移入回收站 + wp_trash_comment($comment_id); + update_comment_meta($comment_id, '_argon_spam_auto_trashed', true); + } elseif ($auto_action === 'hold') { + // 标记为待审核 + wp_set_comment_status($comment_id, 'hold'); + update_comment_meta($comment_id, '_argon_spam_auto_held', true); + } else { + // 仅标记,不改变状态 + update_comment_meta($comment_id, '_argon_spam_marked', true); + } + + // 记录检测信息 + update_comment_meta($comment_id, '_argon_spam_detection_result', [ + 'is_spam' => true, + 'reason' => $result['reason'], + 'action' => $auto_action + ]); + update_comment_meta($comment_id, '_argon_spam_detection_time', time()); } } } diff --git a/settings.php b/settings.php index 6fd43c8..1892168 100644 --- a/settings.php +++ b/settings.php @@ -3875,44 +3875,52 @@ window.pjaxLoaded = function(){ /> -
- :
- :
-
- •
- •
- •
- •
- •
- •
- •
-
- :
+ :
+ :
+ :
+
+
+
+
+
+ :
+ :
+ :
+
+
+