最新消息:本站所有跳转向bbs.ykit.cn的附件将全面停止,附件已转移到https://www.qingsj.com

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

wordpress教程 有客 1583浏览 1评论
为了有效控制垃圾评论,有客建议大家在后台 设置 – 讨论 中,设置一下评论必须审核后才显示,
但是这样设置以后,一旦评论通过审核了,是没有邮件通知评论人的,今天我们就来添加这个通知功能。
代码法
将下面的代码添加到当前主题的 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 = '您在《' . get_the_title($comment->comment_post_ID) . '》中发表的评论已通过审核!

';
$body .= '<strong>您的评论:</strong>
';
$body .= strip_tags($comment-&gt;comment_content) . '

';
$body .= '您可以:<a href="' . get_comment_link($comment-&gt;comment_ID) . '" target="_blank">查看您的评论</a> | <a href="' . $post_link . '#comments" target="_blank">查看其他评论</a> | <a href="' . $post_link . '" target="_blank">再次阅读文章</a>

';
$body .= '欢迎再次光临【<a title="' . get_bloginfo('description') . '" href="' . get_bloginfo('url') . '" target="_blank">' . get_bloginfo('name') . '</a>】。';
$body .= '

注:此邮件为系统自动发送,请勿直接回复';

@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 直接安装

转载请注明:有客帮 » WordPress 评论通过审核后邮件通知评论人

您必须 登录 才能发表评论!

网友最新评论 (1)

  1. cool
    Han8年前 (2014-12-06)