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
This commit is contained in:
spacedmonkey 2023-06-27 10:15:28 +00:00
parent fbbe0f0a76
commit aa404f099e
2 changed files with 3 additions and 17 deletions

View File

@ -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' );
}
}

View File

@ -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.