Skip to content

Commit

Permalink
Query: Check if the theme supports block-templates before calling `…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
audrasjb committed Feb 9, 2022
1 parent 89bcc48 commit 96a1687
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/wp-includes/block-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions tests/phpunit/tests/block-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 96a1687

Please sign in to comment.