Files
argon-theme/email-templates/comment-notify.php
nanhaoluo 5c2f5514c0 feat: 重构邮件模板系统,支持多类型模板自定义
- 新增可扩展的邮件类型系统(评论通知、回复通知、用户注册、密码重置、通用邮件)
- 每种邮件类型支持自定义主题和内容模板
- 实现占位符系统,支持动态数据替换(如 {{blog_name}}、{{post_title}} 等)
- 添加邮件类型启用/禁用开关
- 设置页面新增模板编辑器,支持切换不同邮件类型
- 可用占位符点击即可插入到编辑框
- 支持恢复默认模板功能
- 保留向后兼容的旧版 API
- 通过 filter 钩子支持扩展更多邮件类型
2026-01-15 15:17:47 +08:00

51 lines
1.3 KiB
PHP

<?php
/**
* Argon 评论通知邮件
*
* 当博客收到新评论时发送给管理员的通知邮件
*/
if (!defined('ABSPATH')) {
exit;
}
/**
* 发送评论通知邮件给管理员
*
* @param WP_Comment $comment 评论对象
* @return bool 发送是否成功
*/
function argon_send_comment_notify_email($comment) {
// 获取文章信息
$post = get_post($comment->comment_post_ID);
if (!$post) {
return false;
}
// 获取管理员邮箱
$admin_email = get_option('admin_email');
if (empty($admin_email)) {
return false;
}
// 不给自己发通知
$comment_author_email = strtolower($comment->comment_author_email);
if ($comment_author_email === strtolower($admin_email)) {
return false;
}
// 准备模板变量
$vars = array(
'post_title' => $post->post_title,
'post_url' => get_permalink($post->ID),
'commenter_name' => $comment->comment_author,
'commenter_email' => $comment->comment_author_email,
'comment_content' => $comment->comment_content,
'comment_url' => get_comment_link($comment),
'comment_date' => get_comment_date(get_option('date_format') . ' ' . get_option('time_format'), $comment),
);
// 发送邮件
return argon_send_email($admin_email, 'comment_notify', $vars);
}