WordPress评论通过审核后邮件通知评论人

当你在Wordpress设置-讨论里面打开了以下选项时,通过审核后是无法通知评论人评论通过了审核的

图片[1]-WordPress评论通过审核后邮件通知评论人-阿张同学

需要在主题的functions.php中添加以下代码

/**
 * WordPress 评论通过审核后邮件通知评论人
 */
add_action('comment_unapproved_to_approved', 'wpdx_comment_approved');
function wpdx_comment_approved($comment){
    if (is_email($comment->comment_author_email)){
        $post_link = get_permalink($comment->comment_post_ID);
        $title = '您在【' . get_bloginfo('name') . '】的评论已通过审核';

        $body = '您在《<a href="' . $post_link . '" target="_blank" >' . get_the_title($comment->comment_post_ID) . '</a>》中发表的评论已通过审核!<br /><br />';
        $body .= '<strong>您的评论:</strong><br />';
        $body .= strip_tags($comment->comment_content) . '<br /><br />';
        $body .= '您可以:<a href="' . get_comment_link($comment->comment_ID) . '" target="_blank">查看您的评论</a>  |  <a href="' . $post_link . '#comments" target="_blank">查看其他评论</a>  |  <a href="' . $post_link . '" target="_blank">再次阅读文章</a><br /><br />';
        $body .= '欢迎再次光临【<a href="' . get_bloginfo('url') . '" target="_blank" title="' . get_bloginfo('description') . '">' . get_bloginfo('name') . '</a>】。';
        $body .= '<br /><br />注:此邮件为系统自动发送,请勿直接回复';

        @wp_mail($comment->comment_author_email, $title, $body, "Content-Type: text/html; charset=UTF-8");
    }
}
图片[2]-WordPress评论通过审核后邮件通知评论人-阿张同学
functions插入代码示例

根据需求修改代码中的样式和内容。

如果需要邮件通知评论人回复信息请参考下面这篇文章

评论回复邮件通知

© 版权声明
THE END
喜欢就支持一下吧
点赞3赞赏 分享
评论 抢沙发
头像
拿起笔,写下你的梦想,你的人生就从此刻起航
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容