Skip to content

Instantly share code, notes, and snippets.

@jg314
jg314 / comment_reply_emails.php
Created March 23, 2015 14:00
Send comment reply emails to the parent comment author automatically in WordPress.
<?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>';