From aa404f099e92222643502db4bf249874bff3193e Mon Sep 17 00:00:00 2001 From: spacedmonkey Date: Tue, 27 Jun 2023 10:15:28 +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. Built from https://develop.svn.wordpress.org/trunk@56060 git-svn-id: http://core.svn.wordpress.org/trunk@55572 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/block-template.php | 18 ++---------------- wp-includes/version.php | 2 +- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/wp-includes/block-template.php b/wp-includes/block-template.php index b3b1eecd49..728523e586 100644 --- a/wp-includes/block-template.php +++ b/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' ); } } diff --git a/wp-includes/version.php b/wp-includes/version.php index 0a1e2e9bbb..6da1fe461f 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.3-alpha-56059'; +$wp_version = '6.3-alpha-56060'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.