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

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

2014-11-17_093158_wpdaxue_com

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

代码法

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

/**
 * WordPress 评论通过审核后<a href="https://www.wpdaxue.com/tag/%e9%82%ae%e4%bb%b6%e9%80%9a%e7%9f%a5" title="查看与【邮件通知】相关的文章" target="_blank" rel="noopener">邮件通知</a>评论人
 * https://www.wpdaxue.com/comment-approved-email.html
 */
add_action('comment_unapproved_to_approved', 'wpdx_comment_approved');
function wpdx_comment_approved($comment){
    if (is_email($comment-&gt;comment_author_email)){
        $post_link = get_permalink($comment-&gt;comment_post_ID);
        $title = '您在【' . get_bloginfo('name') . '】的评论已通过审核';
 
        $body = '您在《&lt;a href="' . $post_link . '" target="_blank" &gt;' . get_the_title($comment-&gt;comment_post_ID) . '&lt;/a&gt;》中发表的评论已通过审核!&lt;br /&gt;&lt;br /&gt;';
        $body .= '&lt;strong&gt;您的评论:&lt;/strong&gt;&lt;br /&gt;';
        $body .= strip_tags($comment-&gt;comment_content) . '&lt;br /&gt;&lt;br /&gt;';
        $body .= '您可以:&lt;a href="' . get_comment_link($comment-&gt;comment_ID) . '" target="_blank"&gt;查看您的评论&lt;/a&gt;  |  &lt;a href="' . $post_link . '#comments" target="_blank"&gt;查看其他评论&lt;/a&gt;  |  &lt;a href="' . $post_link . '" target="_blank"&gt;再次阅读文章&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;';
        $body .= '欢迎再次光临【&lt;a href="' . get_bloginfo('url') . '" target="_blank" title="' . get_bloginfo('description') . '"&gt;' . get_bloginfo('name') . '&lt;/a&gt;】。';
        $body .= '&lt;br /&gt;&lt;br /&gt;注:此邮件为系统自动发送,请勿直接回复';
 
        @wp_mail($comment-&gt;comment_author_email, $title, $body, "Content-Type: text/html; charset=UTF-8");
    }
}

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

插件法

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

comment-approved_wpdaxue_com

你可以在后台插件安装界面搜索 Comment Approved 直接安装,或者在这里下载 Comment Approved

来源:

https://www.wpdaxue.com/comment-approved-email.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_33101.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?