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 1169b6b1307ae..3a367e7e22c5a 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 @@ -1091,7 +1091,7 @@ public function prepare_item_for_response( $item, $request ) { if ( in_array( 'content', $fields, true ) ) { $data['content'] = array( /** This filter is documented in wp-includes/comment-template.php */ - 'rendered' => apply_filters( 'comment_text', $comment->comment_content, $comment ), + 'rendered' => apply_filters( 'comment_text', $comment->comment_content, $comment, array() ), 'raw' => $comment->comment_content, ); } diff --git a/tests/phpunit/tests/rest-api/rest-comments-controller.php b/tests/phpunit/tests/rest-api/rest-comments-controller.php index ab8f672c5de8a..ee42906c61796 100644 --- a/tests/phpunit/tests/rest-api/rest-comments-controller.php +++ b/tests/phpunit/tests/rest-api/rest-comments-controller.php @@ -966,6 +966,21 @@ public function test_prepare_item_limit_fields() { ); } + /** + * @ticket 58238 + */ + public function test_prepare_item_comment_text_filter() { + $filter = new MockAction(); + add_filter( 'comment_text', array( $filter, 'filter' ), 10, 3 ); + + $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); + + $response = rest_get_server()->dispatch( $request ); + + $this->assertSame( 1, $filter->get_call_count() ); + $this->assertCount( 3, $filter->get_args()[0] ); + } + public function test_get_comment_author_avatar_urls() { $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );