Skip to content

Conversation

@gziolo
Copy link
Member

@gziolo gziolo commented Oct 21, 2025

Trac ticket: https://core.trac.wordpress.org/ticket/64098

Follow-up for #9410.

Introduces a new REST API endpoint at wp-abilities/v1/categories to expose
ability categories through the WordPress REST API.

The new WP_REST_Abilities_V1_Categories_Controller provides:

  • GET /wp-abilities/v1/categories - Lists all ability categories with pagination
  • GET /wp-abilities/v1/categories/{slug} - Retrieves a single category by slug

Both endpoints require the read capability and return category data including
slug, label, description, and metadata. The collection endpoint supports pagination
with page and per_page parameters (default: 50, max: 100).


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@gziolo gziolo self-assigned this Oct 21, 2025
@github-actions
Copy link

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 gziolo.

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

@gziolo gziolo force-pushed the add/ability-categories-rest-controller branch from 994bfdc to 919511e Compare October 21, 2025 14:18
@gziolo gziolo changed the title Apply feedback from code review Abilities API: Add Ability Categories REST API controller Oct 21, 2025
@gziolo gziolo force-pushed the add/ability-categories-rest-controller branch from 919511e to cb95cdc Compare October 21, 2025 14:30
@github-actions
Copy link

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good! The only thing absent are hooks. I don't think we need a ton (not quite so many as WP_REST_Posts_Controller, but a few for filtering responses could be useful. Since it's all read-only I don't think we need actions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We filter abilities only by category slug:

// Filter by ability category if specified.
$category = $request['category'];
if ( ! empty( $category ) ) {
$abilities = array_filter(
$abilities,
static function ( $ability ) use ( $category ) {
return $ability->get_category() === $category;
}
);
// Reset array keys after filtering.
$abilities = array_values( $abilities );
}

For v1, this should be a good starting point.

In the WordPress 7.0 release cycle, we should expand support for other filtering options after we sort out:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I don't mean filtering via REST, I mean filtering via apply_filters(). 😄

Copy link
Member Author

@gziolo gziolo Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I committed the changes as having the controller is the most important.

@JasonTheAdams, can you draft something explaining your proposal further? Do you want to filter the list by categories, individual items, or both? How about the endpoint with abilities? Should it have the same extensibility in place for consistency?

@gziolo gziolo requested a review from TimothyBJacobs October 21, 2025 16:22
pento pushed a commit that referenced this pull request Oct 22, 2025
Introduces a new REST API endpoint at `wp-abilities/v1/categories` to expose
ability categories through the WordPress REST API.

The new `WP_REST_Abilities_V1_Categories_Controller` provides:

- GET `/wp-abilities/v1/categories` - Lists all ability categories with pagination
- GET `/wp-abilities/v1/categories/{slug}` - Retrieves a single category by slug

Both endpoints require the `read` capability and return category data including
slug, label, description, and metadata. The collection endpoint supports pagination
with `page` and `per_page` parameters (default: 50, max: 100).

Developed in #10380.

Follow-up [61032].

Props gziolo, jason_the_adams, timothyblynjacobs.
Fixes #64098.



git-svn-id: https://develop.svn.wordpress.org/trunk@61045 602fd350-edb4-49c9-b593-d223f7449a82
@github-actions
Copy link

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 61045
GitHub commit: 871fd0e

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions bot closed this Oct 22, 2025
github-actions bot pushed a commit to gilzow/wordpress-performance that referenced this pull request Oct 22, 2025
Introduces a new REST API endpoint at `wp-abilities/v1/categories` to expose
ability categories through the WordPress REST API.

The new `WP_REST_Abilities_V1_Categories_Controller` provides:

- GET `/wp-abilities/v1/categories` - Lists all ability categories with pagination
- GET `/wp-abilities/v1/categories/{slug}` - Retrieves a single category by slug

Both endpoints require the `read` capability and return category data including
slug, label, description, and metadata. The collection endpoint supports pagination
with `page` and `per_page` parameters (default: 50, max: 100).

Developed in WordPress/wordpress-develop#10380.

Follow-up [61032].

Props gziolo, jason_the_adams, timothyblynjacobs.
Fixes #64098.


Built from https://develop.svn.wordpress.org/trunk@61045


git-svn-id: https://core.svn.wordpress.org/trunk@60381 1a063a9b-81f0-0310-95a4-ce76da25c4cd
markjaquith pushed a commit to markjaquith/WordPress that referenced this pull request Oct 22, 2025
Introduces a new REST API endpoint at `wp-abilities/v1/categories` to expose
ability categories through the WordPress REST API.

The new `WP_REST_Abilities_V1_Categories_Controller` provides:

- GET `/wp-abilities/v1/categories` - Lists all ability categories with pagination
- GET `/wp-abilities/v1/categories/{slug}` - Retrieves a single category by slug

Both endpoints require the `read` capability and return category data including
slug, label, description, and metadata. The collection endpoint supports pagination
with `page` and `per_page` parameters (default: 50, max: 100).

Developed in WordPress/wordpress-develop#10380.

Follow-up [61032].

Props gziolo, jason_the_adams, timothyblynjacobs.
Fixes #64098.


Built from https://develop.svn.wordpress.org/trunk@61045


git-svn-id: http://core.svn.wordpress.org/trunk@60381 1a063a9b-81f0-0310-95a4-ce76da25c4cd
@gziolo gziolo deleted the add/ability-categories-rest-controller branch October 22, 2025 07:26
$offset = ( $page - 1 ) * $per_page;

$total_categories = count( $categories );
$max_pages = ceil( $total_categories / $per_page );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to cast int here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I see other occurrences use (int). Good catch, thank you 👍🏻

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

3 participants