-
Notifications
You must be signed in to change notification settings - Fork 47
Add category listing endpoints for the REST API #120
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
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## trunk #120 +/- ##
============================================
+ Coverage 86.65% 88.50% +1.84%
- Complexity 148 162 +14
============================================
Files 18 19 +1
Lines 982 1140 +158
Branches 92 92
============================================
+ Hits 851 1009 +158
Misses 131 131
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
This largely limits who can consume these abilities. For example, plugin developer no longer will be able to integrate a simple readonly ability on the client executed upon user interaction when they are only logged in but with read permissions. This essentially means abilities become discoverable on the client only for users with high-level of permissions. One of the future integrations for abilities is Command Palette where I would expect all logged in users would be able to see at least subset of abilities listed in the UI. |
|
Maybe the alternative solution for starters is to prevent exposure of |
True and that is a good valid use case. It just kind of stood out to me as maybe too open as I was introducing another endpoint. I've backed it out for now, however ee2039e |
|
I checked the code and I don’t have any other feedback. The implementation proposed looks solid from my perspective. Thank you for helping here! |
|
Aside, I’m happy to discuss how to ensure we don’t accidentally try to send through REST API class instances or callables if someone adds them to |
* add: category listing endpoints for the REST API * update: back out permissions check changes Co-authored-by: emdashcodes <[email protected]> Co-authored-by: gziolo <[email protected]>
* Docs refactor in prepartion for WordPress 6.9 Moved all PHP related docs to the php-api.md Created new README.md file with correct doc ordering Removed doc file numbering Updating main repo README.md doc links * Updating hooks Adding reference for abilities_api_init Moving hook registration in code examples above callback function for better readability * Adding other category functions to PHP API * Update README.md with direct link to docs README * Adding ability_class information and example (#122) * Adding ability_class information and example * Adding contributing docs to Documenation section in the readme * Fixing outdated link * PR review updates * Adding REST API docs updates from #120 * JavaScript client updates from #120 Co-authored-by: jonathanbossenger <[email protected]> Co-authored-by: gziolo <[email protected]> Co-authored-by: aaronware <[email protected]> Co-authored-by: galatanovidiu <[email protected]>
This PR introduces a new REST endpoint for discovering and listing ability categories.
Why
Following PRs #102 and #114 which introduced the categories system, we need a way to expose category information via the REST API so that it can be used in places like the command pallete, agents, etc.
External systems and AI agents need to discover what categories exist before they can effectively filter and query abilities.
Additionally, the existing abilities endpoints were accessible to any authenticated user withreadcapability, which could return meta information about available capabilities to subscribers (though, I believe they would need an application password setup). I've updated the permission check to requiremanage_optionsinstead, which I think might be better for the endpoints. What do you think?How
Created a new
WP_REST_Abilities_Categories_Controller:GET /wp/v2/abilities/categories(list) andGET /wp/v2/abilities/categories/{slug}self,collection, andabilitieslinks for API discoverabilitypage/per_pageparameters (default 50, max 100)readtomanage_optionsfor both categories and abilities endpoints (see note above)How to Test
Make sure that you have a few categories and Abilities registered.
List categories
curl -u "admin:APP_PASSWORD" \ https://example.com/wp-json/wp/v2/abilities/categoriesself,collection, andabilitiesGet single category
curl -u "admin:APP_PASSWORD" \ https://example.com/wp-json/wp/v2/abilities/categories/data-retrievalTest pagination
X-WP-TotalandX-WP-TotalPagesheadersTest filtering abilities by category
Test permissions
Test 404 handling
curl -u "admin:APP_PASSWORD" \ https://example.com/wp-json/wp/v2/abilities/categories/non-existentrest_category_not_founderror code