From 4543ceb045c779a90513c926b478c2b1f86e98dd Mon Sep 17 00:00:00 2001 From: nanhaoluo <3075912108@qq.com> Date: Thu, 22 Jan 2026 13:35:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=82=AE=E4=BB=B6=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=92=8C=E5=9E=83=E5=9C=BE=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除所有邮件模板中的 emoji,表述正式化 - 为所有用户邮件添加退订功能支持 - 新增垃圾评论通知邮件模板(spam_notify) - 检测到垃圾评论时自动发送邮件给评论者 - 邮件包含识别理由、AI 模型、服务提供商、识别码等信息 - 提供查询识别详情和退订链接 --- email-templates/base.php | 56 +++++++++++++++++++++++-- email-templates/spam-notify.php | 74 +++++++++++++++++++++++++++++++++ functions.php | 6 +++ 3 files changed, 132 insertions(+), 4 deletions(-) create mode 100644 email-templates/spam-notify.php diff --git a/email-templates/base.php b/email-templates/base.php index cbaeab0..d915ebd 100644 --- a/email-templates/base.php +++ b/email-templates/base.php @@ -19,13 +19,13 @@ function argon_get_email_types() { 'description' => __('当博客收到新评论时发送给管理员', 'argon'), 'default_subject' => '[{{blog_name}}] 文章收到新评论', 'default_content' => '

文章收到新评论

-

{{commenter_name}} 在文章《{{post_title}}》中发表了评论:

+

用户 {{commenter_name}} 在文章《{{post_title}}》中发表了评论:

{{comment_content}}

{{#ai_spam_check}}
-

🤖 AI 内容审核

+

AI 内容审核

识别结果:{{#ai_is_spam}}疑似垃圾评论{{/ai_is_spam}}{{^ai_is_spam}}正常评论{{/ai_is_spam}}

{{#ai_spam_reason}}

识别理由:{{ai_spam_reason}}

{{/ai_spam_reason}} {{#ai_detection_code}}

识别码:{{ai_detection_code}}

{{/ai_detection_code}} @@ -50,6 +50,44 @@ function argon_get_email_types() { 'theme_color' => __('主题色', 'argon'), ), ), + 'spam_notify' => array( + 'name' => __('垃圾评论通知', 'argon'), + 'description' => __('当评论被 AI 识别为垃圾评论时发送给评论者', 'argon'), + 'default_subject' => '[{{blog_name}}] 您的评论未通过审核', + 'default_content' => '

评论审核通知

+

尊敬的用户 {{commenter_name}}

+

您在文章《{{post_title}}》中发表的评论未通过系统审核。

+
+

您的评论内容

+

{{comment_content}}

+
+
+

审核信息

+

识别结果:疑似不当内容

+

识别理由:{{ai_spam_reason}}

+

AI 模型:{{ai_model}}

+

服务提供商:{{ai_provider}}

+

识别码:{{ai_detection_code}}

+
+

如果您认为这是误判,请通过识别码查询详细信息或联系网站管理员申诉。

+

+ 查询识别详情 +

', + 'placeholders' => array( + 'blog_name' => __('博客名称', 'argon'), + 'post_title' => __('文章标题', 'argon'), + 'post_url' => __('文章链接', 'argon'), + 'commenter_name' => __('评论者名称', 'argon'), + 'comment_content' => __('评论内容', 'argon'), + 'ai_spam_reason' => __('AI 识别理由', 'argon'), + 'ai_model' => __('AI 模型', 'argon'), + 'ai_provider' => __('AI 服务提供商', 'argon'), + 'ai_detection_code' => __('AI 识别码', 'argon'), + 'query_url' => __('查询链接', 'argon'), + 'unsubscribe_url' => __('退订链接', 'argon'), + 'theme_color' => __('主题色', 'argon'), + ), + ), 'reply_notify' => array( 'name' => __('回复通知', 'argon'), 'description' => __('当评论收到回复时发送给原评论者', 'argon'), @@ -219,7 +257,7 @@ function argon_get_email_template_config($type) { /** * 获取邮件基础模板 HTML */ -function argon_get_email_base_template() { +function argon_get_email_base_template($include_unsubscribe = false) { $settings = argon_get_email_settings(); // 页眉部分 @@ -252,6 +290,14 @@ function argon_get_email_base_template() { } } + // 退订链接部分 + $unsubscribe_html = ''; + if ($include_unsubscribe) { + $unsubscribe_html = '

+ 退订邮件通知 +

'; + } + $template = ' @@ -291,6 +337,7 @@ function argon_get_email_base_template() {

' . esc_html($settings['footer_text']) . '

+ ' . $unsubscribe_html . ' @@ -428,7 +475,8 @@ function argon_send_email($to, $type, $vars = array()) { * 兼容旧版 API - 渲染邮件(已废弃,保留向后兼容) */ function argon_render_email($content, $vars = array()) { - $base_template = argon_get_email_base_template(); + $include_unsubscribe = isset($vars['unsubscribe_url']) && !empty($vars['unsubscribe_url']); + $base_template = argon_get_email_base_template($include_unsubscribe); $html = str_replace('{{email_content}}', $content, $base_template); $html = str_replace('{{email_subject}}', isset($vars['subject']) ? esc_html($vars['subject']) : '', $html); $html = argon_replace_placeholders($html, $vars, false); diff --git a/email-templates/spam-notify.php b/email-templates/spam-notify.php new file mode 100644 index 0000000..ffbb24a --- /dev/null +++ b/email-templates/spam-notify.php @@ -0,0 +1,74 @@ +comment_author_email)) { + return false; + } + + // 获取文章信息 + $post = get_post($comment->comment_post_ID); + if (!$post) { + return false; + } + + // 获取 AI 配置信息 + $provider = get_option('argon_ai_summary_provider', 'openai'); + $model = get_option('argon_ai_summary_model', ''); + + $provider_names = [ + 'openai' => 'OpenAI', + 'anthropic' => 'Anthropic', + 'deepseek' => 'DeepSeek', + 'qianwen' => '通义千问', + 'wenxin' => '文心一言', + 'doubao' => '豆包', + 'kimi' => 'Kimi', + 'zhipu' => '智谱', + 'siliconflow' => 'SiliconFlow' + ]; + + $provider_display = isset($provider_names[$provider]) ? $provider_names[$provider] : $provider; + + // 生成退订链接(使用通用的邮件退订机制) + $unsubscribe_token = md5($comment->comment_author_email . wp_salt()); + $unsubscribe_url = add_query_arg([ + 'action' => 'unsubscribe_spam_notify', + 'email' => urlencode($comment->comment_author_email), + 'token' => $unsubscribe_token + ], home_url()); + + // 准备模板变量 + $vars = array( + 'commenter_name' => $comment->comment_author, + 'post_title' => $post->post_title, + 'post_url' => get_permalink($post->ID), + 'comment_content' => $comment->comment_content, + 'ai_spam_reason' => isset($detection_result['reason']) ? $detection_result['reason'] : '', + 'ai_model' => $model, + 'ai_provider' => $provider_display, + 'ai_detection_code' => $detection_code, + 'query_url' => home_url('/ai-query?code=' . $detection_code), + 'unsubscribe_url' => $unsubscribe_url, + ); + + // 发送邮件 + return argon_send_email($comment->comment_author_email, 'spam_notify', $vars); +} diff --git a/functions.php b/functions.php index ad1245c..34b8992 100644 --- a/functions.php +++ b/functions.php @@ -283,6 +283,7 @@ require_once(get_template_directory() . '/email-templates/base.php'); require_once(get_template_directory() . '/email-templates/comment-notify.php'); require_once(get_template_directory() . '/email-templates/reply-notify.php'); require_once(get_template_directory() . '/email-templates/feedback-notify.php'); +require_once(get_template_directory() . '/email-templates/spam-notify.php'); //检测更新 require_once(get_template_directory() . '/theme-update-checker/plugin-update-checker.php'); @@ -7711,6 +7712,11 @@ function argon_async_spam_detection_handler($comment_id) { 'reason' => $result['reason'], 'action' => $auto_action ]); + + // 发送垃圾评论通知邮件给评论者 + if (!empty($comment->comment_author_email)) { + argon_send_spam_notify_email($comment, $result, $detection_code); + } } else { // 记录正常评论的检测结果 update_comment_meta($comment_id, '_argon_spam_detection_result', [