Repository navigation
Conversation
Adds a read-only ability that reports whether the active theme is a block theme, its name, and the block templates the site has for it. Each template has its slug, title, source (theme, custom or plugin) and whether the theme ships it as a file, so an agent can check what it may change before it proposes a template. The ability is gated behind the Custom Abilities experiment, requires `edit_theme_options`, is public, and stands down when the ability is already registered. Templates are sorted by slug. Template parts are not included. Fixes WordPress#1303.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1309 +/- ##
=============================================
+ Coverage 85.03% 85.11% +0.08%
- Complexity 4832 4843 +11
=============================================
Files 190 192 +2
Lines 17950 18051 +101
=============================================
+ Hits 15263 15364 +101
Misses 2687 2687
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Member
|
@yaman-694 would you mind porting this over to https://github.com/WordPress/abilities? |
Author
|
Sure @jeffpaul I will work on that. |
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?
Closes #1303
Adds
core/templates-query, a read-only ability that reports whether the active theme is a block theme, its name, and the block templates the site has for it.Why?
An agent that wants to change how a page looks needs to know first whether the theme supports block templates, which templates exist, and which ones a user has already edited.
Today the only way to find out is to try, as the AI Workspace's template proposals (#1298) do with their own
wp_is_block_theme()andget_block_template()checks.This ability lets any consumer (the workspace, MCP clients, other plugins) ask first.
How?
The ability follows how the plugin registers
core/content-queryandcore/settings-get:includes/Abilities/Templates/Templates.phpregisters the ability onwp_abilities_api_initat priority 11, and stands down when an ability with the same name is already registered.includes/Abilities/Gated/Templates_Query.phpgates it behind the Custom Abilities experiment, and it is added toGated_Abilities.{ "block_theme": true, "theme": "Twenty Twenty-Five", "templates": [ { "slug": "404", "title": "Page: 404", "source": "theme", "has_theme_file": true }, { "slug": "single", "title": "Single Posts", "source": "custom", "has_theme_file": true } ] }get_block_templates(), so they match what the Site Editor shows: theme files (theme), templates a user created or edited (custom), and templates a plugin registered (plugin).has_theme_filetells an edited theme template (which Reset can bring back) from one a user created.get_block_templates()lists edited templates before theme files.edit_theme_options, the capability the Site Editor needs, and is annotated read-only, non-destructive and idempotent.It is marked
publicandshow_in_rest, so it is available over REST and, through the MCP Adapter, over MCP.sourceis a string, not an enum: it comes from core and from filters, and an unexpected value should not fail the whole response.propertieskey: PHP encodes an empty array as the JSON array[], which the JSON Schema validator in@wordpress/abilitiesrejects before the ability runs.A test pins this.
Decisions to confirm
These follow the questions on #1303; happy to change any of them:
wp_templateis listed, not template parts (wp_template_part).public, like the othercore/*abilities.core/templates-query, as proposed in the issue.Use of AI Tools
Testing Instructions
core/templates-querywith{}.block_theme: trueand the theme's templates withsource: "theme".source: "custom"andhas_theme_file: true.source: "custom"andhas_theme_file: false.block_themeisfalseandtemplatesis empty.Automated tests:
npm run test:php -- --filter 'TemplatesTest|Gated_AbilitiesTest'(13 new tests, using a block and a classic fixture theme intests/data/themes).npm run test:e2e -- tests/e2e/specs/abilities/core-templates-query.spec.js, which runs the ability through the client-side Abilities API.The ability was also run end to end over MCP through the MCP Adapter's default server, where it is listed by
mcp-adapter-discover-abilitiesand returns the site's templates throughmcp-adapter-execute-ability.Changelog Entry