好久好久以前,wordpress的留言似乎(我已經忘了)可以自動寄信通知管理者要審核,回覆留言也會寄信通知留言者你的留言有人回覆你了,現在新版的wordpress似乎已經沒有這個功能,所以我想把它加回來
先參考了網路的文章 找到在2013年發表的外掛 Comment Reply by Admins Notifier,載點 發現竟然還可以用勒~於是乎我又自己加工了一下,最後經過一連串的測試,證實是可以使用的。
原本的程式碼
<?php/*Plugin Name: Comment Reply by Admins NotifierPlugin URI: http://www.yakuphoca.com/comment-reply-by-admins-notifier-plugin/Description: When you reply a comment as Admin or Editor, an E-mail will send a notify to commenter.Version: 2.0Author: Yakup HocaAuthor URI: http://www.yakuphoca.comLicense: GPL2*/// don’t load directlyif (!function_exists(‘add_action’)) {header(‘Status: 403 Forbidden’);header(‘HTTP/1.1 403 Forbidden’);exit();}add_action(‘comment_post’, ‘yh_comment_reply_by_admins_notifier’);function yh_comment_reply_by_admins_notifier($comment_id){$comment = get_comment($comment_id);if( $comment->comment_parent != 0 ){if( current_user_can( ‘moderate_comments’ ) ){$current_user = wp_get_current_user();if ( ($current_user->user_email == $comment->comment_author_email) ){$parent_comment = get_comment($comment->comment_parent);if($parent_comment->user_id != $current_user->ID){$email = $parent_comment->comment_author_email;$adminname = $current_user->display_name;$post = get_post($comment->comment_post_ID);$posttitle = esc_attr($post->post_title);$postlink = get_permalink($comment->comment_post_ID);$commentlink = get_comment_link($comment_id);$blogname = wp_specialchars_decode(get_option(‘blogname’), ENT_QUOTES);$subject = sprintf(‘Your Comment was Replied – %1$s’, $blogname);$notify_message = sprintf(‘%1$s (Admin of %2$s) replied to a comment you left on:’, $adminname, $blogname ) . ‘<br />’;$notify_message .= sprintf( ‘<a href=”%1$s”>%2$s</a>’, $postlink, $posttitle ) . “<br /><br />”;$notify_message .= ‘You can check admin\’s comment here: ‘ . “<br />”;$notify_message .= ‘<a href=”‘ . $commentlink . ‘”>’ . $commentlink . ‘</a><br /><br /><br />’;$notify_message .= ‘This e-mail was sent by <a href=”‘ . get_home_url() . ‘”>’ . $blogname . ‘</a><br />’;$notify_message .= ‘If the comment isn\’t belong to you, never mind about this e-mail.’ . “<br />”;$message_headers = “Content-Type: text/html; charset=\”” . get_option(‘blog_charset’) . “\”\n”;wp_mail( $email, $subject, $notify_message, $message_headers );}}}}}?>
*****************************
然後我把它翻譯了一下 (自行比對,或是直接複製修改)
<?php/*Plugin Name: Comment Reply by Admins NotifierPlugin URI: http://www.yakuphoca.com/comment-reply-by-admins-notifier-plugin/Description: When you reply a comment as Admin or Editor, an E-mail will send a notify to commenter.Version: 2.0Author: Yakup HocaAuthor URI: http://www.yakuphoca.comLicense: GPL2*/// don’t load directlyif (!function_exists(‘add_action’)) {header(‘Status: 403 Forbidden’);header(‘HTTP/1.1 403 Forbidden’);exit();}add_action(‘comment_post’, ‘yh_comment_reply_by_admins_notifier’);function yh_comment_reply_by_admins_notifier($comment_id){$comment = get_comment($comment_id);if( $comment->comment_parent != 0 ){if( current_user_can( ‘moderate_comments’ ) ){$current_user = wp_get_current_user();if ( ($current_user->user_email == $comment->comment_author_email) ){$parent_comment = get_comment($comment->comment_parent);if($parent_comment->user_id != $current_user->ID){$email = $parent_comment->comment_author_email;$adminname = $current_user->display_name;$post = get_post($comment->comment_post_ID);$posttitle = esc_attr($post->post_title);$postlink = get_permalink($comment->comment_post_ID);$commentlink = get_comment_link($comment_id);$blogname = wp_specialchars_decode(get_option(‘blogname’), ENT_QUOTES);$subject = sprintf(‘你的留言已經有人回應你了,在%1$s的部落格’, $blogname);$notify_message = sprintf(‘%1$s已經在%2$s的部落格文章主題中回應你的留言,文章如下網址:’, $adminname, $blogname ) . ‘<br />’;$notify_message .= sprintf( ‘<a href=”%1$s”>%2$s</a>’, $postlink, $posttitle ) . “<br /><br />”;$notify_message .= ‘你也可以直接點選下面這個網址直達你的留言處: ‘ . “<br />”;$notify_message .= ‘<a href=”‘ . $commentlink . ‘”>’ . $commentlink . ‘</a><br /><br /><br />’;$notify_message .= ‘這個E-Mail的出處是 <a href=”‘ . get_home_url() . ‘”>’ . $blogname . ‘</a><br />’;$notify_message .= ‘如果你沒有在任天堂的部落格留言過請忽略並刪除此E-Mail’ . “<br />”;$message_headers = “Content-Type: text/html; charset=\”” . get_option(‘blog_charset’) . “\”\n”;wp_mail( $email, $subject, $notify_message, $message_headers );}}}}}?>
這樣寄出來的信如下
還有這個
謝謝您的閱讀
如果對我寫的文章內容有任何問題,歡迎在底下留言讓我知道
如果對於文章有想要留言反饋的也歡迎一起討論
我是任天堂543亂亂寫的Sega
Leave a Reply