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 ); | |
} | |
} |
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!
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
thanks for sharing this - i got here via your link in the ClassicPress petition
here's something that might go well with your function - this is not my code, but i did modify it a wee bit...