Home php教程 php手册 在主题函数修改系统通知邮件 美化篇

在主题函数修改系统通知邮件 美化篇

Jun 06, 2016 pm 08:09 PM
theme Revise function system beautify notify mail

我觉得有些人说的也对,总贴代码,可能滚去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 );
Copy after login

效果见上一篇附图

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Huawei's Qiankun ADS3.0 intelligent driving system will be launched in August and will be launched on Xiangjie S9 for the first time Huawei's Qiankun ADS3.0 intelligent driving system will be launched in August and will be launched on Xiangjie S9 for the first time Jul 30, 2024 pm 02:17 PM

On July 29, at the roll-off ceremony of AITO Wenjie's 400,000th new car, Yu Chengdong, Huawei's Managing Director, Chairman of Terminal BG, and Chairman of Smart Car Solutions BU, attended and delivered a speech and announced that Wenjie series models will be launched this year In August, Huawei Qiankun ADS 3.0 version was launched, and it is planned to successively push upgrades from August to September. The Xiangjie S9, which will be released on August 6, will debut Huawei’s ADS3.0 intelligent driving system. With the assistance of lidar, Huawei Qiankun ADS3.0 version will greatly improve its intelligent driving capabilities, have end-to-end integrated capabilities, and adopt a new end-to-end architecture of GOD (general obstacle identification)/PDP (predictive decision-making and control) , providing the NCA function of smart driving from parking space to parking space, and upgrading CAS3.0

Tips for dynamically creating new functions in golang functions Tips for dynamically creating new functions in golang functions Apr 25, 2024 pm 02:39 PM

Go language provides two dynamic function creation technologies: closure and reflection. closures allow access to variables within the closure scope, and reflection can create new functions using the FuncOf function. These technologies are useful in customizing HTTP routers, implementing highly customizable systems, and building pluggable components.

Always new! Huawei Mate60 series upgrades to HarmonyOS 4.2: AI cloud enhancement, Xiaoyi Dialect is so easy to use Always new! Huawei Mate60 series upgrades to HarmonyOS 4.2: AI cloud enhancement, Xiaoyi Dialect is so easy to use Jun 02, 2024 pm 02:58 PM

On April 11, Huawei officially announced the HarmonyOS 4.2 100-machine upgrade plan for the first time. This time, more than 180 devices will participate in the upgrade, covering mobile phones, tablets, watches, headphones, smart screens and other devices. In the past month, with the steady progress of the HarmonyOS4.2 100-machine upgrade plan, many popular models including Huawei Pocket2, Huawei MateX5 series, nova12 series, Huawei Pura series, etc. have also started to upgrade and adapt, which means that there will be More Huawei model users can enjoy the common and often new experience brought by HarmonyOS. Judging from user feedback, the experience of Huawei Mate60 series models has improved in all aspects after upgrading HarmonyOS4.2. Especially Huawei M

Considerations for parameter order in C++ function naming Considerations for parameter order in C++ function naming Apr 24, 2024 pm 04:21 PM

In C++ function naming, it is crucial to consider parameter order to improve readability, reduce errors, and facilitate refactoring. Common parameter order conventions include: action-object, object-action, semantic meaning, and standard library compliance. The optimal order depends on the purpose of the function, parameter types, potential confusion, and language conventions.

How to write efficient and maintainable functions in Java? How to write efficient and maintainable functions in Java? Apr 24, 2024 am 11:33 AM

The key to writing efficient and maintainable Java functions is: keep it simple. Use meaningful naming. Handle special situations. Use appropriate visibility.

Complete collection of excel function formulas Complete collection of excel function formulas May 07, 2024 pm 12:04 PM

1. The SUM function is used to sum the numbers in a column or a group of cells, for example: =SUM(A1:J10). 2. The AVERAGE function is used to calculate the average of the numbers in a column or a group of cells, for example: =AVERAGE(A1:A10). 3. COUNT function, used to count the number of numbers or text in a column or a group of cells, for example: =COUNT(A1:A10) 4. IF function, used to make logical judgments based on specified conditions and return the corresponding result.

Comparison of the advantages and disadvantages of C++ function default parameters and variable parameters Comparison of the advantages and disadvantages of C++ function default parameters and variable parameters Apr 21, 2024 am 10:21 AM

The advantages of default parameters in C++ functions include simplifying calls, enhancing readability, and avoiding errors. The disadvantages are limited flexibility and naming restrictions. Advantages of variadic parameters include unlimited flexibility and dynamic binding. Disadvantages include greater complexity, implicit type conversions, and difficulty in debugging.

Huawei will launch the Xuanji sensing system in the field of smart wearables, which can assess the user's emotional state based on heart rate Huawei will launch the Xuanji sensing system in the field of smart wearables, which can assess the user's emotional state based on heart rate Aug 29, 2024 pm 03:30 PM

Recently, Huawei announced that it will launch a new smart wearable product equipped with Xuanji sensing system in September, which is expected to be Huawei's latest smart watch. This new product will integrate advanced emotional health monitoring functions. The Xuanji Perception System provides users with a comprehensive health assessment with its six characteristics - accuracy, comprehensiveness, speed, flexibility, openness and scalability. The system uses a super-sensing module and optimizes the multi-channel optical path architecture technology, which greatly improves the monitoring accuracy of basic indicators such as heart rate, blood oxygen and respiration rate. In addition, the Xuanji Sensing System has also expanded the research on emotional states based on heart rate data. It is not limited to physiological indicators, but can also evaluate the user's emotional state and stress level. It supports the monitoring of more than 60 sports health indicators, covering cardiovascular, respiratory, neurological, endocrine,

See all articles