Skip to content

Port the user write abilities (wp/user-create, wp/user-update, wp/user-delete) from WordPress/ai PR #1105 - #9

Merged
nikmclaughlin merged 1 commit into
mainfrom
add/user-writes
Oct 30, 2026
Merged

nikmclaughlin merged 1 commit into
mainfrom
add/user-writes

Conversation

@nikmclaughlin

Copy link
Copy Markdown
Contributor

What?

Adds the three user write abilities to the package: wp/user-create, wp/user-update, and wp/user-delete — a faithful port of WordPress/ai PR #1105 ("Add core/user-create, core/user-update, and core/user-delete abilities", author @jorgefilipecosta), incubating under the experimental tier's wp/ prefix (D5; D7: no aliases — upstream's core/user-* names are not carried).

Why?

Agents can read users (core/users-query, PR #3) but not manage them. This port gives consumers one canonical copy while the upstream proposal settles (plan item B5).

How?

  • src/Users/Abstract_User_Write.php (shared base) + User_Create.php / User_Update.php / User_Delete.php, per the established media-write pattern. Per the B3 lesson the base embeds verbatim copies of the Users_Query helpers (projection, normalization) — Users_Query is a coreify-tracked core backport and stays byte-exact (verify:coreify round-trip holds).
  • Contracts: create takes username + email plus optional password, name, first_name, last_name, url, description, locale, nickname, slug, and roles — without a password one is generated and the user is emailed a set-password link, as wp-admin does. Update takes an id and the same fields except username (immutable). Delete takes an id + required reassign: the ID of the user who receives the content, or false to delete the content (posts and pages go to the trash). Users cannot be trashed, so deletion is permanent. Each answers with the user through the core/users-query field projection picked via fields; delete returns the user as it was before deletion; the password is never returned.
  • Floors: create needs create_users plus promote_users to give roles; update needs edit_user, or promote_user when only roles is given; delete needs delete_user. An empty roles list removes every role; users cannot remove their own roles; users cannot delete their own account; users cannot be deleted on multisite.
  • Error-code honesty (observable contract): unknown roles and schema violations answer ability_invalid_input at input validation; missing users answer the route's generic denial (a now-missing user fails the permission callback like an unreadable one); the in-execute refusals (users_cannot_edit_roles, users_user_invalid_reassign, invalid username/params under params) are pinned where reachable, exactly as upstream's tests observe them.
  • Companion changes: none needed — the PR Backport the core/users-query Ability #3 core-7.2 backport of core/users-query already carries every upstream query change (username-ordered collections, include without per_page on one page, the "Query Users" label, params-mapped filter errors, id required in the nested user schema); verified and pinned by a test. The upstream's gated-class rename (Users_Query → Users) is plugin scaffolding — not ported (D7; the Registrar owns registration).
  • Annotations/manifest: tier experimental, core_since: null, category: user, proposal → the upstream PR; create/update POST-served, delete DELETE-served, exactly as the upstream registers them.

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/user-create with { "username": "newuser", "email": "user@example.com", "roles": ["editor"] } → returns the user (no password, ever); without a password the user is emailed a set-password link. wp/user-update with { "id": 7, "name": "New Name" } → the updated user; roles changes need promote_user. wp/user-delete with { "id": 7, "reassign": 1 } → the user as it was, posts reassigned; reassign: false → content trashed/deleted, user gone.
  3. Floors: editors cannot create (create_users), cannot update others (edit_user) nor promote (promote_user); nobody can delete themselves or strip their own roles.
  4. 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/user-create, wp/user-update, wp/user-delete — tier experimental, faithful ports of the user write abilities from WordPress/ai PR #1105 by @jorgefilipecosta, answering through the core/users-query field projection.

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

…lities from WordPress/ai PR #1105

## What?

Adds the three user write abilities to the package: a faithful port of
WordPress/ai PR #1105 ("Add `core/user-create`, `core/user-update`, and
`core/user-delete` abilities", author @jorgefilipecosta), incubating under the
experimental tier's `wp/` prefix (D5). The upstream's `core/user-*` names are
not adopted; no aliases exist (D7). Category `user` (tier experimental).

## Why?

Agents can query users through abilities (PR #3's `core/users-query`) but not
create, update, or delete them. This package ports the three writes so
consumers get one canonical copy while the upstream proposal settles.

## How?

- **The abilities:** `src/Users/Abstract_User_Write.php` (shared base) +
  `User_Create.php` / `User_Update.php` / `User_Delete.php` mirror the PR's
  logic — labels, descriptions, schemas (create requires `username` + `email`;
  update takes `id` and everything but `username`; delete requires `id` +
  `reassign`), annotations (create: `idempotent: false`; update:
  `destructive: true`/`idempotent: false` — DELETE would carry the password in
  the query string; delete: destructive idempotent, DELETE-served), error
  codes, the roles rules (empty list removes every role, self-role-removal and
  self-deletion prevented, users cannot be deleted on multisite, the delete
  answers with the user as it was — the password is never returned), and the
  set-password/email flow when a create omits the password.
- **Shared state:** the field projection, normalization, and
  `format_user()`'s `$edit_context` write-side parameter live as self-contained
  verbatim copies of the package's `Users_Query` port — deliberately NOT a
  `Users_Query` extension or refactor, because the coreify round-trip gate
  diffs that class against the tracked core-trunk fixture (the B3 lesson).
- **Companion (D2) verified, nothing ported:** the PR-side `core/users-query`
  changes (label "Query Users", username-ordered collections, the
  include-without-per_page max-page behavior, params-mapped filter errors,
  `id` required in the user output schema) are already present in the PR #3
  core-7.2 backport; verification is pinned in the new suite.

## 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

- New: `tests/Abilities/UserWritesTest.php` — the triad (success incl. the
  projected answers with the password never returned and the generated
  password; capability: create_users/promote_users/edit_user/delete_user
  gates, self-deletion and self-role-removal prevented, reassignment
  semantics with the posts moving; bad input: invalid username, empty
  password, unknown role, missing/repeat rows) + the companion users-query pin.
- `composer run lint:phpcs`, `lint:phpstan`, `verify:manifest`, `verify:coreify`
  and the PHPUnit suite on BOTH wp-env environments (trunk then stable, one at
  a time, stopped between) pass.

Co-authored-by: jorgefilipecosta <jorgefilipecosta@users.noreply.github.com>
@nikmclaughlin
nikmclaughlin merged commit 8270285 into main Oct 30, 2026
12 checks passed
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.

1 participant