#58238 closed defect (bug) (fixed)
comment_text filter not applied with correct number of arguments within REST API
Reported by: | sjregan | Owned by: | 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.
17 months ago
#1
- Keywords has-patch added
#3
@
10 months ago
- Owner set to SergeyBiryukov
- Resolution set to fixed
- Status changed from new to closed
In 57176:
@SergeyBiryukov commented on PR #4414:
10 months ago
#4
Thanks for the PR! Merged in r57176.
Note: See
TracTickets for help on using
tickets.
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