-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix template resolution to give precedence to child theme PHP templates over parent theme block templates with equal specificity #1961
Fix template resolution to give precedence to child theme PHP templates over parent theme block templates with equal specificity #1961
Conversation
My current approach would change the semantics of |
Potential TODO: Merge the logic from |
…it takes precedence over a block template
* } | ||
* @param array $template_type wp_template or wp_template_part. | ||
* | ||
* @return array Templates. | ||
*/ | ||
function get_block_templates( $query = array(), $template_type = 'wp_template' ) { | ||
function get_block_templates( $query = array(), $template_type = 'wp_template', $child_theme_fallback_php_template = null ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like how I had to change the function signature of get_block_templates()
-- which is, after all, supposed to be a general-purpose function to get all templates for a given theme (DB or file-based).
I'll try a different approach (where the filtering will hopefully happen in a later stage, i.e. in resolve_block_template
-- even though that'll require some redundant checks) in a separate PR.
Closing in favor of #1985. |
WIP. Description of the issue (as found in the corresponding Trac ticket) below:
When a theme has a PHP template of a certain specificity (e.g.
page-home.php
), and it happens to be a child theme of another theme which has a block template for the same specificity (e.g.page-home.html
), WordPress will currently pick the parent theme’s block template over the child theme's PHP template to render the page.This is a regression. If the PHP and block template have equal specificity, the child theme's template should be used. This issue was fixed before in WordPress/gutenberg#31123. The relevant logic has since been modified and eventually backported to Core , so the fix now needs to happen in Core (plus GB's pre-WP-5.9 compat layer, but that's somewhat secondary).
We have a unit test for this (but obviously had to disable it). The unit test existed in Gutenberg before but didn’t fail there due to a faulty test setup. In fact, the issue was only found while backporting the unit test.
Trac ticket: https://core.trac.wordpress.org/ticket/54515
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.