Skip to content

Port the wp/terms-query ability from WordPress/ai PR #1099 - #10

Merged
nikmclaughlin merged 1 commit into
mainfrom
add/terms-query
Oct 30, 2026
Merged

nikmclaughlin merged 1 commit into
mainfrom
add/terms-query

Conversation

@nikmclaughlin

Copy link
Copy Markdown
Contributor

What?

Adds wp/terms-query to the package: a faithful port of WordPress/ai PR #1099 ("Add core/terms-query ability", author @jorgefilipecosta), incubating under the experimental tier's wp/ prefix (D5; D7: no aliases — upstream's core/terms-query name is not carried).

Why?

Agents can read posts, users, settings, and media — but not taxonomy terms. This port reads categories, tags, and other opted-in taxonomies like the REST terms endpoints do (plan item B6, part 1).

How?

  • src/Terms/Terms_Query.php on Abstract_Core_Ability: three modes — a term by id (optionally guarded by taxonomy), a term by taxonomy + slug, or the terms of one taxonomy filtered by search, include, exclude, parent, post, hide_empty, orderby, order, page, and per_page, answered as { terms, total, total_pages }.
  • Fields: id, count, description, link, name, slug, taxonomy, parent (hierarchical taxonomies only); the default set omits description and link; id is always returned.
  • Taxonomy opt-in: taxonomies are exposed via show_in_abilities, like post types for core/content-query. Core 7.2 provides the flag; a package polyfill covers 6.9–7.1 (per the setting_show_in_abilities precedent) and marks category + post_tag. The polyfill's readers accept any truthy opt-in value identically to core's bool cast (verified on trunk); noted in KNOWN-ISSUES.
  • Pinned realities (KNOWN-ISSUES): term search matches name and slug only (the REST-mirroring semantics of this WP version), and collection positives for post-boot-registered taxonomies are pinned at registration time (a suite-harness constraint, noted inline).
  • Annotations: readonly: true (read-only); manifest: tier experimental, core_since: null, proposal → the upstream PR, category ported verbatim from the source registration.

Use of AI tools

Tool(s): goose (agent). Model(s): provided via the harness. Used for: implementation, tests, and docs. Reviewed and edited by the committer.

Testing Instructions

  1. Load the package in a wp_abilities_api_init callback: ( new WordPress\Abilities\Registrar )->register_all();
  2. Run wp/terms-query with { "taxonomy": "category" } (collection, { terms, total, total_pages }), { "id": 1 } (single term), and { "taxonomy": "category", "slug": "uncategorized" }; try the fields picker and hide_empty.
  3. Gates: composer run lint:phpcs && composer run lint:phpstan && composer run verify:manifest && composer run verify:coreify, and the PHPUnit suite on both wp-env environments (trunk + stable, one at a time) pass.

Changelog entries

Added (CHANGELOG.md): wp/terms-query — tier experimental, faithful port of the terms read ability from WordPress/ai PR #1099 by @jorgefilipecosta: reads categories, tags, and other show_in_abilities taxonomies by id, by taxonomy+slug, or as a filtered paginated collection.

Co-authored-by: jorgefilipecosta jorgefilipecosta@users.noreply.github.com

Faithful port of the read-only terms query ability from
WordPress/ai PR #1099 (author @jorgefilipecosta), on this package's
Abstract_Core_Ability authoring surface:

- `src/Terms/Terms_Query.php` — the three oneOf modes (a term by ID with
  the optional taxonomy guard, a term by taxonomy + slug, and a filtered
  collection answered as { terms, total, total_pages }), the PR's schemas,
  annotations (readonly, closed-world), permission gates, field projection
  (id always; description/link off by default; parent hierarchical-only),
  error codes, and REST-mirroring quirks. Name `core/terms-query` is not
  carried (D5: wp/ tier experimental, D7: no aliases); registration is the
  Registrar's; text domain default.
- Companion support-surface feature `taxonomy_show_in_abilities`
  (Support/Features) with the package polyfill marking the built-in
  `category` and `post_tag` through register_taxonomy_args, mirroring the
  PR's Show_In_Abilities companion. Verified: no currently supported core
  declares the WP_Taxonomy flag (7.1 stable and 7.2-beta3 both lack it), so
  the polyfill marks on both environment branches.
- Manifest entry `wp/terms-query` (experimental, content category,
  proposal ai#1099, requires) + tests/Abilities/TermsQueryTest.php (the
  ported test triad), README/CHANGELOG/KNOWN-ISSUES updates.

Co-authored-by: jorgefilipecosta <jorgefilipecosta@users.noreply.github.com>
@nikmclaughlin
nikmclaughlin merged commit 5fba8a4 into main Oct 30, 2026
12 checks passed
nikmclaughlin added a commit that referenced this pull request Oct 30, 2026
…m-delete) from WordPress/ai PR #1103 (#11)

* Port the `wp/term-create`, `wp/term-update`, and `wp/term-delete` Abilities from WordPress/ai PR #1103

## What?

