Skip to content

Commit

Permalink
REST API: Pass correct number of arguments to the comment_text filter.
Browse files Browse the repository at this point in the history
This ensures that `WP_REST_Comments_Controller::prepare_item_for_response()` passes three arguments to the `comment_text` filter, for consistency with all the other instances in core.

Follow-up to [15957], [16357], [25555], [38832], [40664].

Props sjregan, SergeyBiryukov.
Fixes #58238.

git-svn-id: https://develop.svn.wordpress.org/trunk@57176 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Dec 9, 2023
1 parent 1325c63 commit 9bfb304
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
Expand Down
15 changes: 15 additions & 0 deletions tests/phpunit/tests/rest-api/rest-comments-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );

Expand Down

0 comments on commit 9bfb304

Please sign in to comment.