From 96a1687b91462d36736508767307e51e03a44d80 Mon Sep 17 00:00:00 2001 From: Jb Audras Date: Wed, 9 Feb 2022 13:20:49 +0000 Subject: [PATCH] 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 #54844. git-svn-id: https://develop.svn.wordpress.org/trunk@52697 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/block-template.php | 4 ++++ tests/phpunit/tests/block-template.php | 1 + 2 files changed, 5 insertions(+) diff --git a/src/wp-includes/block-template.php b/src/wp-includes/block-template.php index de266c04f2..7bea75dca4 100644 --- a/src/wp-includes/block-template.php +++ b/src/wp-includes/block-template.php @@ -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. diff --git a/tests/phpunit/tests/block-template.php b/tests/phpunit/tests/block-template.php index 95dab825b9..7163fea70a 100644 --- a/tests/phpunit/tests/block-template.php +++ b/tests/phpunit/tests/block-template.php @@ -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() {