Make WordPress Core

Changeset 57176


Ignore:
Timestamp:
12/09/2023 10:11:45 PM (10 months ago)
Author:
SergeyBiryukov
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php

    r56747 r57176  
    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            );
  • trunk/tests/phpunit/tests/rest-api/rest-comments-controller.php

    r56549 r57176  
    965965            array_keys( $response->get_data() )
    966966        );
     967    }
     968
     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] );
    967982    }
    968983
Note: See TracChangeset for help on using the changeset viewer.