Make WordPress Core

Changeset 61179


Ignore:
Timestamp:
11/07/2025 02:05:43 PM (12 months ago)
Author:
ellatrix
Message:

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 ​https://github.com/WordPress/wordpress-develop/pull/10472.

Fixes #64204.
Props adamsilverstein, mamaduka, peterwilsoncc, ellatrix, wildworks, mukesh27, desrosj, annezazu, jeffpaul.

Location:
trunk/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/schema.php

    r60954 r61179  
    561561                // 6.4.0
    562562                'wp_attachment_pages_enabled'     => 0,
     563
     564                // 6.9.0
     565                'wp_notes_notify'                 => 1,
     566
    563567        );
    564568
  • trunk/src/wp-admin/options-discussion.php

    r60805 r61179  
    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>
  • trunk/src/wp-admin/options.php

    r60238 r61179  
    126126                'comment_registration',
    127127                'show_comments_cookies_opt_in',
     128                'wp_notes_notify',
    128129        ),
    129130        'media'      => array(
  • trunk/src/wp-includes/comment.php

    r61144 r61179  
    24262426function wp_new_comment_notify_postauthor( $comment_id ) {
    24272427        $comment = get_comment( $comment_id );
    2428 
    2429         $maybe_notify = get_option( 'comments_notify' );
     2428        $is_note = ( $comment && 'note' === $comment->comment_type );
     2429
     2430        $maybe_notify = $is_note ? get_option( 'wp_notes_notify' ) : get_option( 'comments_notify' );
    24302431
    24312432        /**
    … …  
    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
  • trunk/src/wp-includes/default-filters.php

    r61178 r61179  
    523523add_action( 'comment_post', 'wp_new_comment_notify_moderator' );
    524524add_action( 'comment_post', 'wp_new_comment_notify_postauthor' );
     525add_action( 'rest_insert_comment', array( 'WP_REST_Comments_Controller', 'wp_new_comment_via_rest_notify_postauthor' ) );
    525526add_action( 'after_password_reset', 'wp_password_change_notification' );
    526527add_action( 'register_new_user', 'wp_send_new_user_notifications' );
  • trunk/src/wp-includes/pluggable.php

    r61131 r61179  
    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. */
    … …  
    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";
    1923 
    1924                         if ( user_can( $post->post_author, 'edit_comment', $comment->comment_ID ) ) {
     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                        }
     1941
     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. */
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php

    r61144 r61179  
    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.
Note: See TracChangeset for help on using the changeset viewer.