Skip to content

Abilities API: Add the core/terms-query, core/term-create, core/term-update and core/term-delete abilities - #16102

Open
jorgefilipecosta wants to merge 1 commit into
WordPress:trunkfrom
jorgefilipecosta:add/term-abilities
Open

jorgefilipecosta wants to merge 1 commit into
WordPress:trunkfrom
jorgefilipecosta:add/term-abilities

Conversation

@jorgefilipecosta

@jorgefilipecosta jorgefilipecosta commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Shape from WordPress/abilities#22. Same approach as #16028.

This PR adds the core/terms-query, core/term-create, core/term-update and core/term-delete abilities to the content category, for the taxonomies that set show_in_abilities:

  • core/terms-query takes { where, fields, pagination } and returns { items, pagination } with the totals. where.taxonomy is required, and ids, slugs, parent, post and hide_empty filter the terms.
  • core/term-create takes { data, fields } and returns the new term. data.taxonomy and data.name are required.
  • core/term-update takes { where: { taxonomy, id }, data, fields }, changes only the attributes in data and returns the term.
  • core/term-delete takes { where: { taxonomy, id } }, deletes the term permanently and returns { outcome }. A default term is refused.
  • data accepts name, slug, description and parent.
  • The abilities require a logged-in user, and each call checks the capabilities of the user for the taxonomy and the term.

Outside the new WP_Abilities_Terms class:

  • register_taxonomy() accepts a new show_in_abilities argument, stored in WP_Taxonomy::$show_in_abilities. It is false by default and true for category and post_tag.
  • wp_register_core_abilities() loads the class and registers the abilities.

Creating a category:

const term = await wp.apiFetch( {
	path: '/wp-abilities/v1/abilities/core/term-create/run',
	method: 'POST',
	data: {
		input: {
			data: { taxonomy: 'category', name: 'Product updates', description: 'Release notes.' },
		},
	},
} );
{
	"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:

await wp.apiFetch( {
	path: '/wp-abilities/v1/abilities/core/term-update/run',
	method: 'POST',
	data: {
		input: {
			where: { taxonomy: 'category', id: term.id },
			data: { slug: 'updates', description: 'Release notes and roadmap updates.' },
			fields: [ 'name', 'slug', 'description' ],
		},
	},
} );
{ "id": 5, "name": "Product updates", "slug": "updates", "description": "Release notes and roadmap updates." }

Querying the top-level categories, two per page:

await wp.apiFetch( {
	path: wp.url.addQueryArgs( '/wp-abilities/v1/abilities/core/terms-query/run', {
		input: {
			where: { taxonomy: 'category', parent: 0 },
			fields: [ 'name', 'slug', 'count' ],
			pagination: { per_page: 2 },
		},
	} ),
} );
{
	"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_default error:

await wp.apiFetch( {
	path: wp.url.addQueryArgs( '/wp-abilities/v1/abilities/core/term-delete/run', {
		input: { where: { taxonomy: 'category', id: term.id } },
	} ),
	method: 'DELETE',
} );
{ "outcome": "deleted" }

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

Testing

Verify unit tests are passing:

npm run test:php -- --group 66743

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

@github-actions

Copy link
Copy Markdown

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

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

@jorgefilipecosta jorgefilipecosta added the Core abilities Core abilities related tasks label Nov 19, 2026
@jorgefilipecosta jorgefilipecosta moved this from Todo to In progress in Core abibilities Nov 19, 2026
@jorgefilipecosta jorgefilipecosta self-assigned this Nov 19, 2026
…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.
@jorgefilipecosta
jorgefilipecosta marked this pull request as ready for review November 20, 2026 15:13
@jorgefilipecosta jorgefilipecosta moved this from In progress to Neeeds review in Core abibilities Nov 20, 2026
@github-actions

Copy link
Copy Markdown

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:

Props jorgefilipecosta.

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


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Core abilities Core abilities related tasks

Projects

Status: Neeeds review

Development

Successfully merging this pull request may close these issues.

1 participant