评论回复后,自动发一封邮件提醒评论人,是提高用户体验的一大举措。今天抽空研究了一下邮件回复,根据自己的需要,选择一种自己需要的代码,添加在主题的 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 = "$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 '<label for="comment_mail_notify">有人回复时邮件通知我';
}
add_action('comment_form','add_checkbox');
<h3 id="备注说明">备注说明
发送邮件,需要主机支持 mail() 函数,如果你发现没办法收到邮件,可以询问你的主机商。由于每个人的主机环境不一样,有些朋友在添加这个功能的时候,总是不能成功,这时候,你可以试试 的方式。
总结以上是内存溢出为你收集整理的WordPress添加评论回复邮件提醒通知功能全部内容,希望文章能够帮你解决WordPress添加评论回复邮件提醒通知功能所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)