Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First step towards hybrid themes: Fallback to PHP templates #29026

Merged
merged 10 commits into from
Mar 22, 2021
13 changes: 13 additions & 0 deletions lib/full-site-editing/template-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

aristath marked this conversation as resolved.
Show resolved Hide resolved
if ( $current_template ) {
$_wp_current_template_content = empty( $current_template->content ) ? __( 'Empty template.', 'gutenberg' ) : $current_template->content;

Expand Down