Skip to content

Instantly share code, notes, and snippets.

@thesnippetdev
Created September 18, 2020 04:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thesnippetdev/d0ad79959fabcabc72f9fb2c0270136c to your computer and use it in GitHub Desktop.
Save thesnippetdev/d0ad79959fabcabc72f9fb2c0270136c to your computer and use it in GitHub Desktop.
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 );
}
}
@WooFunctions
Copy link

That's a nice start and very much useful in terms of changing the frontend UI of the WP comment system. Just one small fix that's needed though as the text, after having clicked on "Reply to ABC", is changed to "Reply to ABC to ABC". Other than that, all good!

@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