Query: Check if the theme supports block-templates before calling locate_block_template() in get_query_template().

This change improves performance for classic themes by removing an unnecessary query and fixes an issue where a classic theme would show "Empty template: Index" on the frontend when an empty `(block-)templates/index.html` file exists.

Props johnbillion, ianatkins, Mamaduka, costdev, manfcarlo, dolphingg, audrasjb, madeinua, kapilpaul, rafiahmedd, SergeyBiryukov.
Fixes .


git-svn-id: https://develop.svn.wordpress.org/trunk@52697 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jb Audras 2022-02-09 13:20:49 +00:00
parent 89bcc4843a
commit 96a1687b91
2 changed files with 5 additions and 0 deletions
src/wp-includes
tests/phpunit/tests

@ -48,6 +48,10 @@ function _add_template_loader_filters() {
function locate_block_template( $template, $type, array $templates ) {
global $_wp_current_template_content;
if ( ! current_theme_supports( 'block-templates' ) ) {
return $template;
}
if ( $template ) {
/*
* locate_template() has found a PHP template at the path specified by $template.

@ -18,6 +18,7 @@ class Tests_Block_Template extends WP_UnitTestCase {
public function set_up() {
parent::set_up();
switch_theme( 'block-theme' );
do_action( 'setup_theme' );
}
public function tear_down() {