#58238 closed defect (bug) (fixed)
comment_text filter not applied with correct number of arguments within REST API
| Reported by: | sjregan | Owned by: | SergeyBiryukov |
|---|---|---|---|
| Priority: | normal | Milestone: | 6.5 |
| Component: | REST API | Version: | 6.2 |
| Severity: | normal | Keywords: | has-patch |
| Cc: | Focuses: |
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.
3 years ago
#1
- Keywords has-patch added
@SergeyBiryukov commented on PR #4414:
3 years ago
#4
Thanks for the PR! Merged in r57176.
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
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