Repository navigation
Abilities API: Add the core/terms-query, core/term-create, core/term-update and core/term-delete abilities - #16102
jorgefilipecosta wants to merge 1 commit into
Conversation
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. |
…term-update` and `core/term-delete` abilities. Adds four abilities for the terms of the taxonomies that set the new `show_in_abilities` argument of `register_taxonomy()`, which is on for `category` and `post_tag`. `core/terms-query` returns a page of the terms of a taxonomy with the totals, filtered by IDs, slugs, parent, post or `hide_empty`. `core/term-create`, `core/term-update` and `core/term-delete` create, change and permanently delete a term. The create and update abilities return the term in the same form as the query. The abilities require a logged-in user, and each call checks the capabilities of the user for the taxonomy and the term. A default term cannot be deleted. See #66743.
b5772b3 to
a53d52a
Compare
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. 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. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Shape from WordPress/abilities#22. Same approach as #16028.
This PR adds the
core/terms-query,core/term-create,core/term-updateandcore/term-deleteabilities to thecontentcategory, for the taxonomies that setshow_in_abilities:core/terms-querytakes{ where, fields, pagination }and returns{ items, pagination }with the totals.where.taxonomyis required, andids,slugs,parent,postandhide_emptyfilter the terms.core/term-createtakes{ data, fields }and returns the new term.data.taxonomyanddata.nameare required.core/term-updatetakes{ where: { taxonomy, id }, data, fields }, changes only the attributes indataand returns the term.core/term-deletetakes{ where: { taxonomy, id } }, deletes the term permanently and returns{ outcome }. A default term is refused.dataacceptsname,slug,descriptionandparent.Outside the new
WP_Abilities_Termsclass:register_taxonomy()accepts a newshow_in_abilitiesargument, stored inWP_Taxonomy::$show_in_abilities. It isfalseby default andtrueforcategoryandpost_tag.wp_register_core_abilities()loads the class and registers the abilities.Creating a category:
{ "id": 5, "taxonomy": "category", "name": "Product updates", "slug": "product-updates", "link": "http://localhost:8950/category/product-updates/" }Changing its slug and description, and asking for some fields:
{ "id": 5, "name": "Product updates", "slug": "updates", "description": "Release notes and roadmap updates." }Querying the top-level categories, two per page:
{ "items": [ { "id": 2, "name": "News", "slug": "news", "count": 1 }, { "id": 5, "name": "Product updates", "slug": "updates", "count": 0 } ], "pagination": { "total": 3, "total_pages": 2 } }Deleting it. For the default category the answer is a
term_is_defaulterror:{ "outcome": "deleted" }Trac ticket: https://core.trac.wordpress.org/ticket/66743
Testing
Verify unit tests are passing:
Or run the examples above in the editor console as an administrator.
AI disclosure: the change and tests were drafted with AI assistance (Claude Code).