Skip to content

Commit 5dd4591

Browse files
committed
Notes: notify post author on note submission.
Fix an issue where new notes did not trigger a notification because they are submitted via the REST API. Ensures REST API submissions (for notes) trigger the post author notification. Leverage existing comment notification infrastructure. Developed in WordPress/wordpress-develop#10472. Fixes #64204. Props adamsilverstein, mamaduka, peterwilsoncc, ellatrix, wildworks, mukesh27, desrosj, annezazu, jeffpaul. Built from https://develop.svn.wordpress.org/trunk@61179 git-svn-id: https://core.svn.wordpress.org/trunk@60515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 parent 40d26b3 commit 5dd4591

File tree

8 files changed

+52
-8
lines changed

8 files changed

+52
-8
lines changed

wp-admin/includes/schema.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,10 @@ function populate_options( array $options = array() ) {
560560

561561
// 6.4.0
562562
'wp_attachment_pages_enabled' => 0,
563+
564+
// 6.9.0
565+
'wp_notes_notify' => 1,
566+
563567
);
564568

565569
// 3.3.0

wp-admin/options-discussion.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@
160160
<label for="moderation_notify">
161161
<input name="moderation_notify" type="checkbox" id="moderation_notify" value="1" <?php checked( '1', get_option( 'moderation_notify' ) ); ?> />
162162
<?php _e( 'A comment is held for moderation' ); ?> </label>
163+
<br />
164+
<label for="wp_notes_notify">
165+
<input name="wp_notes_notify" type="checkbox" id="wp_notes_notify" value="1" <?php checked( '1', get_option( 'wp_notes_notify' ) ); ?> />
166+
<?php _e( 'Anyone posts a note' ); ?> </label>
167+
163168
</fieldset></td>
164169
</tr>
165170
<?php $before_comment_appears_title = __( 'Before a comment appears' ); ?>

wp-admin/options.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
'comment_order',
126126
'comment_registration',
127127
'show_comments_cookies_opt_in',
128+
'wp_notes_notify',
128129
),
129130
'media' => array(
130131
'thumbnail_size_w',

wp-includes/comment.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2425,8 +2425,9 @@ function wp_new_comment_notify_moderator( $comment_id ) {
24252425
*/
24262426
function wp_new_comment_notify_postauthor( $comment_id ) {
24272427
$comment = get_comment( $comment_id );
2428+
$is_note = ( $comment && 'note' === $comment->comment_type );
24282429

2429-
$maybe_notify = get_option( 'comments_notify' );
2430+
$maybe_notify = $is_note ? get_option( 'wp_notes_notify' ) : get_option( 'comments_notify' );
24302431

24312432
/**
24322433
* Filters whether to send the post author new comment notification emails,
@@ -2447,9 +2448,11 @@ function wp_new_comment_notify_postauthor( $comment_id ) {
24472448
return false;
24482449
}
24492450

2450-
// Only send notifications for approved comments.
2451-
if ( ! isset( $comment->comment_approved ) || '1' !== $comment->comment_approved ) {
2452-
return false;
2451+
// Send notifications for approved comments and all notes.
2452+
if (
2453+
! isset( $comment->comment_approved ) ||
2454+
( '1' !== $comment->comment_approved && ! $is_note ) ) {
2455+
return false;
24532456
}
24542457

24552458
return wp_notify_postauthor( $comment_id );

wp-includes/default-filters.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@
522522
// Email notifications.
523523
add_action( 'comment_post', 'wp_new_comment_notify_moderator' );
524524
add_action( 'comment_post', 'wp_new_comment_notify_postauthor' );
525+
add_action( 'rest_insert_comment', array( 'WP_REST_Comments_Controller', 'wp_new_comment_via_rest_notify_postauthor' ) );
525526
add_action( 'after_password_reset', 'wp_password_change_notification' );
526527
add_action( 'register_new_user', 'wp_send_new_user_notifications' );
527528
add_action( 'edit_user_created_user', 'wp_send_new_user_notifications', 10, 2 );

wp-includes/pluggable.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,6 +1894,20 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) {
18941894
$subject = sprintf( __( '[%1$s] Pingback: "%2$s"' ), $blogname, $post->post_title );
18951895
break;
18961896

1897+
case 'note':
1898+
/* translators: %s: Post title. */
1899+
$notify_message = sprintf( __( 'New note on your post "%s"' ), $post->post_title ) . "\r\n";
1900+
/* translators: 1: Note author's name, 2: Note author's IP address, 3: Note author's hostname. */
1901+
$notify_message .= sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
1902+
/* translators: %s: Note author email. */
1903+
$notify_message .= sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n";
1904+
/* translators: %s: Note text. */
1905+
$notify_message .= sprintf( __( 'Note: %s' ), "\r\n" . ( empty( $comment_content ) ? __( 'resolved/reopened' ) : $comment_content ) ) . "\r\n\r\n";
1906+
$notify_message .= __( 'You can see all notes on this post here:' ) . "\r\n";
1907+
/* translators: Note notification email subject. 1: Site title, 2: Post title. */
1908+
$subject = sprintf( __( '[%1$s] Note: "%2$s"' ), $blogname, $post->post_title );
1909+
break;
1910+
18971911
default: // Comments.
18981912
/* translators: %s: Post title. */
18991913
$notify_message = sprintf( __( 'New comment on your post "%s"' ), $post->post_title ) . "\r\n";
@@ -1917,11 +1931,15 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) {
19171931
break;
19181932
}
19191933

1920-
$notify_message .= get_permalink( $comment->comment_post_ID ) . "#comments\r\n\r\n";
19211934
/* translators: %s: Comment URL. */
1922-
$notify_message .= sprintf( __( 'Permalink: %s' ), get_comment_link( $comment ) ) . "\r\n";
1935+
if ( 'note' === $comment->comment_type ) {
1936+
$notify_message .= get_edit_post_link( $comment->comment_post_ID, 'url' ) . "\r\n";
1937+
} else {
1938+
$notify_message .= get_permalink( $comment->comment_post_ID ) . "#comments\r\n\r\n";
1939+
$notify_message .= sprintf( __( 'Permalink: %s' ), get_comment_link( $comment ) ) . "\r\n";
1940+
}
19231941

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

wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ public function __construct() {
3636
$this->meta = new WP_REST_Comment_Meta_Fields();
3737
}
3838

39+
/**
40+
* Send a notification to the post author when a new note is added via the REST API.
41+
*
42+
* @since 6.9.0
43+
*
44+
* @param WP_Comment $comment The comment object.
45+
*/
46+
public static function wp_new_comment_via_rest_notify_postauthor( $comment ) {
47+
if ( 'note' === $comment->comment_type ) {
48+
wp_new_comment_notify_postauthor( $comment->comment_ID );
49+
}
50+
}
3951
/**
4052
* Registers the routes for comments.
4153
*

wp-includes/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* @global string $wp_version
1818
*/
19-
$wp_version = '6.9-beta3-61178';
19+
$wp_version = '6.9-beta3-61179';
2020

2121
/**
2222
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

0 commit comments

Comments
 (0)