Make WordPress Core

Changeset 56060

Timestamp:
06/27/2023 10:13:07 AM (14 months ago)
Author:
spacedmonkey
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-template.php

    r55988 r56060  
    77
    88/**
    9  * Adds necessary filters to use 'wp_template' posts instead of theme template files.
     9 * Adds necessary s.
    1010 *
    1111 * @access private
     
    1313 */
    1414function _add_template_loader_filters() {
    15     if ( ! current_theme_supports( 'block-templates' ) ) {
    16         return;
    17     }
    18 
    19     $template_types = array_keys( get_default_block_template_types() );
    20     foreach ( $template_types as $template_type ) {
    21         // Skip 'embed' for now because it is not a regular template type.
    22         if ( 'embed' === $template_type ) {
    23             continue;
    24         }
    25         add_filter( str_replace( '-', '', $template_type ) . '_template', 'locate_block_template', 20, 3 );
    26     }
    27 
    28     // Request to resolve a template.
    29     if ( isset( $_GET['_wp-find-template'] ) ) {
     15    if ( isset( $_GET['_wp-find-template'] ) && current_theme_supports( 'block-templates' ) ) {
    3016        add_action( 'pre_get_posts', '_resolve_template_for_new_post' );
    3117    }
Note: See TracChangeset for help on using the changeset viewer.