在主题函数修改系统通知邮件 美化篇
程序员文章站
2024-04-03 22:32:04
...
我觉得有些人说的也对,总贴代码,可能滚去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( __( '"; return $notify_message; } add_filter( 'comment_notification_text', 'xhd_mail2admin', 10, 2 );
您的文章《%s》有新评论' ), $post->post_title ) . ' '; $notify_message .= sprintf( __('昵称 : %s '), $comment->comment_author ) . ' '; $notify_message .= sprintf( __('IP : %1$s ( %2$s ) '), $json, $comment->comment_author_IP ) . ' '; $notify_message .= sprintf( __('网站 : %s'), $comment->comment_author_url ) . ' '; $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 : %s'), $pageRank ) . ' '; } else { $notify_message .= __('PR : 0 ') . ' '; } $notify_message .= __(' 评论内容 :') . $comment->comment_content . ' '; $notify_message .= sprintf( __('固定链接 : %s'), get_comment_link($comment) ) . ' '; if ( EMPTY_TRASH_DAYS ) $notify_message .= sprintf( __('Trash it: %s'), admin_url("comment.php?action=trash&c=$comment_id") ) . "
"; else $notify_message .= sprintf( __('Delete it: %s'), admin_url("comment.php?action=delete&c=$comment_id") ) . "
"; $notify_message .= sprintf( __('Spam it: %s'), admin_url("comment.php?action=spam&c=$comment_id") ) . "
效果见上一篇附图
原文地址:在主题函数修改系统通知邮件 美化篇, 感谢原作者分享。
推荐阅读