Make WordPress Core


Ignore:
Timestamp:
10/31/2025 06:55:47 PM (4 months ago)
Author:
adamsilverstein
Message:

Editor: Notes should not appear in the context of comments.

Prevent notes from inadvertently showing up in the context of comments - including on the Dashboard recent comments widget and the “Mine” count on the Comments page. Notes are stored as a custom ‘note’ comment type and this change ensures the note type is only returned when explicitly requested, or when ‘all’ types are requested.

The query for note children is modified to return all child notes. This fixes an issue where children were no longer being returned for the ‘note’ type.

Also fixes https://github.com/WordPress/gutenberg/issues/72548.

Props adamsilverstein, timothyblynjacobs, shailu25, peterwilsoncc, westonruter, mamaduka, kadamwhite.
Fixes #64145.
Fixes #64152.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-comments-controller.php

    r61089 r61105  
    40774077        );
    40784078    }
     4079
     4080    /**
     4081     * Test children link for note comment type. Based on test_get_comment_with_children_link.
     4082     *
     4083     * @ticket 64152
     4084     */
     4085    public function test_get_note_with_children_link() {
     4086        $parent_comment_id = self::factory()->comment->create(
     4087            array(
     4088                'comment_approved' => 1,
     4089                'comment_post_ID'  => self::$post_id,
     4090                'user_id'          => self::$admin_id,
     4091                'comment_type'     => 'note',
     4092                'comment_content'  => 'Parent note comment',
     4093            )
     4094        );
     4095
     4096        self::factory()->comment->create(
     4097            array(
     4098                'comment_approved' => 1,
     4099                'comment_parent'   => $parent_comment_id,
     4100                'comment_post_ID'  => self::$post_id,
     4101                'user_id'          => self::$admin_id,
     4102                'comment_type'     => 'note',
     4103                'comment_content'  => 'First child note comment',
     4104            )
     4105        );
     4106
     4107        wp_set_current_user( self::$admin_id );
     4108        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%s', $parent_comment_id ) );
     4109        $request->set_param( 'type', 'note' );
     4110        $request->set_param( 'context', 'edit' );
     4111        $response = rest_get_server()->dispatch( $request );
     4112        $this->assertSame( 200, $response->get_status() );
     4113
     4114        $this->assertArrayHasKey( 'children', $response->get_links() );
     4115
     4116        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
     4117        $request->set_param( 'post', self::$post_id );
     4118        $request->set_param( 'type', 'note' );
     4119        $request->set_param( 'context', 'edit' );
     4120        $request->set_param( 'parent', 0 );
     4121
     4122        $response = rest_get_server()->dispatch( $request );
     4123        $this->assertSame( 200, $response->get_status() );
     4124
     4125        $data = $response->get_data();
     4126
     4127        $this->assertArrayHasKey( '_links', $data[0] );
     4128        $this->assertArrayHasKey( 'children', $data[0]['_links'] );
     4129
     4130        $children = $data[0]['_links']['children'];
     4131
     4132        // Verify the href attribute contains the expected status and type parameters.
     4133        $this->assertStringContainsString( 'status=all', $children[0]['href'] );
     4134        $this->assertStringContainsString( 'type=note', $children[0]['href'] );
     4135    }
    40794136}
Note: See TracChangeset for help on using the changeset viewer.