Skip to content
Closed
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8ec209c
Send a notification to the post author when a note is added
adamsilverstein Nov 5, 2025
6799a1d
phpcbf
adamsilverstein Nov 5, 2025
6faacfe
remove notes conditional
adamsilverstein Nov 5, 2025
b3487af
Only notify on notes REST insert
adamsilverstein Nov 5, 2025
0daba4c
update docblock
adamsilverstein Nov 6, 2025
cbfef88
Queue note notifications with cron
adamsilverstein Nov 6, 2025
f089d47
Skip notifications for empty notes
adamsilverstein Nov 6, 2025
79fd7e5
Update src/wp-includes/pluggable.php
adamsilverstein Nov 6, 2025
2aa7c96
Whitespace
adamsilverstein Nov 6, 2025
f9d4686
adjust since
adamsilverstein Nov 6, 2025
79aa49d
Revert "Queue note notifications with cron"
adamsilverstein Nov 6, 2025
8da27bc
update: Anyone posts a comment + "or note"
adamsilverstein Nov 6, 2025
98c2873
Add separate notes notification setting
adamsilverstein Nov 6, 2025
099de2f
Move notification hook so it is always available when action triggered
adamsilverstein Nov 6, 2025
887974e
Empty notes are resolution/reopen events
adamsilverstein Nov 6, 2025
62ed6c3
Fix notification logic
adamsilverstein Nov 6, 2025
25f0b56
phpcbf
adamsilverstein Nov 6, 2025
f3bee16
Check comment object returned before using
adamsilverstein Nov 6, 2025
0f6fff0
Merge branch 'trunk' into add/notes-notifications
adamsilverstein Nov 6, 2025
3b168e3
Update comment.php
adamsilverstein Nov 7, 2025
6fd6294
Update class-wp-rest-comments-controller.php
adamsilverstein Nov 7, 2025
93b9bd1
PHP not react
adamsilverstein Nov 7, 2025
7a1ed8e
rename notes_notify -> wp_ notes_notify
adamsilverstein Nov 7, 2025
2f4c927
Move wp_ notes_notify to bottom and add comment
adamsilverstein Nov 7, 2025
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
35 changes: 32 additions & 3 deletions src/wp-includes/comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -2447,14 +2447,43 @@ function wp_new_comment_notify_postauthor( $comment_id ) {
return false;
}

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

return wp_notify_postauthor( $comment_id );
}

/**
* Send a notification to the post author when a new note is added via the REST API.
*
* @since 6.9.0
*
* @param WP_Comment $comment The comment object.
*/
function wp_new_comment_via_rest_notify_postauthor( $comment ) {
if ( 'note' === $comment->comment_type ) {
// Queue up the email notification as a cron callback. The second parameter ensures each callback is executed.
wp_schedule_single_event( time(), 'wp_new_comment_via_rest_notify_postauthor', array( $comment->comment_ID, time() ) );
}
}

/**
* Cron callback to send an author email notifcation, keeping the action asynchronous.
*/
function wp_new_comment_via_rest_notify_postauthor_cron( $comment_id ) {
$comment = get_comment( $comment_id );
if ( $comment ) {
wp_new_comment_notify_postauthor( $comment_id );
}
}

// Add a custom hook for the note notification cron job.
add_action( 'wp_new_comment_via_rest_notify_postauthor', 'wp_new_comment_via_rest_notify_postauthor_cron' );

/**
* Sets the status of a comment.
*
Expand Down
1 change: 1 addition & 0 deletions src/wp-includes/default-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@
// Email notifications.
add_action( 'comment_post', 'wp_new_comment_notify_moderator' );
add_action( 'comment_post', 'wp_new_comment_notify_postauthor' );
add_action( 'rest_insert_comment', 'wp_new_comment_via_rest_notify_postauthor' );
add_action( 'after_password_reset', 'wp_password_change_notification' );
add_action( 'register_new_user', 'wp_send_new_user_notifications' );
add_action( 'edit_user_created_user', 'wp_send_new_user_notifications', 10, 2 );
Expand Down
29 changes: 26 additions & 3 deletions src/wp-includes/pluggable.php
Original file line number Diff line number Diff line change
Expand Up @@ -1746,6 +1746,11 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) {
return false;
}

// Skip notifications for empty notes.
if ( 'note' === $comment->comment_type && empty( $comment->comment_content ) ) {
return false;
}

$post = get_post( $comment->comment_post_ID );
$author = get_userdata( $post->post_author );

Expand Down Expand Up @@ -1894,6 +1899,20 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) {
$subject = sprintf( __( '[%1$s] Pingback: "%2$s"' ), $blogname, $post->post_title );
break;

case 'note':
/* translators: %s: Post title. */
$notify_message = sprintf( __( 'New note on your post "%s"' ), $post->post_title ) . "\r\n";
/* translators: 1: Note author's name, 2: Note author's IP address, 3: Note author's hostname. */
$notify_message .= sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
/* translators: %s: Note author email. */
$notify_message .= sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n";
/* translators: %s: Note text. */
$notify_message .= sprintf( __( 'Note: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n";
$notify_message .= __( 'You can see all notes on this post here:' ) . "\r\n";
/* translators: Note notification email subject. 1: Site title, 2: Post title. */
$subject = sprintf( __( '[%1$s] Note: "%2$s"' ), $blogname, $post->post_title );
break;

default: // Comments.
/* translators: %s: Post title. */
$notify_message = sprintf( __( 'New comment on your post "%s"' ), $post->post_title ) . "\r\n";
Expand All @@ -1917,11 +1936,15 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) {
break;
}

$notify_message .= get_permalink( $comment->comment_post_ID ) . "#comments\r\n\r\n";
/* translators: %s: Comment URL. */
$notify_message .= sprintf( __( 'Permalink: %s' ), get_comment_link( $comment ) ) . "\r\n";
if ( 'note' === $comment->comment_type ) {
$notify_message .= get_edit_post_link( $comment->comment_post_ID, 'url' ) . "\r\n";
} else {
$notify_message .= get_permalink( $comment->comment_post_ID ) . "#comments\r\n\r\n";
$notify_message .= sprintf( __( 'Permalink: %s' ), get_comment_link( $comment ) ) . "\r\n";
}

if ( user_can( $post->post_author, 'edit_comment', $comment->comment_ID ) ) {
if ( 'note' !== $comment->comment_type && user_can( $post->post_author, 'edit_comment', $comment->comment_ID ) ) {
if ( EMPTY_TRASH_DAYS ) {
/* translators: Comment moderation. %s: Comment action URL. */
$notify_message .= sprintf( __( 'Trash it: %s' ), admin_url( "comment.php?action=trash&c={$comment->comment_ID}#wpbody-content" ) ) . "\r\n";
Expand Down
Loading