Skip to content

Commit 6c48f38

Browse files
Adjust logic to only impact notes; adjust tests
1 parent 00e446b commit 6c48f38

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1890,7 +1890,7 @@ protected function check_read_post_permission( $post, $request ) {
18901890
* @return bool Whether the comment can be read.
18911891
*/
18921892
protected function check_read_permission( $comment, $request ) {
1893-
if ( 'comment' === $comment->comment_type && ! empty( $comment->comment_post_ID ) ) {
1893+
if ( 'note' !== $comment->comment_type && ! empty( $comment->comment_post_ID ) ) {
18941894
$post = get_post( $comment->comment_post_ID );
18951895
if ( $post ) {
18961896
if ( $this->check_read_post_permission( $post, $request ) && 1 === (int) $comment->comment_approved ) {

tests/phpunit/tests/rest-api/rest-comments-controller.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4226,16 +4226,16 @@ public function test_get_items_type_arg_unauthenticated( $comment_type, $count )
42264226
$request->set_param( 'per_page', self::$per_page );
42274227

42284228
$response = rest_get_server()->dispatch( $request );
4229-
$this->assertEquals( 'comment' === $comment_type ? 200 : 401, $response->get_status() );
4230-
if ( 'comment' !== $comment_type ) {
4229+
$this->assertEquals( 'note' !== $comment_type ? 200 : 401, $response->get_status() );
4230+
if ( 'note' === $comment_type ) {
42314231
$this->assertErrorResponse( 'rest_forbidden_param', $response, 401 );
42324232
}
42334233

42344234
// Next, test getting the individual comments.
42354235
foreach( $comments as $comment ) {
42364236
$request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', $comment ) );
42374237
$response = rest_get_server()->dispatch( $request );
4238-
$this->assertEquals( 'comment' === $comment_type ? 200 : 401, $response->get_status() );
4238+
$this->assertEquals( 'note' !== $comment_type ? 200 : 401, $response->get_status() );
42394239
}
42404240
}
42414241

0 commit comments

Comments
 (0)