diff --git a/src/wp-includes/comment.php b/src/wp-includes/comment.php index 0f102d1ea80ee..02616ede5c533 100644 --- a/src/wp-includes/comment.php +++ b/src/wp-includes/comment.php @@ -2472,15 +2472,28 @@ function wp_new_comment_notify_moderator( $comment_id ) { */ function wp_new_comment_notify_postauthor( $comment_id ) { $comment = get_comment( $comment_id ); - $is_note = ( $comment && 'note' === $comment->comment_type ); + if ( ! ( $comment instanceof WP_Comment ) ) { + return false; + } + $comment_id = $comment->comment_ID; + $is_note = ( 'note' === $comment->comment_type ); - $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 + * @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. @@ -2495,13 +2508,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 ); }