search
尋找貓咪~QQ 地點 桃園市桃園區 Taoyuan , Taoyuan

Send Comment Notification Email To Author In WordPress – ARON HACK 亞倫害的

Original Posts

Send Comment Notification Email To Author In WordPress


When a user left a comment on your site, and the comment get a new reply, this code will send a notification email to the author. Also, you can send a copy to yourself with Bcc to ensure this feature working fine.

However, there is another issue. With default settings in WordPress, the email filed in comment form is not required. And that’s what we would customize in the next post.

add_action( 'comment_post', 'send_comment_notification_mail', 10, 2 );
function send_comment_notification_mail( $comment_ID, $comment_approved ) {

    if( 1 === $comment_approved ){

        $comment = get_comment( $comment_ID );

        if($comment->comment_parent != 0){

            $parent_id = $comment->comment_parent;
            $parent_comment = get_comment( $parent_id );
            $author_mail = $parent_comment->comment_author_email;
            $post_link = get_permalink($parent_comment->comment_post_ID);
            $post_title = get_the_title($parent_comment->comment_post_ID);

            $comment_link = $post_link."#comment-".$parent_id;
            $comment_link = urldecode($comment_link);


            $to = $parent_comment->comment_author." ";
            $content = "Your comment in '".$post_title."' has a new reply。\n".
                                 $comment_link;


            $headers[] = 'From: ARON HACK ';
            // $headers[] = 'Cc: [email protected]';
            $headers[] = 'Bcc: [email protected]';


            wp_mail($to,
                    "[AROH HACK] Comment Reply Notification",
                    $content,
                    $headers);
        }
    }
}

Hooks Used In This Tutorial

get_comments
wp_mail

Related Posts

The Complete WordPress Customization Tutorial – Just Copy And Paste And Work

Content Protection by DMCA.com


熱門推薦

本文由 aronhackcom 提供 原文連結

寵物協尋 相信 終究能找到回家的路
寫了7763篇文章,獲得2次喜歡
留言回覆
回覆
精彩推薦