首页 > php教程 > php手册 > 正文

在主题函数直接修改系统邮件通知

php中文网
发布: 2016-06-06 20:09:09
原创
1867人浏览过

修改wp自带的发送给管理员的评论通知邮件,不用动系统文件 原始方法: 修改系统文件wp-includes/pluggable.php中的 wp_notify_postauthor 函数 高端方法: 添加自定义function,挂钩到原函数 by小蝴蝶 相关的钩子: comment_notification_text 基本思路 function

修改wp自带的发送给管理员的评论通知邮件,不用动系统文件

  1. 原始方法: 修改系统文件wp-includes/pluggable.php中的wp_notify_postauthor函数
  2. 高端方法: 添加自定义function,挂钩到原函数 by小蝴蝶
  3. 相关的钩子: comment_notification_text
  4. 基本思路
  5. 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( $url); $i++) {
$hash ^= ord($seed{$i%87}) ^ ord($url{$i});
$hash = (($hash >> 23) & 0x1FF) | $hash << 9;
}
return sprintf("8%x", $hash);
}
登录后复制

然后是主代码

 
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 );
登录后复制

效果如图:

Shop7z网上购物系统普及版
Shop7z网上购物系统普及版

Shop7z网上购物系统是基于ASP开发的简单易用的商城建站平台,Shop7z可以满足不同企业、个人的各种网上开店需求!普及版是一套简便易用的商城系统,支持商品图片批量上传、淘宝导入、商品批量修改等实用功能,还支持手机版以及APP的整合,普及版支持4种不同的模板风格,支持支付宝、财付通、网银在线等支付接口,系统还支持新订单邮件通知、多种分类排序、商品归属多分类等功能,支持五种会员价格体系等。

Shop7z网上购物系统普及版 0
查看详情 Shop7z网上购物系统普及版
修改系统邮件通知效果仅供娱乐,么么哒

美化下一篇写
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门推荐
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号