Opened 3 weeks ago
Last modified 3 weeks ago
#59315 new defect (bug)
Merge consideration of block-templates with classic template hierarchy
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | |
Component: | Themes | Keywords: | needs-patch |
Focuses: | performance | Cc: |
Description
For block themes, WordPress will first attempt to locate the appropriate PHP template in the theme for the request before considering a block template in get_query_template
. However, any block template that is found at an equal or higher priority takes precedence over the PHP templates. This means that block themes perform several unnecessary file_exists
checks to look for a PHP template, when a block template is the desired result.
Design considerations
To fix this, the logic from locate_block_template
that attempts to find an appropriate block template would need to be integrated into the foreach loop in locate_template
so that the appropriate block template would be found prior to searching for a PHP template, in get_query_template
if current_theme_supports( 'block-templates' )
returns true. Alternatively, the order of those two functions could be reversed so that locate_block_template is called first if the theme supports block templates.
Benefits
The benefit to this approach is that wasteful file operations would not be called if a more appropriate block template is available, speeding up template rendering. For example, when a block theme responds to a standard single post, locate_template
will end up calling file_exists
9 times before even considering whether an appropriate block template exists.
Caveats and risks
While file_exists
checks have been shown to have a noticeable performance cost in lab profiling, the results of these calls are often cached internally by PHP (see: https://www.php.net/manual/en/function.clearstatcache.php), so the performance impact in the field may be negligible.
Additionally, there are backwards compatibility considerations that will need to be accounted for with this implementation, as plugins are already making use of direct calls to locate_template
and locate_block_template
independently of how they’re used in get_query_template
.
Moving this to Future Release, since we're so close to the 6.4 beta release.