From eee5a9fbbf7bb68b6835558a05232c16b72ecf07 Mon Sep 17 00:00:00 2001 From: adamsilverstein Date: Fri, 7 Nov 2025 09:27:28 -0700 Subject: [PATCH 1/7] Use comment status and type to set $maybe_notify default --- src/wp-includes/comment.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/wp-includes/comment.php b/src/wp-includes/comment.php index 70d78ed33c848..73fd0a7d599d5 100644 --- a/src/wp-includes/comment.php +++ b/src/wp-includes/comment.php @@ -2476,6 +2476,13 @@ function wp_new_comment_notify_postauthor( $comment_id ) { $maybe_notify = $is_note ? get_option( 'wp_notes_notify', 1 ) : get_option( 'comments_notify' ); + // By default, only notify for approved comments and notes. + if ( + ! isset( $comment->comment_approved ) || + ( '1' !== $comment->comment_approved && ! $is_note ) ) { + $maybe_notify = false; + } + /** * Filters whether to send the post author new comment notification emails, * overriding the site setting. @@ -2495,13 +2502,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 ); } From 19a8db7e95f373a7865307936bbf6719e696da76 Mon Sep 17 00:00:00 2001 From: adamsilverstein Date: Fri, 7 Nov 2025 09:36:31 -0700 Subject: [PATCH 2/7] Update filter doc block --- src/wp-includes/comment.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/comment.php b/src/wp-includes/comment.php index 73fd0a7d599d5..a9174be04b6bb 100644 --- a/src/wp-includes/comment.php +++ b/src/wp-includes/comment.php @@ -2484,8 +2484,9 @@ function wp_new_comment_notify_postauthor( $comment_id ) { } /** - * 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 * From a45b3b4a2406c44b5d95825e9383f1568dd02fac Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Mon, 10 Nov 2025 14:27:00 -0700 Subject: [PATCH 3/7] Update comment.php Co-authored-by: Aaron Jorbin --- src/wp-includes/comment.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wp-includes/comment.php b/src/wp-includes/comment.php index a9174be04b6bb..d9a9bd1b8d318 100644 --- a/src/wp-includes/comment.php +++ b/src/wp-includes/comment.php @@ -2489,6 +2489,7 @@ function wp_new_comment_notify_postauthor( $comment_id ) { * 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. From 7c217dd49c831ce7cb6e0fc800e0bc95a67311c4 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Wed, 25 Feb 2026 16:24:19 +0700 Subject: [PATCH 4/7] Apply suggestion from @westonruter Co-authored-by: Weston Ruter --- src/wp-includes/comment.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/comment.php b/src/wp-includes/comment.php index d9a9bd1b8d318..150cdd4700e63 100644 --- a/src/wp-includes/comment.php +++ b/src/wp-includes/comment.php @@ -2474,13 +2474,16 @@ function wp_new_comment_notify_postauthor( $comment_id ) { $comment = get_comment( $comment_id ); $is_note = ( $comment && '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 ( ! isset( $comment->comment_approved ) || - ( '1' !== $comment->comment_approved && ! $is_note ) ) { - $maybe_notify = false; + ( '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' ); } /** @@ -2489,7 +2492,7 @@ function wp_new_comment_notify_postauthor( $comment_id ) { * all notes and for approved comments. * * @since 4.4.0 - * @since 6.9.0 Comment approval status is checked before this filter. + * @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. From 9adf0e575f7ac1bbf05e557e8694bbf7c2f588c6 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Thu, 26 Feb 2026 10:49:31 +0700 Subject: [PATCH 5/7] Apply suggestions from Weston Co-authored-by: Weston Ruter --- src/wp-includes/comment.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/comment.php b/src/wp-includes/comment.php index 150cdd4700e63..49ea28e3f0a60 100644 --- a/src/wp-includes/comment.php +++ b/src/wp-includes/comment.php @@ -2472,13 +2472,13 @@ function wp_new_comment_notify_moderator( $comment_id ) { */ function wp_new_comment_notify_postauthor( $comment_id ) { $comment = get_comment( $comment_id ); + if ( ! ( $comment instanceof WP_Comment ) ) { + return false; + } $is_note = ( $comment && 'note' === $comment->comment_type ); // By default, only notify for approved comments and notes. - if ( - ! isset( $comment->comment_approved ) || - ( '1' !== $comment->comment_approved && ! $is_note ) - ) { + if ( '1' !== $comment->comment_approved && ! $is_note ) { $maybe_notify = false; } else if ( $is_note ) { $maybe_notify = get_option( 'wp_notes_notify', 1 ); From bc0918c2568680f18b60088a7e66891f1feedb64 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Tue, 17 Mar 2026 10:54:35 -0700 Subject: [PATCH 6/7] Update src/wp-includes/comment.php Co-authored-by: Weston Ruter --- src/wp-includes/comment.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/comment.php b/src/wp-includes/comment.php index 75933a9e6f8f7..bb9f855cd2189 100644 --- a/src/wp-includes/comment.php +++ b/src/wp-includes/comment.php @@ -2475,7 +2475,7 @@ function wp_new_comment_notify_postauthor( $comment_id ) { if ( ! ( $comment instanceof WP_Comment ) ) { return false; } - $is_note = ( $comment && 'note' === $comment->comment_type ); + $is_note = ( 'note' === $comment->comment_type ); // By default, only notify for approved comments and notes. if ( '1' !== $comment->comment_approved && ! $is_note ) { From e74d3cfaed1130f401237c0a378a9d49ec1007a6 Mon Sep 17 00:00:00 2001 From: adamsilverstein Date: Tue, 17 Mar 2026 11:05:49 -0700 Subject: [PATCH 7/7] Use comment object ID after get_comment() call The get_comment() return value is filtered, so reassign $comment_id from the comment object to ensure consistency between the property checks and subsequent function calls. Also removes a redundant null check on $comment. --- src/wp-includes/comment.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/comment.php b/src/wp-includes/comment.php index bb9f855cd2189..02616ede5c533 100644 --- a/src/wp-includes/comment.php +++ b/src/wp-includes/comment.php @@ -2475,7 +2475,8 @@ function wp_new_comment_notify_postauthor( $comment_id ) { if ( ! ( $comment instanceof WP_Comment ) ) { return false; } - $is_note = ( 'note' === $comment->comment_type ); + $comment_id = $comment->comment_ID; + $is_note = ( 'note' === $comment->comment_type ); // By default, only notify for approved comments and notes. if ( '1' !== $comment->comment_approved && ! $is_note ) {