在某些互動性很強的WordPress部落格內,開啟嵌套評論是一種非常常見的方法,可是大部分訪客在發表評論後,很難知道有人曾回覆過他的評論,而今天暢想資源就來教大家如何純代碼在WordPress內添加評論回覆郵件提醒通知功能,讓訪客更加方便快捷的瞭解自己的評論近況!
預覽
教學
注意:使用該功能有可能(未經證實!)會由於類似群發而被服務商標識為垃圾郵件,一切後果自負!
提示:如果你需要在新文章發佈時郵件通知留言者,請見「【純代碼】WordPress向留言者發送新文章郵件通知教學」!
將下方代碼添加到「佈景函式庫 (functions.php)」的最底部 ?> 之前,然後點擊  即可~  
 
提示:你可以將下方代碼各高亮部分修改為你想要的配置!
注意:如果您的伺服器並不支持 mail 函數,請參考「這篇文章」並使用外部SMTP發送郵件即可!
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | /* 評論回覆郵件提醒通知功能開始(由AREFLY.COM製作) */ function comments_mail_notify($comment_id) { 	$admin_email = get_option('admin_email');			//發件人=站長郵箱 	//$admin_email = "info@domain.com";				//去除本行注釋可修改發件人郵箱! 	$comment = get_comment($comment_id); 	$comment_author_email = trim($comment->comment_author_email); 	$parent_id = $comment->comment_parent ? $comment->comment_parent : ''; 	$to = $parent_id ? trim(get_comment($parent_id)->comment_author_email) : ''; 	$spam_confirmed = $comment->comment_approved; 	if (($parent_id != '') && ($spam_confirmed != 'spam') && ($to != $admin_email)) { 		$wp_email = $admin_email; 		$to = trim(get_comment($parent_id)->comment_author_email); 		$subject = '您在「' . get_option("blogname") . '」的留言有了新回覆'; 		$message = ' <style> blockquote{ 	padding: 5px 10px; 	margin: 0 5px; 	border: 1px solid #ddd; 	/** border-left: 8px solid #ddd; **/ 	background-color: #e9e9e9; 	overflow: auto; 	border-left-width: 4px; 	font-family: inherit; } blockquote.code, pre{ 	font-family: "Courier New", sans-serif; 	padding: 5px 5px; 	margin: 0; } code{ 	padding: 2px 4px; 	color: #8A2908; 	background: rgba(0, 0, 0, 0.05); 	border: 1px solid rgba(0, 0, 0, 0.1); 	-webkit-border-radius: 3px; 	-moz-border-radius: 3px; 	border-radius: 3px; 	font-size: 12px; 	font-family: "Courier New", sans-serif; 	word-wrap: break-word; 	word-break: break-all; } kbd{ 	padding: 0.1em 0.6em; 	border: 1px solid #cccccc; 	font-size: 11px; 	font-family: Arial, Helvetica, sans-serif; 	background-color: #f7f7f7; 	color: #333333; 	-webkit-box-shadow: rgba(0, 0, 0, 0.2) 0 1px 0, white 0 0 0 2px inset; 	-moz-box-shadow: rgba(0, 0, 0, 0.2) 0 1px 0, white 0 0 0 2px inset; 	box-shadow: rgba(0, 0, 0, 0.2) 0 1px 0, white 0 0 0 2px inset; 	-webkit-border-radius: 3px; 	-moz-border-radius: 3px; 	-ms-border-radius: 3px; 	-o-border-radius: 3px; 	border-radius: 3px; 	text-shadow: white 0 1px 0; 	display: inline-block; 	margin: 0 0.1em; 	line-height: 1.4; 	text-indent: 0em; } p img:not(.wp-smiley){ 	-webkit-border-radius: 6px; 	-moz-border-radius: 6px; 	border-radius: 6px; 	max-width: 400px; 	width: expression(this.width > 400 ? "400px" : true); 	height: auto; } a{ 	color: #12addb; } </style> <div style="color: #555; font-size: 12px; font-family: \'Segoe UI\', \'Segoe\', \'Segoe WP\', \'Tahoma\', \'Microsoft YaHei\', sans-serif; -webkit-font-smoothing: antialiased; width: 600px; margin:0 auto; border: 1px solid #e9e9e9; border-top: none;"> 	<table border="0" cellspacing="0" cellpadding="0"> 		<tbody> 			<tr valign="top" height="2"> 				<td width="190" bgcolor="#0B9938"></td> 				<td width="120" bgcolor="#9FCE67"></td> 				<td width="85" bgcolor="#EDB113"></td> 				<td width="85" bgcolor="#FFCC02"></td> 				<td width="130" bgcolor="#5B1301" valign="top"></td> 			</tr> 		</tbody> 	</table> 	<div style="padding:0 15px 8px"> 		<h2 style="border-bottom: 1px solid #e9e9e9; font-size: 14px; font-weight: normal; padding: 10px 0 10px;"><span style="color: #12addb;">> </span>您在「<a style="text-decoration:none;color:#12addb" href="' . get_option("home") . '" title="' . get_option("blogname") . '" target="_blank">' . get_option("blogname") . '</a>」中的留言有新回覆啦!</h2> 		<div style="font-size:12px;color:#777;padding:0 10px;margin-top:18px"> 			<div class="im"> 				<p>' .trim(get_comment($parent_id)->comment_author) . ' 您好!</p> 				<p>您曾在本站文章「' . get_the_title($comment->comment_post_ID) . '」中發表留言:</p> 				<p style="background-color:#f5f5f5;padding:10px 15px;margin:18px 0"> ' .nl2br(get_comment($parent_id)->comment_content) . ' </p> 			</div> 			<p>「' . trim($comment->comment_author) . '」給您的回覆如下:</p> 			<p style="background-color:#f5f5f5;padding:10px 15px;margin:18px 0"> ' . nl2br($comment->comment_content) . ' </p> 			<p>您可以點擊「<a style="text-decoration:none; color:#12addb" href="' . htmlspecialchars(get_comment_link($parent_id)) . '" target="_blank">查看回覆的完整內容</a>」</p> 			<p>歡迎再次光臨「<a style="text-decoration:none; color:#12addb" href="' . get_option('home') . '" target="_blank">' . get_option('blogname') . '</a>」</p> 		</div> 	</div> 	<div style="color:#888;padding:10px;border-top:1px solid #e9e9e9;background:#f5f5f5"> 		<p style="margin:0;padding:0"><span style="color:#BDBDBD">© <a style="color: #888; text-decoration: none;" href="' . get_option("home") . '" title="' . get_option("blogname") . '" target="_blank">' . get_option("blogname") . '</a> 請添加 <a style="color:#BDBDBD" href="mailto:'.get_option('admin_email').'">'.get_option('admin_email').'</a> 至您的通訊錄,以便接收本站郵件,謝謝!</span></p> 	</div> </div> 		'; 		$message = do_shortcode(convert_smilies($message)); 		$from = "From: \"" . htmlspecialchars(get_option('blogname'),ENT_QUOTES) . "\" <$wp_email>"; 		$headers = "$from\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n"; 		wp_mail( $to, $subject, $message, $headers ); 		//echo 'Mail to '.$to.'<br/> '.$subject.$message;		//僅供測試! 	} } add_action('comment_post', 'comments_mail_notify'); /* 評論回覆郵件提醒通知功能結束(由AREFLY.COM製作) */ | 
 
		