Repository navigation
Add Ability: core/get-active-theme - #2
Open
matiasbenedetto wants to merge 1 commit into
Open
matiasbenedetto wants to merge 1 commit into
matiasbenedetto wants to merge 1 commit into
Conversation
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.
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
This was referenced May 26, 2026
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 a new core ability
core/get-active-themeto 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
fieldsarray 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?
core/get-active-themewithwp_register_ability()under thesitecategory.permission_callback:current_user_can( 'switch_themes' ).execute_callback: callswp_get_theme()and projects through the shared$prepare_theme_datahelper.meta.annotations:readonly: true,destructive: false,idempotent: true.meta.show_in_rest:trueso the ability is reachable via the Abilities REST namespace.$theme_properties/$theme_fields/$prepare_theme_dataonce 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 afieldsprojection (subset).test_core_get_active_theme_requires_switch_themes— runs the ability as a subscriber and asserts aability_invalid_permissionsWP_Error.Run only this PR's tests:
Result on this branch:
Abilities Explorer
The new Abilities Explorer experiment shipped with the WordPress AI plugin can also be used to exercise this ability interactively:
trunkand activate it.core/get-active-themein thesitecategory.{ "fields": ["stylesheet", "name", "version"] }.Testing evidence
Invoking the ability via
wp eval-fileagainst 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):Stacked PRs
This PR is the base of a 4-PR stack that ships the theme abilities:
core/get-active-themecore/get-theme-info— Add Ability: core/get-theme-info #3core/get-themes— Add Ability: core/get-themes #4core/activate-theme— Add Ability: core/activate-theme #5