1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| <?php function tlo_comment_mail_notify($comment_id) { global $comment_author; $comment = get_comment($comment_id); $parent_id = $comment->comment_parent ? $comment->comment_parent : ''; $spam_confirmed = $comment->comment_approved; $from = $comment->comment_author_email; $to = get_comment($parent_id)->comment_author_email; if (($parent_id != '') && ($spam_confirmed != 'spam') && $from != $to && $to != get_bloginfo('admin_email') ) { $blog_name = get_option('blogname'); $blog_url = site_url(); $post_url = get_permalink( $comment->comment_post_ID ); $comment_author = $comment->comment_author; $subject = 'Re: '.html_entity_decode(get_the_title($comment->comment_post_ID)); $headers[] = 'Reply-To: '.$comment_author.' <'.$comment->comment_author_email.'>'; $comment_parent = get_comment($parent_id); $comment_parent_date = tlo_get_comment_date( $comment_parent ); $comment_parent_time = tlo_get_comment_time( $comment_parent ); $message = <<<HTML <!DOCTYPE html> <html lang="zh"> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> <title>$blog_name</title> </head> <body> <style type="text/css"> img { max-width: 100%; height: auto; } </style> <div class="content"> <div> <p>$comment->comment_content</p> </div> </div> <div class="footer" style="margin-top: 10px"> <p style="color: #777; font-size: small"> — <br> Reply to this email to communicate with replier directly, or <a href="$post_url#comment-$comment_id">view it on $blog_name</a>. <br> You're receiving this email because of your comment got replied. </p> </div> <blockquote type="cite"> <div>On {$comment_parent_date}, {$comment_parent_time},$comment_parent->comment_author <<a href="mailto: $comment_parent->comment_author_email">$comment_parent->comment_author_email</a>> wrote:</div> <br> <div class="content"> <div> <p>$comment_parent->comment_content</p> </div> </div> </blockquote> </body> </html> HTML; add_filter( 'wp_mail_content_type', 'tlo_mail_content_type' ); add_filter( 'wp_mail_from_name', 'tlo_mail_from_name' ); wp_mail( $to, $subject, $message, $headers ); } } add_action('tlo_comment_post_async', 'tlo_comment_mail_notify');
function tlo_comment_mail_notify_async($comment_id) { wp_schedule_single_event( time(), 'tlo_comment_post_async', [$comment_id] ); } add_action('comment_post', 'tlo_comment_mail_notify_async'); // add_action('comment_post', 'tlo_comment_mail_notify');
function tlo_mail_content_type() { return 'text/html'; } function tlo_mail_from_name() { global $comment_author; return $comment_author; }
function tlo_get_comment_time( $comment ) { $date = mysql2date(get_option('time_format'), $comment->comment_date, true);
return apply_filters( 'tlo_get_comment_time', $date, $comment ); } function tlo_get_comment_date( $comment ) { $date = mysql2date(get_option('date_format'), $comment->comment_date);
return apply_filters( 'tlo_get_comment_date', $date, $comment ); }
|