Notify Post Author of Comments
Ensures the original post author always receives a comment notification email, even when the admin and author share an email address.
PHPby SnipCraft
php
<?php
add_filter( 'comment_notification_recipients', 'scseed_always_notify_post_author', 10, 2 );
if ( ! function_exists( 'scseed_always_notify_post_author' ) ) {
function scseed_always_notify_post_author( $emails, $comment_id ) {
$comment = get_comment( $comment_id );
if ( ! $comment ) {
return $emails;
}
$post = get_post( $comment->comment_post_ID );
$author = get_userdata( $post->post_author );
if ( ! $author || empty( $author->user_email ) ) {
return $emails;
}
// Skip notification if the commenter is the post author.
if ( $comment->comment_author_email === $author->user_email ) {
return $emails;
}
if ( ! in_array( $author->user_email, $emails, true ) ) {
$emails[] = $author->user_email;
}
return $emails;
}
}#authors#comments#email#notifications