Created
September 18, 2020 04:00
-
-
Save thesnippetdev/d0ad79959fabcabc72f9fb2c0270136c to your computer and use it in GitHub Desktop.
Email Notification for Comments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // remove before copy / paste | |
add_action('wp_insert_comment', 'email_notifications_for_comments', 99, 2); | |
function email_notifications_for_comments($comment_id, $comment_object) { | |
if ( ( $comment_object->comment_approved == 1 ) && ($comment_object->comment_parent > 0 ) ) { | |
$comment_parent = get_comment($comment_object->comment_parent); | |
$subject = '['.get_bloginfo().'] '.__('Comment Notification'); | |
$body = sprintf(__('Hi %s,<br><br>%s YOUR TEXT HERE ➔<br>%s<br><br> | |
The comment: <br>%s<br><br> | |
Reply by clicking on this link ➔<br>%s'), $comment_parent->comment_author, $comment_object->comment_author, '<a href="'.get_permalink($comment_parent->comment_post_ID).'">'.get_the_title($comment_parent->comment_post_ID).'</a>', $comment_object->comment_content, '<a href="'.get_comment_link($comment_object->comment_ID).'">'.get_comment_link($comment_object->comment_ID).'</a>'); | |
$headers[] = 'From: '.get_bloginfo().' <'.get_option('admin_email').'>'; | |
$headers[] = 'Content-Type: text/html; charset=UTF-8'; | |
wp_mail( $comment_parent->comment_author.' <'.$comment_parent->comment_author_email.'>', $subject, $body, $headers ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hmmm... in my case it doesn't do that