Skip to content

Add Ability: core/get-active-theme - #2

Open
matiasbenedetto wants to merge 1 commit into
pr-base/theme-abilitiesfrom
add/ability-get-active-theme
Open

matiasbenedetto wants to merge 1 commit into
pr-base/theme-abilitiesfrom
add/ability-get-active-theme

Conversation

@matiasbenedetto

@matiasbenedetto matiasbenedetto commented May 26, 2026 •

Copy link
Copy Markdown
Owner

What?

Adds a new core ability core/get-active-theme to the Abilities API.

The ability returns information about the currently active theme. By default it returns a full set of fields (stylesheet, template, name, version, description, author, author_uri, theme_uri, status, parent, screenshot, tags, requires_wp, requires_php, text_domain); callers can pass an optional fields array to project to a subset.

This PR also introduces shared theme schema helpers ($theme_properties, $theme_fields, $prepare_theme_data) that are reused by the follow-up theme abilities in this stack.

Why?

The Abilities API is the surface AI assistants and other automations use to inspect and operate on a WordPress site. Knowing which theme is currently active is a foundational read-only signal: it lets a model describe the site, decide whether a feature is supported (block themes vs classic themes, child themes, required PHP/WP versions, etc.), and reason about subsequent actions before performing them.

A dedicated, schema-driven ability gives that signal a stable, typed contract — instead of relying on REST endpoints with broader payloads or on raw wp_get_theme() access.

How?

  • Registers core/get-active-theme with wp_register_ability() under the site category.
  • permission_callback: current_user_can( 'switch_themes' ).
  • execute_callback: calls wp_get_theme() and projects through the shared $prepare_theme_data helper.
  • meta.annotations: readonly: true, destructive: false, idempotent: true.
  • meta.show_in_rest: true so the ability is reachable via the Abilities REST namespace.
  • Defines $theme_properties / $theme_fields / $prepare_theme_data once at the top of the theme-abilities block so the follow-up PRs (core/get-theme-info, core/get-themes, core/activate-theme) reuse the same schema and projection logic.

How to test

PHPUnit

The PR adds 3 new tests in tests/phpunit/tests/abilities-api/wpRegisterCoreAbilities.php:

  • test_core_get_active_theme_ability_is_registered — verifies the ability is registered, exposed in REST, and that its input/output schemas declare every documented field.
  • test_core_get_active_theme_executes — runs the ability as an administrator with no input (full payload) and with a fields projection (subset).
  • test_core_get_active_theme_requires_switch_themes — runs the ability as a subscriber and asserts a ability_invalid_permissions WP_Error.

Run only this PR's tests:

npm run test:php -- --filter core_get_active_theme tests/phpunit/tests/abilities-api/wpRegisterCoreAbilities.php

Result on this branch:

OK (13 tests, 121 assertions)

Abilities Explorer

The new Abilities Explorer experiment shipped with the WordPress AI plugin can also be used to exercise this ability interactively:

  1. Install the WordPress AI plugin from trunk and activate it.
  2. Open the Abilities Explorer experiment from the plugin UI.
  3. Find core/get-active-theme in the site category.
  4. Run it with no input, then with { "fields": ["stylesheet", "name", "version"] }.

Testing evidence

Invoking the ability via wp eval-file against the dev-env:

Input (no arguments):

{}

Output:

{
    "stylesheet": "twentytwentyfive",
    "template": "twentytwentyfive",
    "name": "Twenty Twenty-Five",
    "version": "1.5",
    "description": "Twenty Twenty-Five emphasizes simplicity and adaptability. ...",
    "author": "the WordPress team",
    "author_uri": "https://wordpress.org",
    "theme_uri": "https://wordpress.org/themes/twentytwentyfive/",
    "status": "active",
    "parent": null,
    "screenshot": "http://localhost:8889/wp-content/themes/twentytwentyfive/screenshot.png",
    "tags": ["one-column", "custom-colors", "...", "news"],
    "requires_wp": "6.7",
    "requires_php": "7.2",
    "text_domain": "twentytwentyfive"
}

Input (field projection):

{ "fields": ["stylesheet", "name", "version"] }

Output:

{
    "stylesheet": "twentytwentyfive",
    "name": "Twenty Twenty-Five",
    "version": "1.5"
}

Input (called as a subscriber, no capability):

{}

Output (WP_Error):

code:    ability_invalid_permissions
message: Ability "core/get-active-theme" does not have necessary permission.

Stacked PRs

This PR is the base of a 4-PR stack that ships the theme abilities:

  1. This PR — Add Ability: core/get-active-theme
  2. Add Ability: core/get-theme-info — Add Ability: core/get-theme-info #3
  3. Add Ability: core/get-themes — Add Ability: core/get-themes #4
  4. Add Ability: core/activate-theme — Add Ability: core/activate-theme #5

Introduces shared theme schema helpers ($theme_properties / $theme_fields
/ $prepare_theme_data) and registers the read-only core/get-active-theme
ability, which returns information about the currently active theme.

Supports an optional 'fields' input to limit the response to a subset of
fields. Requires the 'switch_themes' capability and is exposed via REST.

Includes PHPUnit tests covering schema shape, default + filtered field
execution, and the capability check.
@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 mmaattiiaass.

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

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