Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 );
if ( ! ( $comment instanceof WP_Comment ) ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: hereafter in this function, it should really use $comment->comment_ID (or whatever the field is) instead of $comment_id because the get_comment() function has a filtered return value, so a plugin could potentially substitute the comment with something completely different (although they probably wouldn't).

return false;
}
$is_note = ( $comment && 'note' === $comment->comment_type );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks to the above, this can now be simplified:

Suggested change
$is_note = ( $comment && 'note' === $comment->comment_type );
$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.
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