Comments: Allow comment types to register a display callback#53
Comments: Allow comment types to register a display callback#53adamsilverstein wants to merge 4 commits into
Conversation
Add a `render_callback` argument to `register_comment_type()`, stored on `WP_Comment_Type`. When a comment's registered type defines one, `Walker_Comment` uses it to render that comment, receiving the same arguments as the `callback` argument of wp_list_comments() (the comment, the arguments, and the depth). This gives custom comment types control over their own display, as raised in the tracking ticket, without each type having to filter the walker. An explicit `callback` passed to wp_list_comments() still takes precedence, and built-in types set no callback, so there is no change to existing output. See #35214.
Cover the `render_callback` argument: that a registered type's callback renders its comments through `Walker_Comment`, that an explicit wp_list_comments() `callback` takes precedence, that a type without a callback renders normally, and that the property defaults to null and stores a provided callable. See #35214.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
…ard. Add a test asserting the render_callback receives the comment, the arguments array, and the depth (the documented wp_list_comments() callback contract, previously only the comment was exercised), and a test that a non-callable render_callback is ignored via is_callable() and the comment renders normally. See #35214.
Walker_Comment prints the render_callback output verbatim, matching the existing wp_list_comments() `callback` contract. Note in both the WP_Comment_Type::$render_callback property and the register_comment_type() parameter docs that the callback is responsible for escaping its output.
Description
Adds a
render_callbackargument toregister_comment_type()so a custom comment type can control how its comments are displayed in comment lists, addressing dshanske's request on the tracking ticket (#35214 comment:18) for "a way to register a callback to handle display that can still be overridden by the usual methods."What it adds
render_callbackregistration argument, stored onWP_Comment_Type(defaultnull).Walker_Comment::start_el()dispatches to a comment type'srender_callbackwhen one is set, passing the same arguments as the wp_list_comments()callback: the comment, the arguments array, and the depth.Precedence / non-breaking
callbackpassed towp_list_comments()still takes precedence (handled before the type callback).comment,pingback,trackback) set no callback, so their output is unchanged.Scope / boundary
Stacked on WordPress#12311 (the
register_comment_type()API) and targets that branch; it will be retargeted totrunkonce WordPress#12311 lands. This is item 3 of the remaining below-the-hood work on #35214.Item 4 (generalizing the remaining hard-coded
pingback/trackbackchecks inWalker_Commentandseparate_comments()) is intentionally not included: those checks encode a ping-vs-comment distinction the registry does not yet model, so generalizing them safely needs a dedicated "ping grouping" concept on the registration object and carries output-regression risk. It is better handled as its own focused PR.Testing
New coverage in
tests/phpunit/tests/comment/walker.phpandwpCommentType.php. PHPCS and PHPStan are clean on the changed files.See #35214.