如何實現wordpress評論回復郵件通知

  用心的朋友們肯定發現瞭,網絡營銷博客最近開始特別的重視網站的用戶體驗度,最近幾篇文章都是關於增加用戶體驗度的wordpress功能優化。用過wordpress的朋友們肯定也都知道wordpress的強大,所以我在這裡就不吹噓瞭。

  對wordpress博客來說,評論可以說是網站的靈魂,也是體現網站人氣的一個至關重要的因素,像我的博客每天都會有很多的留言,(因為之前使用瞭Willin Kan 大師的屏蔽wordpress垃圾評論的方法,所以我網站裡的評論都是非機器人留言),那麼增加這些訪客對網站的粘度就顯得尤為重要瞭。

  很多wordpress博客的評論很多,但是卻很少看到作者的回復,那麼這就成瞭增加網站粘度的突破口,讓訪客能及時看到他在你網站留言的回復,並對你的網站進行再次回訪。如何實現wordpress評論回復郵件通知,大傢可以看下面的方法:

  在主題目錄的functions.php中增加以下代碼:

/* 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 = no-reply@ . preg_replace(#^www\.#, , strtolower($_SERVER[‘SERVER_NAME’])); // e-mail 發出點, no-reply 可改為可用的 e-mail.

$subject = 您在 [‘ . get_option(blogname) . ‘] 的留言有瞭回復;

$message =

<div style=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> . trim(get_comment($parent_id)->comment_author) . , 您好!</p>

<p>您曾在《 . get_the_title($comment->comment_post_ID) . 》發表的留言:<br />

. trim(get_comment($parent_id)->comment_content) . </p>

<p> . trim($comment->comment_author) . 給您的回復:<br />

. trim($comment->comment_content) . <br /></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>

</div>;

$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, <br/> , $subject, $message; // for testing

}

}

add_action(comment_post, comment_mail_notify);

// – END –
以上代碼加到functions.php的最後即可,本人以作測試!很完美!

本文地址:/you-jian-tong-zhi.html