From 01888354843b0ec37246f99e2124b19a4c26176f Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 22 Mar 2021 18:55:35 +0200 Subject: [PATCH] First step towards hybrid themes: Fallback to PHP templates (#29026) * Allow falling back to php templates * inline doc * Massaging var names - pros @draganescu * Run phpcbf to fix PHP CS issues * CS fix * full-stop --- lib/full-site-editing/template-loader.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/full-site-editing/template-loader.php b/lib/full-site-editing/template-loader.php index e0047b81c21f1c..f90f07c02fff55 100644 --- a/lib/full-site-editing/template-loader.php +++ b/lib/full-site-editing/template-loader.php @@ -65,6 +65,19 @@ function gutenberg_override_query_template( $template, $type, array $templates = global $_wp_current_template_content; $current_template = gutenberg_resolve_template( $type, $templates ); + // Allow falling back to a PHP template if it has a higher priority than the block template. + $current_template_slug = basename( $template, '.php' ); + $current_block_template_slug = is_object( $current_template ) ? $current_template->slug : false; + foreach ( $templates as $template_item ) { + $template_item_slug = gutenberg_strip_php_suffix( $template_item ); + + // Don't override the template if we find a template matching the slug we look for + // and which does not match a block template slug. + if ( $current_template_slug !== $current_block_template_slug && $current_template_slug === $template_item_slug ) { + return $template; + } + } + if ( $current_template ) { $_wp_current_template_content = empty( $current_template->content ) ? __( 'Empty template.', 'gutenberg' ) : $current_template->content;