WordPress评论邮件告诉无插件完成思绪及代码

通常咱们喜爱应用Wordpress Thread Comment 或 Mail To Commenter这两款插件前者久未更新,已测支持WordPress2.9.2版本 其余的未测试,优点,不进渣滓箱,支持嵌套回复。
后者据网友反馈 该插件容易造成邮件提早 邮件进渣滓箱或收不到邮件的状况。
明天来经过无插件完成WordPress评论邮件告诉,先看成果:
办法:在主标题录的functions中添加以下代码:
 
/* comment_mail_notify v1.0 by willin kan. (無勾選欄) */
function comment_mail_notify($comment_id) {
$admin_email = get_bloginfo ('admin_email'); // $admin_email 可改為你指定的 e-mail.
$comment = get_comment($comment_id);
$comment_author_email = trim($comment->comment_author_email);
$parent_id = $comment->comment_parent ? $comment->comment_parent : '';
$to = $parent_id ? trim(get_comment($parent_id)->comment_author_email) : '';
$spam_confirmed = $comment->comment_approved;
if (($parent_id != '') && ($spam_confirmed != 'spam') && ($to != $admin_email) && ($comment_author_email == $admin_email)) {
/* 下面的判斷式,決定發出郵件的必要條件:
($parent_id != '') && ($spam_confirmed != 'spam'): 回覆的, 而且不是 spam 才可發, 必须!!
($to != $admin_email) : 不發給 admin.
($comment_author_email == $admin_email) : 只有 admin 的回覆才可發.
可視個人需要修正以上條件.
*/
$wp_email = '[email protected]' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME'])); // e-mail 發出點, no-reply 可改為可用的 e-mail.
$subject = '您在【' . get_option("blogname") . '】的留言有回复了!去看看吧 ^_^';
$message = '
<p style="margin: 1em 40px 1em 40px;background-color:#eef2fa;border:1px solid #d8e3e8;color:#111;padding: 0 15px;-moz-border-radius:5px;-webkit-border-radius:5px;-khtml-border-radius:5px;border-radius:5px;">
<p>Hi !<strong>' . trim(get_comment($parent_id)->comment_author) . '</strong>,您好!
您曾在<strong>《' . get_the_title($comment->comment_post_ID) . '》</strong>的留言有了新回复。</p></p>
<p style="margin: 1em 40px 1em 40px;background-color:#eef2fa;border:1px solid #d8e3e8;color:#111;padding: 0 15px;-moz-border-radius:5px;-webkit-border-radius:5px;-khtml-border-radius:5px;border-radius:5px;"><p><strong>
您</strong>说:' . trim(get_comment($parent_id)->comment_content) . '</p>
<p><strong>' . trim($comment->comment_author) . '</strong>说:
' . trim($comment->comment_content) . '</p>
<p>您能够点击<a href="' . htmlspecialchars(get_comment_link($parent_id)) . '">查看完好的回复內容。</a></p>
<p>欢送再度莅临 <a href="' . get_option('home') . '">' . get_option('blogname') . '</a></p>
<p>(此邮件由零碎主动发送,请勿回复。)</p></p>
';
$from = "From: \"" . get_option('blogname') . "\" <$wp_email>";
$headers = "$from\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n";
wp_mail( $to, $subject, $message, $headers );
echo 'mail to ', $to, '
' , $subject, $message; // for testing
}
}
add_action('comment_post', 'comment_mail_notify');
// -- END ----------------------------------------

已测试 兼容WordPress3.1版本及多款主题。

以上就是安达网络工作室关于《WordPress评论邮件通知无插件实现思路及代码》的一些看法。更多内容请查看本栏目更多内容!

本文相关话题: 评论 邮件通知 WordPress
版权声明:本文为 安达网络工作室 转载文章,如有侵权请联系我们及时删除。
相关文章
WordPress获取文章内容摘要的办法

本文实例讲述了WordPress获取文章内容摘要的办法。分享给大家供大家参考。详细如下: 第一个函数是讲述了能...

WordPress主题制造之模板文件的引入办法

get_template_part() 用来援用模板文件,相似于 get_header()、get_sidebar() 和 get_footer(),只不过这个...

wordpress全局变量$wpdb在哪里进行初始化申明

wordpress操作数据库用一个全局变量$wpdb来进行各种操作,应用的时分先在函数申明global $wpdb,而后调用它...

WordPress装置前的预备工作

要害字形容:工作 预备 装置 &nbsp 数据库 用户 创立 权限 应用 软件 解说 WordPress 的装置前的一些预备工...

容许 WordPress 上传恣意文件的办法

此时假如上传一个不在预约义的平安扩大名列表,如.lrc,会报错: File type does not meet security guidel...

wordpress完成读者墙的办法

本文实例讲述了wordpress完成读者墙的办法。分享给大家供大家参考。详细完成办法如下: 1.复制PAGE.php页面...

需求提交

客服服务