Repository navigation
Port the term write abilities (wp/term-create, wp/term-update, wp/term-delete) from WordPress/ai PR #1103 - #11
Conversation
…lities 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>
…n 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.
|
Note on the second commit ( Core trunk r65044 (wordpress-develop #14882) added schema-aware input coercion ( That made one settings-update test (from #8, carried here via the branch base) fail against the new nightly — deterministically, on any commit after r65044, while remaining green on stable (its Abilities API comes from the bridge shim, pre-r65044). No code fix was warranted: the port's The fix is test-only, in two parts:
Verified locally against the current nightly (trunk @ |
What?
Adds the three term write abilities to the package:
wp/term-create,wp/term-update, andwp/term-delete— a faithful port of WordPress/ai PR #1103 ("Addcore/term-create,core/term-update, andcore/term-deleteabilities", author @jorgefilipecosta), incubating under the experimental tier'swp/prefix (D5; D7: no aliases). Builds on the mergedwp/terms-query(PR #10).Why?
Agents can read taxonomy terms but not manage them. This port gives consumers one canonical copy while the upstream proposal settles (plan item B6, part 2 — including the upstream's third ability,
term-delete, which this port carries in full).How?
src/Terms/Abstract_Term_Write.php(shared base) +Term_Create.php/Term_Update.php/Term_Delete.php.Terms_Queryis a hand-authoredwp/*class, so the established media sharing pattern applies: helpers (fields projection, term lookup, item schema, exposure check) extracted verbatim withprivate→protectedat the copy site;Terms_Queryitself untouched.taxonomyand aname, plus optionalslug,description, andparent(hierarchical taxonomies only). Update takes the term'sidand the values to change. Delete takes the term'sidandforce, which must betrue— terms cannot be trashed, so deletion is permanent. On update and delete,taxonomyis an optional guard. The term comes back in the shapewp/terms-queryuses, limited byfields; a delete returns{ deleted, previous }.edit_termsin a hierarchical taxonomy orassign_termsin a flat one; updating needsedit_term; deleting needsdelete_term. A missing term, or one outside the exposed taxonomies or the guard, is denied like a missing capability.map_meta_cap()answersdo_not_allowfordelete_termagainst the term named by thedefault_{$taxonomy}option, andwp_delete_term()returns 0 for it — the denial surfaces through the ported permission path. No bespoke protection logic added, faithfully.Termsregistration class (this package's Registrar owns registration),core/names, gating and unregister-core-copy wiring (D5/D7), REST run-endpoint tests and the JS e2e spec (this repo pins the contract atWP_Ability::execute()+ direct calls), and multisite-specific assertions (single-site wp-env).experimental,core_since: null,proposal→ the upstream PR; annotations ported exactly (create/update POST-served, delete DELETE-served).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
wp_abilities_api_initcallback:( new WordPress\Abilities\Registrar )->register_all();wp/term-createwith{ "taxonomy": "post_tag", "name": "Example" }→ the term through the terms-query projection;wp/term-updatewith{ "id": <id>, "name": "Renamed" };wp/term-deletewith{ "id": <id>, "force": true }→{ deleted: true, previous: … }. The default category delete is refused;forcemissing/false is rejected; taxonomy-guard mismatches are denied.edit_terms/edit_term/delete_term); creating a tag needs onlyassign_terms; below-floor roles denied per gate.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/term-create,wp/term-update,wp/term-delete— tierexperimental, faithful ports of the term write abilities from WordPress/ai PR #1103 by @jorgefilipecosta, answering through thewp/terms-queryfield projection.Co-authored-by: jorgefilipecosta jorgefilipecosta@users.noreply.github.com