xiu主题邮件评论回复美化

Author: 陌小雨Date: 2015-03-23View: 65

xiu主题自带的邮件评论回复很难看呀,样式太简洁了,陌小雨分享给大家陌小雨正在使用的xiu主题美化版,只需要替换主题目录functions.xiu.php文件中的下面代码即可:

/* 
 * comment notify
 * ====================================================
*/
add_action('comment_post','comment_mail_notify'); 
function comment_mail_notify($comment_id) {
  $admin_notify = '1'; 
  $admin_email = get_bloginfo ('admin_email'); 
  $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'])); 
    $to = trim(get_comment($parent_id)->comment_author_email);
    $subject = 'Hi,您在 [' . get_option("blogname") . '] 的留言有人回复啦!';
    $message = '
    <div style="color:#333;font:100 14px/24px microsoft yahei;">
      <p>' . trim(get_comment($parent_id)->comment_author) . ', 您好!</p>
      <p>您曾在《' . get_the_title($comment->comment_post_ID) . '》的留言:<br /> &nbsp;&nbsp;&nbsp;&nbsp; '
       . trim(get_comment($parent_id)->comment_content) . '</p>
      <p>' . trim($comment->comment_author) . ' 给您的回应:<br /> &nbsp;&nbsp;&nbsp;&nbsp; '
       . 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 style="color:#999">(此邮件由系统自动发出,请勿回复.)</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 );
  }
}

全部替换为下面的代码:

/* 
 * comment notify
 * ====================================================
*/
add_action('comment_post','comment_mail_notify'); 
function comment_mail_notify($comment_id) {
  $admin_notify = '1'; 
  $admin_email = get_bloginfo ('admin_email'); 
  $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'])); 
    $to = trim(get_comment($parent_id)->comment_author_email);
    $subject = 'Hi,您在 [' . get_option("blogname") . '] 的留言有人回复啦!';
    $message = '
      <div style="background: #f8f8f8; color: #666; font-size: 12px;">
      <div style="width: 570px; margin: 0 auto; background: #fff; padding: 25px 70px; border-top: 5px solid #FF5E52;">
      <div style="text-align: center; margin-bottom: 40px; line-height: 1.8em;">
      <h1 style="color: #333;">陌小雨</h1>
      <p style="text-indent: 1.3em;">每天分享WordPress建站技巧、主题、插件和屌丝福利心得 | 爱折腾、爱生活!</p>
      </div>
      <p style="font-size: 18px; color: #333;">' . trim(get_comment($parent_id)->comment_author) . ', 您好!</p>
      您曾在《' . get_the_title($comment->comment_post_ID) . '》上发表评论:<br /> &nbsp;&nbsp;&nbsp;&nbsp;<p style="border: 1px solid #eee; padding: 20px; margin: 15px 0;"> '
       . trim(get_comment($parent_id)->comment_content) . '</p>
      ' . trim($comment->comment_author) . ' 给您的回应:<br /> &nbsp;&nbsp;&nbsp;&nbsp; <p style="border: 1px solid #eee; padding: 20px; margin: 15px 0;"><a href="' . htmlspecialchars(get_comment_link($parent_id)) . '">'
       . trim($comment->comment_content) . '<br /></a></p>
      <p class="footer" style="border-top: 1px solid #DDDDDD; padding-top: 6px; margin-top: 15px; color: #838383; text-align: center;">你可以点击此链接 <a href="' . htmlspecialchars(get_comment_link($parent_id)) . '">查看完整內容</a>|欢迎再次来访 <a href="' . get_option('home') . '">' . get_option('blogname') . '</a></p>
      <p style="font-size: 18px; center;">点击图片可以随机查看一篇有趣文章,试试又不会怀孕!</p>
<p style="text-align: center;"><a href="https://dedewp.com/1-2" target="_blank"><img class="image aligncenter" src="https://dedewp.com/wp-content/uploads/random.png" alt="宣传图"  width="560" /></a></p>
<a style="display: block; width: 560px; height: 40px; background: #FF5E52; margin: 25px auto 40px; font-size: 16px; line-height: 40px; letter-spacing: 3px; color: #f8f8f8; text-align: center; text-decoration: none;" href="https://dedewp.com" target="_blank">发现更多精彩&gt;&gt;</a>
<div style="height: 118px; text-align: center; color: #999; border-top: 1px solid #ddd; padding-top: 15px;">
<div style="float: left; height: 115px; width: 279px; border-right: 1px solid #ddd;">
<p style="margin: 0 0 18px; line-height: 14px;">关于陌小雨</p>
<p style="margin: 0 auto; width: 200px; text-align: left;">80后,男,屌丝一枚。所以,您的支持就是我的动力,想要了解更多请点此查看 <a style="text-decoration: none; color: #c0392b;" href="https://dedewp.com/about" rel="nofollow">关于我们</a> ,加入我们或投稿 <a style="text-decoration: none; color: #c0392b;" href="https://dedewp.com/">请点击我</a>。</p>

</div>
<div style="float: left; width: 280px;">
<p style="margin: 0 0 18px; line-height: 14px;">关于本站</p>
<p style="margin: 0 auto; text-align: left; width: 200px;">「陌小雨」成立于2014年,分享WordPress技巧、主题、插件,分享福利和心得 | 助力WordPress菜鸟建站!</p>
</div>
</div>

<p style="text-align: center;color: #bbb;margin-top: 40px;">请不要回复该邮件。你收到它,是因为你曾经在「陌小雨」飘过。</p>
    </div></div></includetail></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 );
  }
}

使用前请自行替换上述代码中的文本和网址超链接