get_block_templates(): Fix non-sequential array keys for registry-only template matches#12557
Draft
im3dabasia wants to merge 2 commits into
Draft
get_block_templates(): Fix non-sequential array keys for registry-only template matches#12557im3dabasia wants to merge 2 commits into
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. |
6 tasks
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.
Trac ticket:
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