Write your own plug-ins to achieve WordPress comment reply Email notification

Source: Internet
Author: User
Tags sprintf

Comment Reply Email notification means: You reply to a comments, a will receive the corresponding email notification.

Create a new plugin, only need a PHP file on it.

First, add_action.

Add_action (' Comment_post ', ' comment_notify ');

Then implement our Send mail function. The main is based on the WordPress API to obtain relevant information, and then call the Wp_mail function to send.

Modifying the source email address can be modified in header:

$message _headers = ' from:acm house <no-reply@acmerblog.com> '. "\r\n\\";

Note the distinction between comment and old_comment. The latter refers to comments that have been returned.

Here on my website the ACM home www.acmerblog.com as an example:

<?php add_action (' comment_post ', ' comment_notify '); 
    function comment_notify ($comment _reply_id) {$comment = Get_comment ($comment _reply_id);
        if ($comment->comment_parent!= 0) {$old _comment = get_comment ($comment->comment_parent);/replied comments  if ($old _comment->user_id = = 0) {$email = $old _comment->comment_author_email; 
            A reviewer's mailbox, as the destination address $name = $comment->comment_author;
            $content = $comment->comment_content;
            $post = Get_post ($comment->comment_post_id);
            $title = $post->post_title;
            $link = Get_permalink ($comment->comment_post_id); $bname =get_option (' blogname '); Get to the name of the website, ACM House.
 Here is no use of this variable, the back directly written dead $blogname = Wp_specialchars_decode ($bname, ent_quotes); $subject = sprintf (' [%1 $ s] replied to you in [%2$s] ', $name, $title);
            The subject of the message//$subject = sprintf (' [%1 $ s] Comment reply: "%2$s", $blogname, $title); $notify _message = sprintf (' Your comments in '%s ' haveNew reply ', $title).
            "\ r \ n"; $notify _message. = sprintf (' Reviewer:%1 $ s ', $name).
            "\ r \ n"; $notify _message. = ' Comment content: '. "\ r \ n". $content.
            "\r\n\r\n"; $notify _message. = ' You can view the comments in this article here: '.
            "\ r \ n"; $notify _message. = $link.
        "#comments \r\n\r\n"; $message _headers = ' from:acm house <no-reply@acmerblog.com> '. "\r\n\\"; The header application can change the source address of the message $message _headers. = "Content-type:text/plain; Charset=\ "". Get_option (' Blog_charset ').
            "\ \ n";
        Wp_mail ($email, $subject, $notify _message, $message _headers); }}}?>




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.