diff --git a/src/wp-admin/includes/schema.php b/src/wp-admin/includes/schema.php index 5886b3d990d5d..217d18d8275a0 100644 --- a/src/wp-admin/includes/schema.php +++ b/src/wp-admin/includes/schema.php @@ -560,6 +560,10 @@ function populate_options( array $options = array() ) { // 6.4.0 'wp_attachment_pages_enabled' => 0, + + // 6.9.0 + 'wp_notes_notify' => 1, + ); // 3.3.0 diff --git a/src/wp-admin/options-discussion.php b/src/wp-admin/options-discussion.php index 7f12d95a268c4..3b4e1ac3a2313 100644 --- a/src/wp-admin/options-discussion.php +++ b/src/wp-admin/options-discussion.php @@ -160,6 +160,11 @@ +
+ + diff --git a/src/wp-admin/options.php b/src/wp-admin/options.php index 23d0f3971ba7c..1d60fc70ec4c3 100644 --- a/src/wp-admin/options.php +++ b/src/wp-admin/options.php @@ -125,6 +125,7 @@ 'comment_order', 'comment_registration', 'show_comments_cookies_opt_in', + 'wp_notes_notify', ), 'media' => array( 'thumbnail_size_w', diff --git a/src/wp-includes/comment.php b/src/wp-includes/comment.php index bc908326fd8a0..a6deb2db599f5 100644 --- a/src/wp-includes/comment.php +++ b/src/wp-includes/comment.php @@ -2425,8 +2425,9 @@ 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 ); - $maybe_notify = get_option( 'comments_notify' ); + $maybe_notify = $is_note ? get_option( 'wp_notes_notify' ) : get_option( 'comments_notify' ); /** * Filters whether to send the post author new comment notification emails, @@ -2447,9 +2448,11 @@ 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 && ! $is_note ) ) { + return false; } return wp_notify_postauthor( $comment_id ); diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index 229c9a75416af..f1cf9df7db5c6 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -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', array( 'WP_REST_Comments_Controller', '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 ); diff --git a/src/wp-includes/pluggable.php b/src/wp-includes/pluggable.php index 37fda9e412217..8dc41bbc4cc50 100644 --- a/src/wp-includes/pluggable.php +++ b/src/wp-includes/pluggable.php @@ -1894,6 +1894,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" . ( empty( $comment_content ) ? __( 'resolved/reopened' ) : $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"; @@ -1917,11 +1931,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"; diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php index 7fe79b57c1b9b..0ef02aae4d0dc 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php @@ -36,6 +36,18 @@ public function __construct() { $this->meta = new WP_REST_Comment_Meta_Fields(); } + /** + * 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. + */ + public static function wp_new_comment_via_rest_notify_postauthor( $comment ) { + if ( 'note' === $comment->comment_type ) { + wp_new_comment_notify_postauthor( $comment->comment_ID ); + } + } /** * Registers the routes for comments. *