Created
March 23, 2015 14:00
-
-
Save jg314/a3b0c7e442e3ba283c84 to your computer and use it in GitHub Desktop.
Send comment reply emails to the parent comment author automatically in WordPress.
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 | |
add_action( 'wp_set_comment_status', 'wi_comment_notification', 99, 2 ); | |
function wi_comment_notification( $comment_id, $comment_status ){ | |
$comment_object = get_comment( $comment_id ); | |
if( $comment_status == 'approve' && $comment_object->comment_parent > 0 ){ | |
$comment_parent = get_comment( $comment_object->comment_parent ); | |
$mailcontent = 'Hi ' . $comment_parent->comment_author . ',<br><br>'; | |
$mailcontent .= $comment_object->comment_author . ' replied to your comment on <a href="' . get_permalink( $comment_parent->comment_post_ID ) . '">' . get_the_title( $comment_parent->comment_post_ID ).'</a> with the following:'; | |
$mailcontent .= '<blockquote>' . $comment_object->comment_content . '</blockquote>'; | |
$mailcontent .= 'See their comment and reply: <a href="' . get_comment_link( $comment_object->comment_ID ) . '">' . get_comment_link( $comment_object->comment_ID ) . '</a><br><br>'; | |
$headers = 'MIME-Version: 1.0' . "\r\n"; | |
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n"; | |
$headers .= 'From: Wired Impact Blog <[email protected]>' . "\r\n"; | |
wp_mail( $comment_parent->comment_author_email, 'New Reply to Your Blog Comment', $mailcontent, $headers ); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment