修改wp自带的发送给管理员的评论通知邮件,不用动系统文件 原始方法: 修改系统文件wp-includes/pluggable.php中的 wp_notify_postauthor 函数 高端方法: 添加自定义function,挂钩到原函数 by小蝴蝶 相关的钩子: comment_notification_text 基本思路 function
修改wp自带的发送给管理员的评论通知邮件,不用动系统文件
- 原始方法: 修改系统文件wp-includes/pluggable.php中的
wp_notify_postauthor
函数 - 高端方法: 添加自定义function,挂钩到原函数 by小蝴蝶
- 相关的钩子:
comment_notification_text
- 基本思路
function xhd_mail2admin( $notify_message, $comment_id ) { //CODE } add_filter( 'comment_notification_text', 'xhd_mail2admin', 10, 2 );
进阶教程
实现效果: 增加了PR和IP归属地,对原有一些累赘的参数进行了删减,去掉了WHOIS,修改了查看评论的固定链接格式
首先扔一段pr查询解码的函数,具体原理见我以前写过的这篇欢迎访客之显示对方网站PR
function app_hash_url($url) { $seed = "Mining PageRank is AGAINST GOOGLE'S TERMS OF SERVICE."; $hash = 0x01020345; for ($i=0; $i<strlen ord>> 23) & 0x1FF) | $hash <p>然后是主代码</p> <pre class="brush:php;toolbar:false"> function xhd_mail2admin( $notify_message, $comment_id ) { /* wp_notify_postauthor原有参数 */ $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); /* ip归属地的api */ $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( __( 'New comment on your post "%s"' ), $post->post_title ) . "\r\n"; $notify_message .= sprintf( __('Author : %s '), $comment->comment_author ) . "\r\n"; $notify_message .= sprintf( __('IP: %1$s ( %2$s) '), $json, $comment->comment_author_IP ) . "\r\n"; //如果担心调用IP归属地造成评论提交变慢,可以把上一行改成下一行,注释去掉 //$notify_message .= sprintf( __('IP: %s '), $IPURL ) . "\r\n"; $notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n"; $notify_message .= sprintf( __('网站: %s'), $comment->comment_author_url ) . "\r\n"; /* PR */ $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 ) . "\r\n"; } else { $notify_message .= __('PR:0 ') . "\r\n"; } $notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n"; $notify_message .= sprintf( __('Permalink: %s'), get_comment_link($comment) ) . "\r\n";//修改了原本的格式,原格式不能精确跳转到评论位置 if ( EMPTY_TRASH_DAYS ) $notify_message .= sprintf( __('Trash it: %s'), admin_url("comment.php?action=trash&c=$comment_id") ) . "\r\n"; else $notify_message .= sprintf( __('Delete it: %s'), admin_url("comment.php?action=delete&c=$comment_id") ) . "\r\n"; $notify_message .= sprintf( __('Spam it: %s'), admin_url("comment.php?action=spam&c=$comment_id") ) . "\r\n"; return $notify_message; } add_filter( 'comment_notification_text', 'xhd_mail2admin', 10, 2 );
效果如图:


美化下一篇写
原文地址:在主题函数直接修改系统邮件通知, 感谢原作者分享。

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

에디트플러스 중국어 크랙 버전
작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음

ZendStudio 13.5.1 맥
강력한 PHP 통합 개발 환경

DVWA
DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는

맨티스BT
Mantis는 제품 결함 추적을 돕기 위해 설계된 배포하기 쉬운 웹 기반 결함 추적 도구입니다. PHP, MySQL 및 웹 서버가 필요합니다. 데모 및 호스팅 서비스를 확인해 보세요.

mPDF
mPDF는 UTF-8로 인코딩된 HTML에서 PDF 파일을 생성할 수 있는 PHP 라이브러리입니다. 원저자인 Ian Back은 자신의 웹 사이트에서 "즉시" PDF 파일을 출력하고 다양한 언어를 처리하기 위해 mPDF를 작성했습니다. HTML2FPDF와 같은 원본 스크립트보다 유니코드 글꼴을 사용할 때 속도가 느리고 더 큰 파일을 생성하지만 CSS 스타일 등을 지원하고 많은 개선 사항이 있습니다. RTL(아랍어, 히브리어), CJK(중국어, 일본어, 한국어)를 포함한 거의 모든 언어를 지원합니다. 중첩된 블록 수준 요소(예: P, DIV)를 지원합니다.
