WordPress评论回复邮件通知,最大好处就是可以增加访问者对博客的粘性。
一、有勾选栏, 由访客决定是否要回应邮件通知
- comment_mail_notify() {
- = \’1\’;
- = get_bloginfo (\’admin_email\’);
- = get_comment();
- = trim(->comment_author_email);
- = ->comment_parent ? ->comment_parent : ;
- ;
- (->query() == )
- ->query();
- (( != && isset([\’comment_mail_notify\’])) || ( == && == \’1\’))
- ->query();
- = ? get_comment()->comment_mail_notify : \’0\’;
- = ->comment_approved;
- ( != && != \’spam\’ && == \’1\’) {
- = \’no-reply@\’ . preg_replace(\’#^www\\.#\’, , ([\’SERVER_NAME\’]));
- = trim(get_comment()->comment_author_email);
- = \’您在 [\’ . get_option() . \’] 的留言有了回應\’;
- = \’
- <div style=>
- <p>\’ . trim(get_comment()->comment_author) . \’, 您好!</p>
- <p>您曾在《\’ . get_the_title(->comment_post_ID) . \’》的留言:<br />\’
- . trim(get_comment()->comment_content) . \'</p>
- <p>\’ . trim(->comment_author) . \’ 給您的回應:<br />\’
- . trim(->comment_content) . \'<br /></p>
- <p>您可以點擊 <a href=>查看回應完整內容</a></p>
- <p>歡迎再度光臨 <a href=>\’ . get_option(\’blogname\’) . \'</a></p>
- <p>(此郵件由系統自動發出, 請勿回覆.)</p>
- </div>\’;
- = . get_option(\’blogname\’) . ;
- = . get_option(\’blog_charset\’) . ;
- wp_mail( , , , );
- }
- }
- add_action(\’comment_post\’, \’comment_mail_notify\’);
- add_checkbox() {
- \'<input type= name= id= value= checked= style= /><label =>有人回覆時郵件通知我</label>\’;
- }
- add_action(\’comment_form\’, \’add_checkbox\’);
二、无勾选栏, 由管理者决定在什麽条件下发邮件
- comment_mail_notify() {
- = get_bloginfo (\’admin_email\’);
- = get_comment();
- = trim(->comment_author_email);
- = ->comment_parent ? ->comment_parent : ;
- = ? trim(get_comment()->comment_author_email) : ;
- = ->comment_approved;
- (( != ) && ( != \’spam\’) && ( != ) && ( == )) {
- = \’no-reply@\’ . preg_replace(\’#^www\\.#\’, , ([\’SERVER_NAME\’]));
- = \’您在 [\’ . get_option() . \’] 的留言有了回應\’;
- = \’
- <div style=>
- <p>\’ . trim(get_comment()->comment_author) . \’, 您好!</p>
- <p>您曾在《\’ . get_the_title(->comment_post_ID) . \’》的留言:<br />\’
- . trim(get_comment()->comment_content) . \'</p>
- <p>\’ . trim(->comment_author) . \’ 給您的回應:<br />\’
- . trim(->comment_content) . \'<br /></p>
- <p>您可以點擊 <a href=>查看回應完整內容</a></p>
- <p>歡迎再度光臨 <a href=>\’ . get_option(\’blogname\’) . \'</a></p>
- <p>(此郵件由系統自動發出, 請勿回覆.)</p>
- </div>\’;
- = . get_option(\’blogname\’) . ;
- = . get_option(\’blog_charset\’) . ;
- wp_mail( , , , );
- }
- }
- add_action(\’comment_post\’, \’comment_mail_notify\’);
三、所有回覆都发邮件
- comment_mail_notify() {
- = get_comment();
- = ->comment_parent ? ->comment_parent : ;
- = ->comment_approved;
- (( != ) && ( != \’spam\’)) {
- = \’no-reply@\’ . preg_replace(\’#^www\\.#\’, , ([\’SERVER_NAME\’]));
- = trim(get_comment()->comment_author_email);
- = \’您在 [\’ . get_option() . \’] 的留言有了回應\’;
- = \’
- <div style=>
- <p>\’ . trim(get_comment()->comment_author) . \’, 您好!</p>
- <p>您曾在《\’ . get_the_title(->comment_post_ID) . \’》的留言:<br />\’
- . trim(get_comment()->comment_content) . \'</p>
- <p>\’ . trim(->comment_author) . \’ 給您的回應:<br />\’
- . trim(->comment_content) . \'<br /></p>
- <p>您可以點擊 <a href=>查看回應完整內容</a></p>
- <p>歡迎再度光臨 <a href=>\’ . get_option(\’blogname\’) . \'</a></p>
- <p>(此郵件由系統自動發出, 請勿回覆.)</p>
- </div>\’;
- = . get_option(\’blogname\’) . ;
- = . get_option(\’blog_charset\’) . ;
- wp_mail( , , , );
- }
- }
- add_action(\’comment_post\’, \’comment_mail_notify\’);
使用方法:添加到在主题的function.php中
这个代码在评论分页的 get_comment_link() 有个 bug。
对使用 comments 和 trackbacks/pingbacks 分离的情况才会出现,没分离的没有影响.
当直接调用 get_comment_link() 因为没经过 wp_list_comments(‘type=comment’) 函数,它会以所有的评论作为分页对象. 所以 trackbacks/pingbacks 数量多的时候会让 cpage 多算了, 本来是 cpage=7 会成了 cpage=8, 所以点击邮件里的“查看回应完整内容会找不到正确评论页面”.
— 修正方式 —-
将以上的:
get_comment_link($parent_id)
改为:
get_comment_link($parent_id, array(\’type\’ => \’comment\’))
加入的参数是让它选取 comment 数量计算就好.
评论样式有使用 comments 和 trackbacks/pingbacks 分离的童鞋,请进行修改,没用到的就不用改了。
暂无评论内容