From 02ea2f1d75a77d014708fd0d38677e85065742e9 Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Tue, 27 Jun 2023 10:13:07 +0000 Subject: [PATCH] Themes: Block template is located twice in `get_query_template()`. When the function `_template_loader_filters` was ported to core from gutenberg, it retained the filter to load block templates. However, the function `locate_block_template` is called manually in `get_query_template`, so this filter is not needed. Calling `locate_block_template` twice, results in performance issue, as `locate_block_template` is a expensive function to run, as it does database and file lookups. Props dlh, mukesh27, flixos90, SergeyBiryukov, bernhard-reiter, spacedmonkey. Fixes #58299. git-svn-id: https://develop.svn.wordpress.org/trunk@56060 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/block-template.php | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/src/wp-includes/block-template.php b/src/wp-includes/block-template.php index b3b1eecd49..728523e586 100644 --- a/src/wp-includes/block-template.php +++ b/src/wp-includes/block-template.php @@ -6,27 +6,13 @@ */ /** - * Adds necessary filters to use 'wp_template' posts instead of theme template files. + * Adds necessary hooks to resolve '_wp-find-template' requests. * * @access private * @since 5.9.0 */ function _add_template_loader_filters() { - if ( ! current_theme_supports( 'block-templates' ) ) { - return; - } - - $template_types = array_keys( get_default_block_template_types() ); - foreach ( $template_types as $template_type ) { - // Skip 'embed' for now because it is not a regular template type. - if ( 'embed' === $template_type ) { - continue; - } - add_filter( str_replace( '-', '', $template_type ) . '_template', 'locate_block_template', 20, 3 ); - } - - // Request to resolve a template. - if ( isset( $_GET['_wp-find-template'] ) ) { + if ( isset( $_GET['_wp-find-template'] ) && current_theme_supports( 'block-templates' ) ) { add_action( 'pre_get_posts', '_resolve_template_for_new_post' ); } }