Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Email Notification for Comments
<?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 &#x2794;<br>%s<br><br>
The comment: <br>%s<br><br>
Reply by clicking on this link &#x2794;<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 );
}
}
@atomGit
Copy link

atomGit commented Dec 18, 2020

hmmm... in my case it doesn't do that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment