Repository navigation
Port the user write abilities (wp/user-create, wp/user-update, wp/user-delete) from WordPress/ai PR #1105 - #9
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Adds the three user write abilities to the package:
wp/user-create,wp/user-update, andwp/user-delete— a faithful port of WordPress/ai PR #1105 ("Addcore/user-create,core/user-update, andcore/user-deleteabilities", author @jorgefilipecosta), incubating under the experimental tier'swp/prefix (D5; D7: no aliases — upstream'score/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 theUsers_Queryhelpers (projection, normalization) —Users_Queryis a coreify-tracked core backport and stays byte-exact (verify:coreifyround-trip holds).username+emailplus optionalpassword,name,first_name,last_name,url,description,locale,nickname,slug, androles— without a password one is generated and the user is emailed a set-password link, as wp-admin does. Update takes anidand the same fields exceptusername(immutable). Delete takes anid+ requiredreassign: the ID of the user who receives the content, orfalseto delete the content (posts and pages go to the trash). Users cannot be trashed, so deletion is permanent. Each answers with the user through thecore/users-queryfield projection picked viafields; delete returns the user as it was before deletion; the password is never returned.create_userspluspromote_usersto give roles; update needsedit_user, orpromote_userwhen onlyrolesis given; delete needsdelete_user. An emptyroleslist removes every role; users cannot remove their own roles; users cannot delete their own account; users cannot be deleted on multisite.ability_invalid_inputat 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 underparams) are pinned where reachable, exactly as upstream's tests observe them.core/users-queryAbility #3 core-7.2 backport ofcore/users-queryalready carries every upstream query change (username-ordered collections,includewithoutper_pageon one page, the "Query Users" label, params-mapped filter errors,idrequired 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).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
wp_abilities_api_initcallback:( new WordPress\Abilities\Registrar )->register_all();wp/user-createwith{ "username": "newuser", "email": "user@example.com", "roles": ["editor"] }→ returns the user (no password, ever); without apasswordthe user is emailed a set-password link.wp/user-updatewith{ "id": 7, "name": "New Name" }→ the updated user;roleschanges needpromote_user.wp/user-deletewith{ "id": 7, "reassign": 1 }→ the user as it was, posts reassigned;reassign: false→ content trashed/deleted, user gone.create_users), cannot update others (edit_user) nor promote (promote_user); nobody can delete themselves or strip their own roles.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— tierexperimental, faithful ports of the user write abilities from WordPress/ai PR #1105 by @jorgefilipecosta, answering through thecore/users-queryfield projection.Co-authored-by: jorgefilipecosta jorgefilipecosta@users.noreply.github.com