评论回复后,自动发一封邮件提醒评论人,是提高用户体验的一大举措。今天抽空研究了一下邮件回复,根据自己的需要,选择一种自己需要的代码,添加在主题的 functions.php 文件的 最后一个 ?> 前面即可
comment_author_email);
$parent_id = $comment->comment_parent ? $comment->comment_parent : '';
global $wpdb;
if ($wpdb->query("Describe {$wpdb->comments} comment_mail_notify") == '')
$wpdb->query("ALTER TABLE {$wpdb->comments} ADD COLUMN comment_mail_notify TINYINT NOT NULL DEFAULT 0;");
if (($comment_author_email != $admin_email && isset($_POST['comment_mail_notify'])) || ($comment_author_email == $admin_email && $admin_notify == '1'))
$wpdb->query("UPDATE {$wpdb->comments} SET comment_mail_notify='1' WHERE comment_ID='$comment_id'");
$notify = $parent_id ? get_comment($parent_id)->comment_mail_notify : '0';
$spam_confirmed = $comment->comment_approved;
if ($parent_id != '' && $spam_confirmed != 'spam' && $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)->comment_author_email);
$subject = '您在 [' . get_option("blogname") . '] 的留言有了回复';
$message = '
' . trim(get_comment($parent_id)->comment_author) . ',您好!
您曾在《' . get_the_title($comment->comment_post_ID) . '》的留言:
'
. trim(get_comment($parent_id)->comment_content) . '
' . trim($comment->comment_author) . ' 给您的回复:
'
. trim($comment->comment_content) . '
您可以点击 comment_parent)). '" target="_blank">查看回复的完整內容
感谢您对 的关注,如您有任何疑问,欢迎在博客留言。
(此邮件由系统自动发送,请勿回复。)
';
$from = "From: "" . get_option('blogname') . "" <$wp_email>";
$headers = "$fromnContent-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 '<label for="comment_mail_notify">有人回复时邮件通知我';
}
add_action('comment_form','add_checkbox');
<h3 id="备注说明">备注说明
发送邮件,需要主机支持 mail() 函数,如果你发现没办法收到邮件,可以询问你的主机商。由于每个人的主机环境不一样,有些朋友在添加这个功能的时候,总是不能成功,这时候,你可以试试 的方式。 (编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|