Skip to content

Commit

Permalink
First step towards hybrid themes: Fallback to PHP templates (#29026)
Browse files Browse the repository at this point in the history
* Allow falling back to php templates

* inline doc

* Massaging var names - pros @draganescu

* Run phpcbf to fix PHP CS issues

* CS fix

* full-stop
aristath authored Mar 22, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 2e4a284 commit 0188835
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/full-site-editing/template-loader.php
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 0188835

Please sign in to comment.