15 3月 2014

wp评论邮件通知代码+漂亮的评论样式

先谢豆腐同学,豆腐君的博客

<?php
// 评论回应邮件通知
function comment_mail_notify($comment_id) {
$admin_notify = ‘1’; // admin 要不要收回复通知 ( ‘1’=要 ; ‘0’=不要 )
$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 : ”;
global $wpdb;
if ($wpdb->query(“Describe {$wpdb->comments} comment_mail_notify”) == ”)
$wpdb->query(“ALTER TABLE {$wpdb->comments} ADD COLUMN comment_mail_notify TINYINT NOT NULL DEFAULT 0;”);
if (($comment_author_email != $admin_email && isset($_POST[‘comment_mail_notify’])) || ($comment_author_email == $admin_email && $admin_notify == ‘1’))
$wpdb->query(“UPDATE {$wpdb->comments} SET comment_mail_notify=’1′ WHERE comment_ID=’$comment_id'”);
$notify = $parent_id ? get_comment($parent_id)->comment_mail_notify : ‘0’;
$spam_confirmed = $comment->comment_approved;
if ($parent_id != ” && $spam_confirmed != ‘spam’ && $notify == ‘1’) {
$wp_email = ‘no-reply@’ . preg_replace(‘#^www.#’, ”, strtolower($_SERVER[‘SERVER_NAME’])); // e-mail 发出点, no-reply 可改为可用的 e-mail.
$to = trim(get_comment($parent_id)->comment_author_email);
$subject = ‘您在 [‘ . get_option(“blogname”) . ‘] 的留言有了新回复’;
$message = ‘
<div style=”background:#fff;zoom:1;position:relative;z-index:1;margin:50px auto;”><table width=”556″cellspacing=”0″cellpadding=”0″border=”0″align=”center”style=”margin: 0 auto; font: normal 12px/1 微软雅黑,Tahoma,Helvetica,Arial,sans-serif; background: #fff; line-height: 20px;”><tbody><tr><td height=”115″background=”http://aapple-code.qiniudn.com/header.jpg”><div style=”padding: 0 30px 40px;”><h2 style=”color:#fff;font-size:14px;font-weight:normal;padding:0;”><span style=”color: #ED5224″>&gt;&nbsp;</span>您在&nbsp;<a style=”text-decoration:none;color: #ED5224;”href=”‘ . get_option(‘home’) . ‘”title=”‘ . get_option(‘blogname’) . ‘”target=”_blank”>’ . get_option(‘blogname’) . ‘</a>&nbsp;中的留言有回复啦!</h2></div></td></tr><tr><td valign=”top”background=”http://aapple-code.qiniudn.com/body.jpg”style=”padding: 0 25px;”><table width=”100%”><tbody><tr><td><div style=”font-size:12px;color:#777;padding:0px 6px 1px;”>’ . trim(get_comment($parent_id)->comment_author) . ‘&nbsp;您曾在本站文章「&nbsp;’
. get_the_title($comment->comment_post_ID) . ‘&nbsp;」中发表留言:</p><p style=”color: #777;border: 1px solid #DDD;padding: 5px 8px 5px 8px;background-color: #FCFCFC;border-radius: 3px 3px 3px 3px;font-size: 12px;line-height: 22px;font-family: Consolas,Courier,minispace,Lucida Console;”>’ . nl2br(get_comment($parent_id)->comment_content) . ‘</p><p>「’ . trim($comment->comment_author) . ‘」&nbsp;給您的回复如下:</p><p style=”color: #777;border: 1px solid #DDD;padding: 5px 8px 5px 8px;background-color: #FCFCFC;border-radius: 3px 3px 3px 3px;font-size: 12px;line-height: 22px;font-family: Consolas,Courier,minispace,Lucida Console;”>’ . nl2br($comment->comment_content) . ‘</p><p>您可以点击「&nbsp;<a style=”text-decoration:none; color:#12addb”href=”‘ . htmlspecialchars(get_comment_link($parent_id)) . ‘”title=”单击查看回复的完整內容”target=”_blank”>&nbsp;查看回复的完整內容</a>」,欢迎再次光临&nbsp;「<a style=”text-decoration:none; color:#12addb”href=”‘ . get_option(‘home’) . ‘”title=”‘ . get_option(‘blogname’) . ‘”target=”_blank”>’ . get_option(‘blogname’) . ‘</a>」&nbsp;!</p></div></td></tr></tbody></table></td></tr><tr><td height=”15″background=”http://aapple-code.qiniudn.com/footer.jpg”></td></tr></tbody></table></div>’;
$from = “From: “” . get_option(‘blogname’) . “” <$wp_email>”;
$headers = “$fromnContent-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’);
// 自动勾选
function add_checkbox() {
echo ‘<input type=”checkbox” name=”comment_mail_notify” id=”comment_mail_notify” value=”comment_mail_notify” checked=”checked” style=”margin-left:0px;” /><label for=”comment_mail_notify”>有人回复时邮件通知我</label>’;
}
add_action(‘comment_form’, ‘add_checkbox’);
?>

这是豆腐的评论邮件样式.

使用方法:在主题的function.php中添加~(如果已经有这个类函数~请删除掉~)

 

这个样式超漂亮~如果谁有兴趣,去豆腐博客里评论下,他回复你~就可以看到啦~~~