Skip to content
Open
25 changes: 15 additions & 10 deletions src/wp-includes/comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -2472,15 +2472,27 @@ function wp_new_comment_notify_moderator( $comment_id ) {
*/
function wp_new_comment_notify_postauthor( $comment_id ) {
$comment = get_comment( $comment_id );
Comment thread
adamsilverstein marked this conversation as resolved.
if ( ! ( $comment instanceof WP_Comment ) ) {
Comment thread
westonruter marked this conversation as resolved.
return false;
}
$is_note = ( $comment && 'note' === $comment->comment_type );
Comment thread
adamsilverstein marked this conversation as resolved.
Outdated

$maybe_notify = $is_note ? get_option( 'wp_notes_notify', 1 ) : get_option( 'comments_notify' );
// By default, only notify for approved comments and notes.
if ( '1' !== $comment->comment_approved && ! $is_note ) {
$maybe_notify = false;
} else if ( $is_note ) {
$maybe_notify = get_option( 'wp_notes_notify', 1 );
} else {
$maybe_notify = get_option( 'comments_notify' );
}

/**
* Filters whether to send the post author new comment notification emails,
* overriding the site setting.
* Filters whether to send the post author new comment and note notification emails,
* overriding the site settings and defaults. By default, notifications are sent for
* all notes and for approved comments.
*
* @since 4.4.0
Comment thread
adamsilverstein marked this conversation as resolved.
* @since 6.9.0 Comment approval status is checked before this filter.
*
* @param bool $maybe_notify Whether to notify the post author about the new comment.
* @param int $comment_id The ID of the comment for the notification.
Expand All @@ -2495,13 +2507,6 @@ function wp_new_comment_notify_postauthor( $comment_id ) {
return false;
}

// Send notifications for approved comments and all notes.
if (
! isset( $comment->comment_approved ) ||
( '1' !== $comment->comment_approved && ! $is_note ) ) {
return false;
}

return wp_notify_postauthor( $comment_id );
}

Expand Down
Loading