Make WordPress Core

Opened 13 months ago

Closed 6 months ago

Last modified 6 months ago

#58238 closed defect (bug) (fixed)

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

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

Description

Continuation of tickets #38314 and #24913

The filter is defined here:
wp-includes/comment-template.php:1057

<?php
/**
 * 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:
wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php:1092

it is called with:

<?php
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 (4)

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


13 months ago
#1

  • 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: https://core.trac.wordpress.org/ticket/58238

#2 @SergeyBiryukov
6 months ago

  • Milestone changed from Awaiting Review to 6.5

#3 @SergeyBiryukov
6 months ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 57176:

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.

@SergeyBiryukov commented on PR #4414:


6 months ago
#4

Thanks for the PR! Merged in r57176.

Note: See TracTickets for help on using tickets.