Skip to content

Abilities API: Unify schema conventions across core abilities#11984

Open
gziolo wants to merge 8 commits into
WordPress:trunkfrom
gziolo:enhance/unify-core-abilities-schemas
Open

Abilities API: Unify schema conventions across core abilities#11984
gziolo wants to merge 8 commits into
WordPress:trunkfrom
gziolo:enhance/unify-core-abilities-schemas

Conversation

@gziolo
Copy link
Copy Markdown
Member

@gziolo gziolo commented May 27, 2026

Summary

The three core abilities shipped in 6.9.0 (core/get-site-info, core/get-user-info, core/get-environment-info) drifted in small but visible ways. This PR aligns them on a shared blueprint so they're predictable to consume from REST clients and easier to extend.

  • Every output property declares both title and description, reusing existing WP Admin translations where possible.
  • core/get-environment-info accepts the optional fields input parameter already supported by the other two, with an enum of valid keys.
  • core/get-user-info is exposed via REST (show_in_rest => true) so clients can discover and invoke it under /wp-json/wp-abilities/v1/abilities.
  • Property titles are normalized to Title Case. db_server_info is relabeled Database Server Info since $wpdb->db_server_info() returns vendor+version, not just a version.
  • Schema descriptions are tightened for programmatic consumers: redundant restatement of title/type is removed, the environment description no longer repeats the enum, and the url/wpurl and site-language/user-locale pairs are explicitly contrasted so an AI client can pick the right field and format.
  • Registration tests lock the exact ordered set of property keys on both the input enum and the output properties, so any future field addition forces a test update.

Trac ticket: https://core.trac.wordpress.org/ticket/65355

Test plan

  • npm run test:php -- --filter=Tests_Abilities_API_WpRegisterCoreAbilities is green
  • core/get-user-info is listed at /wp-json/wp-abilities/v1/abilities for an authenticated user
  • core/get-environment-info accepts {"fields":["php_version"]} and returns only that key
  • Unknown field names on any of the three abilities yield an ability_invalid_input error
  • npm run env:composer -- lint -- src/wp-includes/abilities.php reports no violations
  • npm run typecheck:php passes

🤖 Generated with Claude Code

gziolo and others added 4 commits May 27, 2026 10:24
…ore/get-environment-info.

Aligns both abilities with the pattern already used by `core/get-user-info` by adding a `title` to every output schema property. Titles reuse existing WP Admin translations (e.g. 'Site Title', 'WordPress Address (URL)', 'PHP Version') so clients can display human-friendly labels without introducing new strings.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…elds.

Adds the same `fields` input parameter that `core/get-site-info` and `core/get-user-info` accept, so clients can request a subset of the environment payload (e.g. just `php_version`) instead of always receiving all four properties. Unknown field names are rejected by the input schema's enum, matching the existing pattern.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Flips `meta.show_in_rest` to `true` so `core/get-user-info` appears under `wp-abilities/v1/abilities` and can be invoked by REST clients, matching `core/get-site-info` and `core/get-environment-info`. The existing `is_user_logged_in()` permission callback continues to gate access; only the discoverability and REST invocation paths change.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ts in tests.

Switches the three remaining sentence-case property titles to Title Case so all schema titles across the core abilities follow the same convention: 'Site Charset' (was 'Encoding for pages and feeds'), 'Environment Type' (was 'Environment type'), and 'Database Server Info' (was 'Database Server version' — the new label is also more accurate, since `$wpdb->db_server_info()` returns a vendor+version string, not just a version). Also aligns the `version` description in `core/get-site-info` with the equivalent `wp_version` description in `core/get-environment-info`.

Tightens the registration tests for all three abilities to assert the exact ordered set of fields on both the input enum and the output property keys, so adding a new property to any ability now forces a test update.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions
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.

Core Committers: Use this line as a base for the props when committing in SVN:

Props gziolo.

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

'title' => __( 'Database Server Info' ),
'description' => __( 'The database server vendor and version string reported by the driver.' ),
),
'wp_version' => array(
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out that the WordPress version is included in two site abilities. I’ve aligned the title and description to reflect this.

@github-actions
Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Trims descriptions that only restated the title or duplicated information already encoded in `type`/`enum`, and tightens the few descriptions where a programmatic consumer (e.g. an LLM invoking the ability via REST) actually needs disambiguation:

- `environment`: drops the enum re-listing now that the values live in `enum` only.
- `url` / `wpurl`: each description now explicitly contrasts with the other, since both fields can carry the same value.
- `language` (site-info): notes the dash form (en-US), which differs from `locale` in user-info (en_US).
- `id` (user-info): removes "numeric", already implied by `type: integer`.
- `description` (user-info): drops the author-page UI reference and notes the empty-string case instead.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@gziolo gziolo self-assigned this May 27, 2026
gziolo and others added 3 commits May 27, 2026 11:06
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…n tests.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…sts.

The three tests added in this branch covered behavior introduced under ticket 65355, not 65234.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.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.

1 participant