我觉得有些人说的也对,总贴代码,可能滚去github比较好,但是我爱wordpress,我不会离开这里 /**系统原本定义的mail类型不支持HTML,所以需要挂一个新钩子:comment_notification_headers**/function xhd_mail2admin_2() {if ( '' == $comment-comment_author ) {
我觉得有些人说的也对,总贴代码,可能滚去github比较好,但是我爱wordpress,我不会离开这里
/**系统原本定义的mail类型不支持HTML,所以需要挂一个新钩子:comment_notification_headers**/ function xhd_mail2admin_2() { if ( '' == $comment->comment_author ) { $from = "From: \"$blogname\" "; if ( '' != $comment->comment_author_email ) $reply_to = "Reply-To: $comment->comment_author_email"; } else { $from = "From: \"$comment->comment_author\" "; if ( '' != $comment->comment_author_email ) $reply_to = "Reply-To: \"$comment->comment_author_email\" comment_author_email>"; } $message_headers = "$from\n" . "Content-Type: text/html; charset=\"" . get_option('blog_charset') . "\"\n"; return $message_headers; } add_filter('comment_notification_headers', 'xhd_mail2admin_2', 10, 2 ); /**在昨天代码基础上的美化**/ function xhd_mail2admin( $notify_message, $comment_id ) { $comment = get_comment( $comment_id ); $post = get_post( $comment->comment_post_ID ); $author = get_userdata( $post->post_author ); if ( $comment->user_id == $post->post_author ) return false; if ( $post->post_author == get_current_user_id() ) return false; if ( '' == $author->user_email ) return false; $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); $IPURL = 'http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip='.$comment->comment_author_IP; $json = file_get_contents($IPURL); $json = json_decode($json, true); $json = $json["country"].$json["province"].$json["city"].$json["district"].$json["isp"]; $notify_message = sprintf( __( '<div style="font: 12px 微软雅黑;width: 600px;margin: 20px auto;word-break: break-all;"> <table border="0" style="font: 15px 微软雅黑;border-collapse: collapse;width: 600px;margin: 20px auto;"><tbody> <tr> <td style="text-align: center;padding: 8px 15px;font: 15px 微软雅黑;border: 1px solid #ccc;" colspan="2">您的文章《%s》有新评论' ), $post->post_title ) . '</td>'; $notify_message .= sprintf( __('</tr> <tr> <td style="padding: 8px 15px;font: 15px 微软雅黑;border: 1px solid #ccc;width: 70px;">昵称 :</td> <td style="padding: 8px 15px;font: 15px 微软雅黑;border: 1px solid #ccc;"> %s '), $comment->comment_author ) . '</td>'; $notify_message .= sprintf( __('</tr> <tr> <td style="padding: 6px 15px;font: 15px 微软雅黑;border: 1px solid #ccc;">IP :</td> <td style="padding: 6px 15px;font: 15px 微软雅黑;border: 1px solid #ccc;"> %1$s ( %2$s ) '), $json, $comment->comment_author_IP ) . '</td> </tr> <tr> <td style="padding: 6px 15px;font: 15px 微软雅黑;border: 1px solid #ccc;">'; $notify_message .= sprintf( __('网站 :</td> <td style="padding: 8px 15px;font: 15px 微软雅黑;border: 1px solid #ccc;"> %s'), $comment->comment_author_url ) . '</td> </tr> <tr> <td style="padding: 8px 15px;font: 15px 微软雅黑;border: 1px solid #ccc;">'; $domain1 = $comment->comment_author_url ; $domain=substr($domain1,7); $startUrl = "http://toolbarqueries.google.com/tbr?client=navclient-auto&features=Rank&q=info:"; $resultUrl = $startUrl.$domain."&ch=".app_hash_url($domain); $array = get_headers($resultUrl,1); if(!preg_match('/403/',$array[0])){ $pageContent = file_get_contents($resultUrl); $pageRank = substr($pageContent,9); $notify_message .= sprintf( __('PR : </td> <td style="padding: 6px 15px;font: 15px 微软雅黑;border: 1px solid #ccc;"> %s'), $pageRank ) . '</td> </tr> <tr> <td style="padding: 6px 15px;font: 15px 微软雅黑;border: 1px solid #ccc;">'; } else { $notify_message .= __('PR : </td> <td style="padding: 6px 15px;font: 15px 微软雅黑;border: 1px solid #ccc;">0 ') . '</td> </tr> <tr> <td style="padding: 6px 15px;font: 15px 微软雅黑;border: 1px solid #ccc;">'; } $notify_message .= __('<div>评论内容 :</div> </td> <td style="padding: 6px 15px;font: 15px 微软雅黑;border: 1px solid #ccc;">') . $comment->comment_content . '</td> </tr> <tr> <td style="padding: 6px 15px;font: 15px 微软雅黑;border: 1px solid #ccc;">'; $notify_message .= sprintf( __('固定链接 :</td> <td style="padding: 6px 15px;font: 15px 微软雅黑;border: 1px solid #ccc;"> %s'), get_comment_link($comment) ) . '</td> </tr> </tbody></table> <br><div style="margin-left:10px">'; if ( EMPTY_TRASH_DAYS ) $notify_message .= sprintf( __('Trash it: %s'), admin_url("comment.php?action=trash&c=$comment_id") ) . "<br>"; else $notify_message .= sprintf( __('Delete it: %s'), admin_url("comment.php?action=delete&c=$comment_id") ) . "<br>"; $notify_message .= sprintf( __('Spam it: %s'), admin_url("comment.php?action=spam&c=$comment_id") ) . "<br> </div> </div>"; return $notify_message; } add_filter( 'comment_notification_text', 'xhd_mail2admin', 10, 2 );
效果见上一篇附图
原文地址:在主题函数修改系统通知邮件 美化篇, 感谢原作者分享。