前几天发现回复被回复没有邮件通知,网上搜到到了解决方法。
https://www.wpdaxue.com/comment-mail-notify.html
使用后发现发出的邮件没有评论的链接很不方便,所以自己改了改。
其实只是将

您可以点击查看回复的完整內容

改为

<a href="'.get_permalink($comment->comment_post_ID).'#comment-'.$parent_id.'">您可以点击查看回复的完整內容</a>

而已。
修改后的代码如下,加入主题目录下function.php文件最后一个“?>”之前即可

/* 开始*/
function comment_mail_notify($comment_id) {
$admin_notify = '1'; // admin 要不要收回复通知 ( '1'=要 ; '0'=不要 )
$admin_email = get_bloginfo ('admin_email'); // $admin_email 可改为你指定的 e-mail.
$comment = get_comment($comment_id);
$comment_author_email = trim($comment-&gt;comment_author_email);
$parent_id = $comment-&gt;comment_parent ? $comment-&gt;comment_parent : '';
global $wpdb;
if ($wpdb-&gt;query("Describe {$wpdb-&gt;comments} comment_mail_notify") == '')
$wpdb-&gt;query("ALTER TABLE {$wpdb-&gt;comments} ADD COLUMN comment_mail_notify TINYINT NOT NULL DEFAULT 0;");
if (($comment_author_email != $admin_email &amp;&amp; isset($_POST['comment_mail_notify'])) || ($comment_author_email == $admin_email &amp;&amp; $admin_notify == '1'))
$wpdb-&gt;query("UPDATE {$wpdb-&gt;comments} SET comment_mail_notify='1' WHERE comment_ID='$comment_id'");
$notify = $parent_id ? get_comment($parent_id)-&gt;comment_mail_notify : '0';
$spam_confirmed = $comment-&gt;comment_approved;
if ($parent_id != '' &amp;&amp; $spam_confirmed != 'spam' &amp;&amp; $notify == '1') {
$wp_email = 'no-reply@' . preg_replace('#^www.#', '', strtolower($_SERVER['SERVER_NAME'])); // e-mail 发出点, no-reply 可改为可用的 e-mail.
$to = trim(get_comment($parent_id)-&gt;comment_author_email);
$subject = '您在 [' . get_option("blogname") . '] 的留言有了回复';
$message = '

<div style="background-color: #eef2fa; border: 1px solid #d8e3e8; color: #111; padding: 0 15px; -moz-border-radius: 5px; -webkit-border-radius: 5px; -khtml-border-radius: 5px;">

' . trim(get_comment($parent_id)-&gt;comment_author) . ', 您好!

您曾在《' . get_the_title($comment-&gt;comment_post_ID) . '》的留言:
'
. trim(get_comment($parent_id)-&gt;comment_content) . '

' . trim($comment-&gt;comment_author) . ' 给您的回复:
'
. trim($comment-&gt;comment_content) . '

<a href="'.get_permalink($comment-&gt;comment_post_ID).'#comment-'.$parent_id.'">您可以点击查看回复的完整內容</a>

欢迎再度光临 ' . get_option('blogname') . '

(此邮件由系统自动发送,请勿回复.)

</div>

';
$from = "From: \"" . get_option('blogname') . "\" &lt;$wp_email&gt;";
$headers = "$from\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n";
wp_mail( $to, $subject, $message, $headers );
}
}
add_action('comment_post', 'comment_mail_notify');

/* 自动加勾选栏 */
function add_checkbox() {
echo '<input id="comment_mail_notify" style="margin-left: 20px;" checked="checked" name="comment_mail_notify" type="checkbox" value="comment_mail_notify" /><label for="comment_mail_notify">有人回复时邮件通知我</label>';
}
add_action('comment_form', 'add_checkbox');

标签: 瞎折腾, 瞎折腾, WordPress, mail, 回复, 邮件

已有 2 条评论

  1. 嘻嘻,直接偷懒复制你的代码啦~

  2. 不支持mail函数哎

添加新评论