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
11 changes: 11 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,17 @@ 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_legacy_template = basename( $template, '.php' );
$block_template_slug = is_object( $current_template ) ? $current_template->slug : false;
foreach ( $templates as $item ) {
$legacy_slug = gutenberg_strip_php_suffix( $item );

if ( $block_template_slug !== $current_legacy_template && $legacy_slug === $current_legacy_template ) {
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