Skip to content

Abilities: Sync core/users-query with WordPress core - #1207

Merged
gziolo merged 2 commits into
developfrom
update/sync-users-query-with-core
Oct 26, 2026
Merged

gziolo merged 2 commits into
developfrom
update/sync-users-query-with-core

Conversation

@gziolo

@gziolo gziolo commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

What?

See #64657, r64346.

This PR syncs the core/users-query ability with the version that landed in WordPress core. The plugin acts as a polyfill until WordPress 7.2 is out. It also removes the deprecated core/read-users alias.

Why?

The ability was first built in this plugin (#774) and then moved to WordPress core. During the core review, the input and output shape changed a lot. The plugin should behave the same as core, so code written for the plugin keeps working on WordPress 7.2.

The old alias cannot keep the old contract after these changes, so it is removed. This is the same as what #1206 does for core/read-settings.

How?

The PR has two commits:

  1. Sync with core. includes/Abilities/Users/Users.php is now a copy of the core class WP_Abilities_Users. Each difference from core is marked with a // Plugin: comment: the init() method, unregistering the copy from core, an explicit show_in_rest, and the ai text domain.
  2. Remove the alias. core/read-users is no longer registered.

These are breaking changes for callers:

  • Input: it is now { where, fields, pagination }. where takes ids, slugs, usernames, roles, and has_published_posts. The old root-level id, email, username, slug, include, page, and per_page are removed. Lookup by email is no longer supported.
  • Output: it is always { items, pagination: { total, total_pages } }. A single user is no longer returned as a bare object.
  • Order: results are ordered by username, not by display name.
  • Errors: a filter that cannot be used is rejected, not ignored. A page after the last one returns a 404 error.
  • Permissions: filtering by username needs permission to list users.
  • Label: the label is now "Query Users".

Tests:

  • UsersTest.php is ported from the core test wpRegisterCoreUsersAbility.php. It also keeps two tests that only the plugin needs.
  • Users_RestTest.php is new. It is ported from the core test wpRestAbilitiesUsersController.php and runs the ability through the REST run endpoint.
  • The e2e spec now uses the new input and output.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Comparing the core commit with the plugin, porting the code and tests, updating the e2e spec, and running the checks. I reviewed the diff and the test results.

Testing Instructions

  1. Run npm run test:php -- --filter Users.
  2. Run the multisite tests: npx wp-env --config=.wp-env.test.json run cli --env-cwd=wp-content/plugins/ai bash -c "WP_MULTISITE=1 vendor/bin/phpunit -c phpunit.xml.dist --filter Users".
  3. Reactivate the plugin with npx wp-env --config=.wp-env.test.json run cli wp plugin activate ai. Then run npx wp-scripts test-playwright --config tests/e2e/playwright.config.ts tests/e2e/specs/abilities/core-users-query.spec.js.
  4. Manual check: enable the Custom Abilities experiment. Then run core/users-query with { "where": { "roles": [ "administrator" ] }, "fields": [ "id", "name" ] } and check that the result has items and pagination.

Changelog Entry

Changed - The core/users-query ability now matches WordPress core. The input is now where, fields, and pagination, and the output is always items and pagination. Users are looked up through the ids, slugs, or usernames lists in where, and lookup by email is no longer supported. Results are ordered by username, a filter that cannot be used is rejected, and a page after the last one returns an error.

Removed - The deprecated core/read-users ability alias. Use core/users-query with the new where, fields, and pagination input. The alias could not keep the old input and response shape after the sync with WordPress core.

🤖 Generated with Claude Code

Open WordPress Playground Preview

Apply the changes that shipped with the `core/users-query` ability in
WordPress core (r64346, Trac #64657):

- The input has three members: `where` selects the users, `fields` the
  fields returned for each user, and `pagination` the page.
- `where` filters by `ids`, `slugs`, `usernames`, `roles`, or
  `has_published_posts`. The single-user lookups by `id`, `email`,
  `username`, and `slug` are removed.
- The output always holds the users in `items` and the totals in
  `pagination`. Results are ordered by username.
- Filters that cannot be honored are rejected instead of dropped, and a
  page past the last one returns a 404 error.
- Filtering by username requires permission to list users.
- The REST run endpoint tests from core are ported as well.
The `core/read-users` alias can no longer keep the old input and output
contract after syncing `core/users-query` with WordPress core, so it is
removed. Use `core/users-query` with the new `where`, `fields`, and
`pagination` input instead.
@gziolo
gziolo requested a review from a team October 19, 2026 09:59
@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: gziolo <gziolo@git.wordpress.org>
Co-authored-by: dkotter <dkotter@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@gziolo gziolo self-assigned this Oct 19, 2026
@codecov

codecov Bot commented Oct 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.24%. Comparing base (a0b5dd5) to head (d5ad0be).

Additional details and impacted files
@@              Coverage Diff              @@
##             develop    #1207      +/-   ##
=============================================
+ Coverage      84.18%   84.24%   +0.05%     
+ Complexity      3516     3497      -19     
=============================================
  Files            139      139              
  Lines          13484    13440      -44     
=============================================
- Hits           11351    11322      -29     
+ Misses          2133     2118      -15     
Flag Coverage Δ
unit 84.24% <100.00%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

Copy link
Copy Markdown

✅ WordPress Plugin Check Report

✅ Status: Passed

📊 Report

All checks passed! No errors or warnings found.


🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants