Make WordPress Core

Opened 5 months ago

Last modified 5 months ago

#58238 new defect (bug)

comment_text filter not applied with correct number of arguments within REST API

Reported by: sjregan's profile sjregan Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.2
Component: REST API Keywords: has-patch
Focuses: Cc:


Continuation of tickets #38314 and #24913

The filter is defined here:

 * Filters the text of a comment to be displayed.
 * @since 1.2.0
 * @see Walker_Comment::comment()
 * @param string          $comment_text Text of the current comment.
 * @param WP_Comment|null $comment      The comment object. Null if not found.
 * @param array           $args         An array of arguments.
echo apply_filters( 'comment_text', $comment_text, $comment, $args );

In the REST API:

it is called with:

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 ),
        'raw'      => $comment->comment_content,

Hooks added expecting three arguments will cause a fatal error. Previous fixes have involved passing an empty array as the third parameter when applying the filter.

Change History (1)

This ticket was mentioned in PR #4414 on WordPress/wordpress-develop by sjregan.

5 months ago

  • Keywords has-patch added

Ensures correct number of arguments supplied for 'comment_text' filter in REST API comments controller.
Passes empty array as third parameters for $args.

Trac ticket:

Note: See TracTickets for help on using tickets.