Comments: Add a REST API endpoint for comment types#51
Conversation
|
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. |
|
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 |
Expose registered comment types through a read-only `/wp/v2/comment-types` controller, mirroring the post types controller (`/wp/v2/types`). This lets REST clients discover the registered types and their labels, which the block editor's inline-commenting work needs in order to add and query comments by type. Add a `show_in_rest` argument to `WP_Comment_Type` (defaulting to the value of `public`, as `show_ui` does) to gate which types the endpoint exposes. The built-in `comment`, `pingback`, and `trackback` types are public and therefore visible; the internal `note` type is not. Builds on the registration API in WordPress#12311. See #35214.
Cover the `/wp/v2/comment-types` controller: route registration, the context param, listing public types while excluding non-REST types (`note` and types that opt out via `show_in_rest`), single-type reads, permission checks for the `edit` context, and the item schema. Also assert the `show_in_rest` cascade on `WP_Comment_Type` and add the two new routes to the REST schema route list. See #35214.
Add happy-path coverage for the controller's dedicated HEAD-request handling in get_items() and prepare_item_for_response(), mirroring the post-types controller (ticket 56481): a collection HEAD request returns 200 without preparing item data, single-item HEAD requests still run the rest_prepare_comment_type filter and allow header injection, and HEAD requests with _fields succeed. Also assert the api.w.org/items link points at the type-filtered comments collection. See #35214.
6be8f2f to
7daed7e
Compare
Description
Adds a read-only
/wp/v2/comment-typesREST endpoint that exposes the comment types registered viaregister_comment_type(), mirroring the existing post types controller (/wp/v2/types).This lets REST clients discover the registered comment types and their labels. It directly serves the block editor's inline-commenting work (see #35214 comment:48), which needs to add and query comments by a registered
block_commenttype.What it adds
WP_REST_Comment_Types_Controllerwith two read-only routes:GET /wp/v2/comment-types- list public comment types.GET /wp/v2/comment-types/{type}- a single comment type.show_in_restargument onWP_Comment_Type, defaulting to the value ofpublic(the same wayshow_uicascades). It gates which types the endpoint exposes:comment,pingback,trackbackare public, so they are visible.notetype is not public, so it is not exposed.name,slug,description, and (in theeditcontext)labels. Theeditcontext requires themoderate_commentscapability.The endpoint is additive and read-only, so there is no back-compat impact.
Scope / boundary
This is the next small, additive step on the #35214 tracking ticket, after:
register_comment_type()registration API + labels (this PR is stacked on it and targets that branch; it will be retargeted totrunkonce Comments: Introduce a register_comment_type() API WordPress/wordpress-develop#12311 lands).default_excluded_comment_typesquery filter.Out of scope here (follow-ups): capabilities / meta-caps, admin UI, and generalizing the remaining hard-coded comment-type handling.
Testing
tests/phpunit/tests/rest-api/rest-comment-types-controller.phpcovers route registration, the context param, listing (including exclusion ofnoteandshow_in_rest => falsetypes), single reads, invalid/non-REST type handling,edit-context permission checks, and the schema.WP_Comment_Type'sshow_in_restcascade is asserted intests/phpunit/tests/comment/types.php.PHPCS and PHPStan are clean on the changed files.
See #35214.