- 
                Notifications
    You must be signed in to change notification settings 
- Fork 3.1k
Abilities API: Add Ability Categories REST API controller #10380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Abilities API: Add Ability Categories REST API controller #10380
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.
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.
There was a problem hiding this comment.
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:
wordpress-develop/src/wp-includes/rest-api/endpoints/class-wp-rest-abilities-v1-list-controller.php
Lines 96 to 107 in c6c922c
| // 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:
There was a problem hiding this comment.
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(). 😄
There was a problem hiding this comment.
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?
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.
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
There was a problem hiding this comment.
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 👍🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.