WordPress adds a comment reply email notification function, wordpress notification

Source: Internet
Author: User

WordPress adds a comment reply email notification function, wordpress notification

After a comment is replied, an email is automatically sent to the reviewer, which is a major measure to improve the user experience. Zhu Meng has been using the comments from Master Willin Kan to reply to the email reminder code. I believe many people are using the code. If you haven't used it yet, try it.

Select a desired code based on your needs and add it to the topic's functions. php or pluggable. php (recommended)
The last file?> Above:

Method 1: Send email notifications for all replies

By default, all comments filled in the email address will be sent to the comments by email, without any selection.

/* Comment_mail_policy v1.0 by willin kan. (send emails to all replies) */function comment_mail_notify ($ comment_id) {$ comment = get_comment ($ comment_id); $ parent_id = $ comment-> comment_parent? $ Comment-> comment_parent: ''; $ spam_confirmed = $ comment-> comment_approved; if ($ parent_id! = '') & ($ Spam_confirmed! = 'Spam') {$ wp_email = 'no-reply @'. preg_replace ('# ^ www. # ', '', strtolower ($ _ SERVER ['server _ name']); // email sending point. no-reply can be changed to available email. $ to = trim (get_comment ($ parent_id)-> comment_author_email); $ subject = 'you are in ['. get_option ("blogname "). '] The message has a reply'; $ message = '<div style = "background-color: # eef2fa; border: 1px solid # d8e3e8; color: #111; padding: 0 15px;-moz-border-radius: 5px;-webkit-bord Er-radius: 5px;-khtml-border-radius: 5px; "> <p> '. trim (get_comment ($ parent_id)-> comment_author).', hello! </P> <p> you used 《'. get_the_title ($ comment-> comment_post_ID ). ': <br/> '. trim (get_comment ($ parent_id)-> comment_content ). '</p> <p> '. trim ($ comment-> comment_author ). 'reply to you: <br/> '. trim ($ comment-> comment_content ). '<br/> </p> <p> you can click to view the reply content. </p> <p> welcome to visit again '. get_option ('blogname '). '</p> <p> (this email is automatically sent by the system. Do not reply .) </p> </div> '; $ from = "From :\"". get_option ('blogname '). "\" <$ wp_email> "; $ headers =" $ from \ nContent-Type: text/html; charset = ". get_option ('blog _ charset '). "\ n"; wp_mail ($ to, $ subject, $ message, $ headers) ;}} add_action ('comment _ Post', 'comment _ mail_policy '); // -- END ----------------------------------------

Method 2: Ask the visitor to choose whether to send email notifications.

A check box is displayed at the bottom of the comment box, allowing the reviewer to decide whether to receive email notifications.

/* Start */function comment_mail_notify ($ comment_id) {$ admin_notify = '1'; // if admin wants to receive a reply notification ('1' = yes; '0' = No) $ admin_email = get_bloginfo ('admin _ mail'); // $ admin_email can be changed to the specified email. $ comment = get_comment ($ comment_id); $ comment_author_email = trim ($ comment-> comment_author_email); $ parent_id = $ comment-> comment_parent? $ Comment-> comment_parent: ''; global $ wpdb; if ($ wpdb-> query (" Describe {$ wpdb-> comments} comment_mail_policy ") = '') $ wpdb-> query ("alter table {$ wpdb-> comments} add column comment_mail_y y tinyint not null default 0;"); if ($ comment_author_email! = $ Admin_email & isset ($ _ POST ['comment _ mail_y y ']) | ($ comment_author_email = $ admin_email & $ admin_notify = '1 ')) $ wpdb-> query ("UPDATE {$ wpdb-> comments} SET comment_mail_y y = '1' WHERE comment_ID = '$ comment_id'"); $ parenty = $ parent_id? Get_comment ($ parent_id)-> comment_mail_policy: '0'; $ spam_confirmed = $ comment-> comment_approved; if ($ parent_id! = ''& $ Spam_confirmed! = 'Spam' & $ your Y = '1') {$ wp_email = 'no-reply @'. preg_replace ('# ^ www. # ', '', strtolower ($ _ SERVER ['server _ name']); // email sending point. no-reply can be changed to available email. $ to = trim (get_comment ($ parent_id)-> comment_author_email); $ subject = 'you are in ['. get_option ("blogname "). '] The message has a reply'; $ message = '<div style = "background-color: # eef2fa; border: 1px solid # d8e3e8; color: #111; padding: 0 15px;-moz-border-radius: 5px;-webkit-border-radius: 5px;-khtml-border-radius: 5px; "> <p> '. trim (get_comment ($ parent_id)-> comment_author ). ', hello! </P> <p> you used 《'. get_the_title ($ comment-> comment_post_ID ). ': <br/> '. trim (get_comment ($ parent_id)-> comment_content ). '</p> <p> '. trim ($ comment-> comment_author ). 'reply to you: <br/> '. trim ($ comment-> comment_content ). '<br/> </p> <p> you can click to view the full content of the reply. </p> <p> visit again '. get_option ('blogname '). '</p> <p> (this email is automatically sent by the system. Do not reply .) </p> </div> '; $ from = "From :\"". get_option ('blogname '). "\" <$ wp_email> "; $ headers =" $ from \ nContent-Type: text/html; charset = ". get_option ('blog _ charset '). "\ n"; wp_mail ($ to, $ subject, $ message, $ headers) ;}} add_action ('comment _ Post', 'comment _ mail_policy '); /* automatically add the check box */function add_checkbox () {echo '<input type = "checkbox" name = "comment_mail_y y" id = "comment_mail_notify" value = "comment_mail_notify" checked = "checked" style = "margin-left: 20px; "/> <label for =" comment_mail_notify "> notify me by email when someone replies </label> ';} add_action ('comment _ Form', 'add _ checkbox ');

Method 3: Ask the blog administrator to decide when to send an email.

You can configure the following code (view code comments) based on your needs to determine the conditions for sending an email.

/* Comment_mail_policy v1.0 by willin kan. (no check box) */function comment_mail_notify ($ comment_id) {$ admin_email = get_bloginfo ('admin _ email '); // $ admin_email can be changed to the specified email. $ 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') & ($! = $ Admin_email) & ($ comment_author_email = $ admin_email) {/* the preceding condition determines the necessary conditions for sending an email: ($ parent_id! = '') & ($ Spam_confirmed! = 'Spam'): The reply, and it is not spam. required !! ($! = $ Admin_email): Do not send to admin. ($ comment_author_email = $ admin_email): Only admin replies can be sent. the preceding conditions must be modified as an individual. */$ wp_email = 'no-reply @'. preg_replace ('# ^ www. # ', '', strtolower ($ _ SERVER ['server _ name']); // email sending point. no-reply can be changed to available email. $ subject = 'you are in ['. get_option ("blogname "). '] The message has a reply'; $ message = '<div style = "background-color: # eef2fa; border: 1px solid # d8e3e8; color: #111; padding: 0 15px;-m Oz-border-radius: 5px;-webkit-border-radius: 5px;-khtml-border-radius: 5px; "> <p> '. trim (get_comment ($ parent_id)-> comment_author ). ', hello! </P> <p> you used 《'. get_the_title ($ comment-> comment_post_ID ). ': <br/> '. trim (get_comment ($ parent_id)-> comment_content ). '</p> <p> '. trim ($ comment-> comment_author ). 'reply to you: <br/> '. trim ($ comment-> comment_content ). '<br/> </p> <p> you can click to view the full content of the reply. </p> <p> visit again '. get_option ('blogname '). '</p> <p> (this email is automatically sent by the system. Do not reply .) </p> </div> '; $ from = "From :\"". get_option ('blogname '). "\" <$ wp_email> "; $ headers =" $ from \ nContent-Type: text/html; charset = ". get_option ('blog _ charset '). "\ n"; wp_mail ($ to, $ subject, $ message, $ headers) ;}} add_action ('comment _ Post', 'comment _ mail_policy '); // -- END ----------------------------------------

Method 4: Support for nested and @-user comments

This method is reprinted from zww. me. The comment reply notifications in this version support nesting and @ user. If you have any questions, please go to the author's page for feedback.

/* Email Notification by Qiqiboy */function comment_mail_notify ($ comment_id) {$ comment = get_comment ($ comment_id ); // obtain the comment-related data by id $ content = $ comment-> comment_content; // match the comment content $ match_count = preg_match_all ('/<a href = "# comment-([0-9] + )? "Rel =" nofollow ">/si', $ content, $ matchs); if ($ match_count> 0) {// If foreach ($ matchs [1] as $ parent_id) is matched {// send an email for each child match SimPaled_send_email ($ parent_id, $ comment );}} elseif ($ comment-> comment_parent! = '0') {// in case someone intentionally deletes @ reply, you can also find the parent comment id to determine the email sending object $ parent_id = $ comment-> comment_parent; simPaled_send_email ($ parent_id, $ comment);} else return;} add_action ('comment _ Post', 'comment _ mail_notify '); function SimPaled_send_email ($ parent_id, $ comment) {// email sending function by Qiqiboy.com $ admin_email = get_bloginfo ('admin _ email '); // administrator email $ parent_comment = get_comment ($ parent_id ); // obtain the information about the respondent (or the parent comment) $ author_email = $ commen T-> comment_author_email; // reviewer's email address $ to = trim ($ parent_comment-> comment_author_email); // respondent's email address $ spam_confirmed = $ comment-> comment_approved; if ($ spam_confirmed! = 'Spam' & $! = $ Admin_email & $! = $ Author_email) {$ wp_email = 'no-reply @'. preg_replace ('# ^ www \. # ', '', strtolower ($ _ SERVER ['server _ name']); // E-mail sending point, no-reply can be changed to available email. $ subject = 'you are in ['. get_option ("blogname "). '] The message has a response'; $ message = '<div style = "background-color: # eef2fa; border: 1px solid # d8e3e8; color: #111; padding: 0 15px;-moz-border-radius: 5px;-webkit-border-radius: 5px;-khtml-border-radius: 5px; "> <p> '. trim (get _ Comment ($ parent_id)-> comment_author). ', hello! </P> <p> you used 《'. get_the_title ($ comment-> comment_post_ID ). ': <br/> '. trim (get_comment ($ parent_id)-> comment_content ). '</p> <p> '. trim ($ comment-> comment_author ). 'reply to you: <br/> '. trim ($ comment-> comment_content ). '<br/> </p> <p> you can click <a href = "'. htmlspecialchars (get_comment_link ($ parent_id, array ("type" => "all "))). '"> View the full content of the reply </a> </p> <p> welcome to <a href ="' again "'. get_option ('home '). '"> '. get_option ('blogname '). '</a> </p> <p> (this email is automatically sent. Please do not reply .) </p> </div> '; $ from = "From :\"". get_option ('blogname '). "\" <$ wp_email> "; $ headers =" $ from \ nContent-Type: text/html; charset = ". get_option ('blog _ charset '). "\ n"; wp_mail ($ to, $ subject, $ message, $ headers );}}

Remarks

To send an email, the host must support the mail () function. If you find that you cannot receive the email, you can ask your host provider. Because each person's host environment is different, some friends may not succeed when adding this function. At this time, you can try sending emails via SMTP.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.