演示链接:查看演示

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

为了有效控制垃圾评论,倡萌建议大家在后台 设置 – 讨论 中,设置一下评论必须审核后才显示,

 

但是这样设置以后,一旦评论通过审核了,是没有邮件通知评论人的,今天我们就来添加这个通知功能。

代码法

将下面的代码添加到当前主题的 functions.php 即可

 

/**

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

 * http://www.moke8.com/

 */

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");

    }

}

你可以根据自己的需要修改上面的代码,来实现某些样式和内容。注意修改functions.php文件后,要保存为 UTF-8 格式,否则可能出现乱码问题。

插件法

如果你觉得修改代码比较麻烦,也可以直接安装 Comment Approved 插件,启用该插件以后,在 设置 – Comment Approved 进入到设置界面:

你可以在后台插件安装界面搜索 Comment Approved 直接安装

THE END
喜欢就支持一下吧
点赞0 分享