johnbillion / query-monitor

The developer tools panel for WordPress
https://querymonitor.com
GNU General Public License v2.0
1.6k stars 211 forks source link

The method wp_resolve_block_template results in more database queries #763

Closed spacedmonkey closed 1 year ago

spacedmonkey commented 1 year ago

The method wp_resolve_block_template, results in database queries that are reported, even on theme that do not support block templates.

Screenshot 2023-05-05 at 11 18 38

Something like this might fix the issue.

protected static function wp_resolve_block_template( $template_type, $template_hierarchy, $fallback_template ) {
        if ( ! function_exists( 'resolve_block_template' ) ) {
            return null;
        }

                if ( ! current_theme_supports( 'block-templates' ) ) {
            return null;
            }

        return resolve_block_template( $template_type, $template_hierarchy, $fallback_template );
    }
johnbillion commented 1 year ago

Looks like current_theme_supports( 'block-templates' ) is indeed what we want, thanks. Fixed in 6b678fd.