Adds the three term write abilities to the package: a faithful port of
WordPress/ai PR #1103 ("Add `core/term-create`, `core/term-update`, and
`core/term-delete` abilities", author @jorgefilipecosta), incubating under the
experimental tier's `wp/` prefix on the shared `content` category and field
projection of `wp/terms-query` (PR #10). The PR's `core/term-*` registration
names, gating, and unregister-core-copy wiring are not copied; no aliases
exist (D7).

## Why?

Agents can read terms through abilities (`wp/terms-query`) but not write them.
This package ports the three writes so consumers get one canonical copy while
the upstream proposal settles.

## How?

- **The abilities:** `src/Terms/Abstract_Term_Write.php` (shared base) +
  `Term_Create.php` / `Term_Update.php` / `Term_Delete.php` mirror the PR's
  logic — labels, descriptions, schemas, annotations (create POST semantics,
  update POST with destructive=true idempotent=false, delete DELETE with
  destructive=true idempotent=true), error codes, and the guard semantics.
  Create takes a `taxonomy` and a `name`, plus optional `slug`,
  `description`, and `parent` (hierarchical only); update takes `id` and the
  values to change; delete takes `id` and `force`, which must be true because
  terms cannot be trashed (non-forced answers `terms_trash_not_supported`,
  501). On update and delete, `taxonomy` is an optional guard.
- **The floors:** creating needs `edit_terms` in a hierarchical taxonomy or
  `assign_terms` in a flat one; updating needs `edit_term`; deleting needs
  `delete_term`. A missing term, one outside the exposed taxonomies, or one
  outside the guard is denied like a missing capability — a generic denial
  through the validated transport, `terms_term_invalid` (404) on a direct
  call; a malformed `id` or non-string guard fails closed, never cast onto
  another term.
- **The default category is not protected by any code of its own** (as upstream): core's `map_meta_cap()` answers `do_not_allow` for `delete_term`
  against the term named by the `default_{$taxonomy}` option, and
  `wp_delete_term()` returns 0 for it — the denial surfaces as the generic
  transport denial, `terms_cannot_delete` (403) on a direct call, and
  `terms_cannot_delete` (500) when a filter grants the capability anyway.
- **Answers through the query's contract:** written terms return through the
  `wp/terms-query` projection (`fields` picking the subset, the ID always
  included, `parent` only for hierarchical taxonomies); a delete returns
  `{ deleted, previous }`.
- **Code sharing (media pattern):** `Terms_Query` is a hand-authored `wp/*`
  class, so its shared helpers (`fields` projection, term lookup, item
  schema) are extracted verbatim from this package's PR #10 port with
  `private` relaxed to `protected`, into `Abstract_Term_Write`; `Terms_Query`
  itself keeps its byte-stable backport shape (verify:coreify holds).
- **Companions:** the taxonomy opt-in machinery the writes ride (`show_in_abilities`
  on WP_Taxonomy, polyfilled pre-7.2) and the projection both came from PR
  #10; the writes need nothing beyond riding them. Manifest entries declare
  the `taxonomy_show_in_abilities` support feature, as the query does.

Co-authored-by: jorgefilipecosta <jorgefilipecosta@users.noreply.github.com>

* Tests: pin the settings-update unique-list rows to the r65044 coercion contract

## What?

A test-only trunk-drift fix for the settings-update suite (no `src/` change).
Core r65044 (#14882, #66383) added `WP_Ability::coerce_input()`, which the
Abilities API now runs after validation and before the permission check and
execute callback. The `uniqueItems` fixture `('1', '01')` — unique as strings,
colliding after the cast — is refused by that layer with `ability_invalid_input`
before the plugin code runs, so
`SettingsUpdateTest::test_a_value_sanitizing_makes_invalid_is_refused`, which
pinned the former contract (`settings_invalid_param` from the plugin), failed
deterministically against the trunk nightly (CI run 41034270103).

## How?

- The colliding row (`test_a_value_sanitizing_makes_invalid_is_refused`) now
  pins the framework contract where the coercion layer exists (the exact fixture
  core's own `data_input_coercion_errors` regression test pins):
  `ability_invalid_input`, no error data (refusal came from the framework, the
  plugin's execute callback never ran), nothing written. Hosts without the
  layer (7.1-, the stable matrix job) keep the plugin's `settings_invalid_param`
  mapping assertions.
- A distinct-after-coercion row (`test_a_list_unique_after_coercion_still_updates`)
  keeps the callback-reachable list coverage: items casting to distinct integers
  ('1' and '02') pass validation and coercion, and the coerced list is what the
  answer carries and what gets stored.
- The mapping row (`test_the_plugin_sanitize_refusal_maps_to_settings_invalid_param`)
  covers the plugin's unchanged `settings_invalid_param` semantics (400, the
  named param, the all-or-nothing order) directly on the plugin's execute path,
  as the companion read row already does, since `execute()` can no longer reach
  the callback with the colliding fixture on coercion hosts.
- The `su_list_setting` registration the three rows share moved to
  `register_unique_list_setting()`.

Verified: green against the current trunk nightly (post-r65044) and stable
(7.1.4), one wp-env at a time; `phpcs` and `phpstan` clean.

---------

Co-authored-by: jorgefilipecosta <jorgefilipecosta@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a core/terms-query ability (taxonomies, categories, tags)

1 participant