Skip to content

Comments: Add a REST API endpoint for comment types#51

Open
adamsilverstein wants to merge 3 commits into
feature/register-comment-typefrom
feature/rest-comment-types
Open

Comments: Add a REST API endpoint for comment types#51
adamsilverstein wants to merge 3 commits into
feature/register-comment-typefrom
feature/rest-comment-types

Conversation

@adamsilverstein

Copy link
Copy Markdown
Owner

Description

Adds a read-only /wp/v2/comment-types REST endpoint that exposes the comment types registered via register_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_comment type.

What it adds

  • WP_REST_Comment_Types_Controller with two read-only routes:
    • GET /wp/v2/comment-types - list public comment types.
    • GET /wp/v2/comment-types/{type} - a single comment type.
  • A show_in_rest argument on WP_Comment_Type, defaulting to the value of public (the same way show_ui cascades). It gates which types the endpoint exposes:
    • comment, pingback, trackback are public, so they are visible.
    • the internal note type is not public, so it is not exposed.
  • The controller exposes name, slug, description, and (in the edit context) labels. The edit context requires the moderate_comments capability.

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:

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.php covers route registration, the context param, listing (including exclusion of note and show_in_rest => false types), single reads, invalid/non-REST type handling, edit-context permission checks, and the schema. WP_Comment_Type's show_in_rest cascade is asserted in tests/phpunit/tests/comment/types.php.

$ phpunit --group comment
OK (599 tests, 1506 assertions)

$ phpunit --filter WP_Test_REST_Comment_Types_Controller
OK (18 tests, 71 assertions)

PHPCS and PHPStan are clean on the changed files.

See #35214.

@github-actions

Copy link
Copy Markdown

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props adamsilverstein.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 568acaaf-bccc-49b8-8c0c-7563e82bee4e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/rest-comment-types

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.
@adamsilverstein adamsilverstein force-pushed the feature/rest-comment-types branch from 6be8f2f to 7daed7e Compare June 25, 2026 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant