Repository navigation
Conversation
Adds the read-only `wp/templates-query` ability. It reports whether the active theme is a block theme, its name, and its block templates sorted by slug, each with where it comes from and whether the theme ships it as a file. It requires `edit_theme_options`. The ability incubates under the experimental `wp/` prefix; the upstream `core/templates-query` name is not carried.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @nikolas4175-godaddy. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
|
Thanks @yaman-694 for putting this together! I'm working on an update following discussion in #18 to rename the experimental tier of abilities under the |
|
FYI: @yaman-694 Experimental tier now lives under the |
What?
Ports the read-only templates query ability from WordPress/ai#1309 into this package as
wp/templates-query, as requested in WordPress/ai#1309 (comment).The upstream PR closes WordPress/ai#1303.
The ability incubates under the experimental
wp/prefix (NAME-LIFECYCLE.md).The upstream
core/templates-queryname is not carried, and there is no alias.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.
How?
src/Templates/Templates_Query.phponAbstract_Core_Ability.It takes no input (an empty object is accepted) and returns
{ block_theme, theme, templates }.get_block_templates()(wp_templateonly, not template parts), so they match what the Site Editor shows.Each has
slug,title,source(theme,customorplugin) andhas_theme_file, which tells an edited theme template from one a user created.They are sorted by slug, because
get_block_templates()lists edited templates before theme files.sourceis an open string, not an enum: it comes from core and from filters, and an unexpected value should not fail the whole response.propertieskey, because PHP encodes it as the JSON array[], which the@wordpress/abilitiesvalidator rejects before the ability runs.A test pins this.
required_capabilitiesisedit_theme_options, the capability the Site Editor needs, with no permission callback.readonly: true,destructive: false,idempotent: trueandopen_world: false, plusshow_in_rest: trueandmcp.public: true, as on the otherwp/read abilities.experimental, categorysite,core_since: null, andproposalpointing to the upstream PR.Differences from the upstream PR
Only the name, the
open_world: falseannotation, andmcp.publicin place ofpublic.On a local site I loaded the upstream class next to the port and compared them:
label, description, category, both schemas, permissions and output were identical for administrator, editor, subscriber and logged-out users, for no input,
{}, unknown keys and non-object input, on a block theme with theme, edited and user-created templates and on a classic theme.Over the REST run route and the MCP adapter, the responses differ only by the ability name inside error messages.
Use of AI tools
Testing Instructions
WordPress\Abilities\Registrar::register_all();(for example withtools/wordpress-abilities-bridge).wp/templates-query(GET /wp-json/wp-abilities/v1/abilities/wp/templates-query/run):block_themeistrueand the theme's templates havesource: "theme".source: "custom"andhas_theme_file: true.source: "custom"andhas_theme_file: false.block_themeisfalseandtemplatesis empty.Automated:
tests/Abilities/TemplatesQueryTest.php: 13 tests, using a block and a classic fixture theme intests/Fixtures/themes.The one warning (
Abstract_Media_Write.php:977) and the skipped tests come from the existing media and settings tests.composer run lint:phpcs,composer run lint:phpstan,composer run verify:manifestandcomposer run verify:coreifypass.Changelog entry