Skip to content

Commit 9bfb304

Browse files
REST API: Pass correct number of arguments to the comment_text filter.
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
1 parent 1325c63 commit 9bfb304

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

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
@@ -1091,7 +1091,7 @@ public function prepare_item_for_response( $item, $request ) {
10911091
if ( in_array( 'content', $fields, true ) ) {
10921092
$data['content'] = array(
10931093
/** This filter is documented in wp-includes/comment-template.php */
1094-
'rendered' => apply_filters( 'comment_text', $comment->comment_content, $comment ),
1094+
'rendered' => apply_filters( 'comment_text', $comment->comment_content, $comment, array() ),
10951095
'raw' => $comment->comment_content,
10961096
);
10971097
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,21 @@ public function test_prepare_item_limit_fields() {
966966
);
967967
}
968968

969+
/**
970+
* @ticket 58238
971+
*/
972+
public function test_prepare_item_comment_text_filter() {
973+
$filter = new MockAction();
974+
add_filter( 'comment_text', array( $filter, 'filter' ), 10, 3 );
975+
976+
$request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
977+
978+
$response = rest_get_server()->dispatch( $request );
979+
980+
$this->assertSame( 1, $filter->get_call_count() );
981+
$this->assertCount( 3, $filter->get_args()[0] );
982+
}
983+
969984
public function test_get_comment_author_avatar_urls() {
970985
$request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
971986

0 commit comments

Comments
 (0)