Abilities API: Add Ability Categories REST API controller#10380
Abilities API: Add Ability Categories REST API controller#10380gziolo wants to merge 1 commit intoWordPress:trunkfrom
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. |
994bfdc to
919511e
Compare
919511e to
cb95cdc
Compare
cb95cdc to
04c7a07
Compare
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
We filter abilities only by category slug:
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:
There was a problem hiding this comment.
Sorry, I don't mean filtering via REST, I mean filtering via apply_filters(). 😄
There was a problem hiding this comment.
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?
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
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
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
| $offset = ( $page - 1 ) * $per_page; | ||
|
|
||
| $total_categories = count( $categories ); | ||
| $max_pages = ceil( $total_categories / $per_page ); |
There was a problem hiding this comment.
Better to cast int here
There was a problem hiding this comment.
Ok, I see other occurrences use (int). Good catch, thank you 👍🏻
There was a problem hiding this comment.
Addressed with https://core.trac.wordpress.org/changeset/61047.
Trac ticket: https://core.trac.wordpress.org/ticket/64098
Follow-up for #9410.
Introduces a new REST API endpoint at
wp-abilities/v1/categoriesto exposeability categories through the WordPress REST API.
The new
WP_REST_Abilities_V1_Categories_Controllerprovides:/wp-abilities/v1/categories- Lists all ability categories with pagination/wp-abilities/v1/categories/{slug}- Retrieves a single category by slugBoth endpoints require the
readcapability and return category data includingslug, label, description, and metadata. The collection endpoint supports pagination
with
pageandper_pageparameters (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.