Skip to content

Backport the core/users-query Ability - #3

Merged
nikmclaughlin merged 22 commits into
WordPress:mainfrom
dkotter:add/read-users-backport
Oct 29, 2026
Merged

nikmclaughlin merged 22 commits into
WordPress:mainfrom
dkotter:add/read-users-backport

Conversation

@dkotter

@dkotter dkotter commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Important

This branch is based off of #2, so leaving this in draft until that has been merged

What?

Adds core/users-query to the package as a backport of the ability that ships in WordPress 7.2.

Depends on #2 (core/settings-get), which this branch is built on. Until #2 merges, this PR also shows #2's commits.

Why?

Brings the core/users-query Ability into this package, allowing consumers to get one canonical copy on WordPress 6.9–7.1. On 7.2+, core's copy is used and the package copy is skipped

How?

  • The ability: src/Users/Users_Query.php was generated from core's class with tools/coreify.php --reverse and matches it apart from the package wrapper.
  • No polyfill needed: everything the ability uses already exists in WordPress 6.9.
  • Manifest and categories: a manifest entry, plus the user category definition copied from core.
  • coreify: a profile for the new ability, so its round-trip check now covers all three backports.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Implementation, tests, and an independent review pass. I reviewed and edited the result.

Testing Instructions

  1. On a WordPress 7.1 site, copy or symlink tools/wordpress-abilities-bridge into wp-content/plugins/ and activate WordPress Abilities Bridge. If you copy it rather than symlink it, add define( 'WP_ABILITIES_PACKAGE_PATH', '/path/to/wordpress-abilities' ); to wp-config.php.
  2. Confirm the bridge's admin notice lists core/users-query as registered.
  3. As an administrator, open the post editor, open the browser console, and run:
    await wp.apiFetch( { path: '/wp-abilities/v1/abilities/core/users-query/run?input[fields][]=id&input[fields][]=username&input[fields][]=roles' } )
    It should return the site's users with their usernames and roles, plus pagination totals.
  4. Open /wp-json/wp-abilities/v1/abilities/core/users-query/run in a private window (logged out). It should return a 401 "not allowed to execute this ability" error.
  5. Log in as a Subscriber and repeat step 3. Only users who have published posts should be listed, and username and roles should be left out, except on your own account if you're in the list.
  6. On a WordPress 7.2 site, repeat steps 1–4. The results should match, but here core provides the ability and the package copy is skipped.

Changelog Entry

Added - core/users-query ability, backported from WordPress 7.2 for WordPress 6.9–7.1.

@nikmclaughlin
nikmclaughlin marked this pull request as ready for review October 29, 2026 17:55
@nikmclaughlin nikmclaughlin changed the title Backport the core/read-users Ability Backport the core/users-query Ability Oct 29, 2026
@nikmclaughlin
nikmclaughlin merged commit 4a77ee6 into WordPress:main Oct 29, 2026
6 checks passed
@nikmclaughlin

Copy link
Copy Markdown
Contributor

Merged — thanks @dkotter!

Housekeeping note: after #2's squash merge, GitHub's "Update branch" reported conflicts (the stacked commits vs. the squashed #2 on main). I resolved them by pushing a merge commit (254be0d) to your fork branch that records main and keeps this branch's content — the resulting PR diff was exactly your own 7 commits' changes, and CI ran green on it before the squash merge. Also renamed the PR title to match the ability's actual name (core/users-query).

nikmclaughlin added a commit that referenced this pull request Oct 30, 2026
…lities from WordPress/ai PR #1105 (#9)

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

2 participants