Repository navigation
get_block_templates(): Fix non-sequential array keys for registry-only template matches - #12557
im3dabasia wants to merge 2 commits into
Conversation
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
|
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. |
Trac ticket: https://core.trac.wordpress.org/ticket/65689
What Why How
get_block_templates() returns an array whose keys are not sequential when the only matching template comes from the plugin template registry (WP_Block_Templates_Registry), which stores templates keyed by name. When no wp_template post or theme file also matches,
array_merge()carries those string keys straight into the result with no numeric0index.This breaks callers that assume a plain list, e.g. wp_get_post_content_block_attributes() in
block-editor.php, which accesses$templates[0]. Reproduced in WordPress/gutenberg#80291 : assigning a plugin-registered template to a post and opening it in the editor triggers PHP warnings and deprecation notices.Two tests added:
get_block_templates()returns a sequentially indexed array when the registry is the sole match.Before
Both the tests I added were failing locally.
After
Use of AI Tools
AI assistance: Yes
Tool(s): Claude
Model(s): Claude Sonnet 4.5