当你回复了用户的评论,或用户之间的相互回复,通过邮件通知该用户,可以促进网站回流,增加用户黏度。
虽然网络上已经有了许多评论回复邮件通知代码,但感觉大多数都太过复杂了,毕竟我们只想要简单的一个通知功能,所以我自己写了一个。
function bzg_comment_mail_notify($comment_id) {$comment = get_comment($comment_id);$parent_id = $comment->comment_parent ? $comment->comment_parent : \'\';if($parent_id) {$blogname = get_bloginfo( \'name\' );$adminemail = get_bloginfo(\'admin_email\');$parent_email = get_comment($parent_id)->comment_author_email;$parent_name = get_comment($parent_id)->comment_author;$mail_title = $parent_name . \' 您在\' . $blogname . \'上的评论有了新回复\';$headers[] = \'From: \' . $blogname . \' < \' . $adminemail . \'>\';$headers[] = \'Content-Type: text/html; charset=UTF-8\';$comment_link = get_comment_link($comment_id, array(\'type\' => \'comment\'));$mail_txt = \'\';$mail_txt .= \'<p>\' . $parent_name . \' 您好!</p>\';$mail_txt .= \'<p>您曾在《\' . get_the_title($comment->comment_post_ID) . \'》的评论有了新的回复,您的评论内容为:</p>\';$mail_txt .= \'<p>\' . get_comment($parent_id)->comment_content . \'</p>\';$mail_txt .= \'<p>回复内容为:</p>\';$mail_txt .= \'<p>\' . get_comment($comment_id)->comment_content . \'</p>\';$mail_txt .= \'<p>您可以点击下面的链接查看详细内容:<br />\';$mail_txt .= \'<a href=\"\' . $comment_link . \'\">\' . $comment_link . \'</a></p>\';wp_mail( $parent_name . \' <\' . $parent_email . \'>\', $mail_title, $mail_txt, $headers );}}add_action(\'comment_post\', \'bzg_comment_mail_notify\');
将以上代码粘贴至主题文件functions.php中即可。
文章链接:https://www.jitheme.com/2516.html
更新时间:2024年03月28日
1.本站大部分内容均收集于网络!若内容若侵犯到您的权益,请发送邮件至:service@jitheme.com,我们将第一时间处理!
2.资源所需价格并非资源售卖价格,是收集、整理、编辑详情以及本站运营的适当补贴,并且本站不提供任何免费技术支持。
3.所有资源仅限于参考和学习,版权归原作者所有,更多请阅读极(子)主题网络服务协议。