Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions lib/full-site-editing/template-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function get_template_hierarchy( $template_type ) {
* @param array $templates A list of template candidates, in descending order of priority.
* @return string The path to the Full Site Editing template canvas file.
*/
function gutenberg_override_query_template( $template, $type, array $templates = array() ) {
function gutenberg_override_query_template( $template, $type, array $templates ) {
global $_wp_current_template_content;
$current_template = gutenberg_resolve_template( $type, $templates );

Expand Down Expand Up @@ -163,17 +163,13 @@ function gutenberg_override_query_template( $template, $type, array $templates =
* @type int[] A list of template parts IDs for the template.
* }
*/
function gutenberg_resolve_template( $template_type, $template_hierarchy = array() ) {
function gutenberg_resolve_template( $template_type, $template_hierarchy ) {
if ( ! $template_type ) {
return null;
}

if ( empty( $template_hierarchy ) ) {
if ( 'index' === $template_type ) {
$template_hierarchy = get_template_hierarchy( 'index' );
} else {
$template_hierarchy = array_merge( get_template_hierarchy( $template_type ), get_template_hierarchy( 'index' ) );
}
$template_hierarchy = array( $template_type );
}

$slugs = array_map(
Expand Down
8 changes: 8 additions & 0 deletions phpunit/class-template-loader-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,14 @@ function test_gutenberg_custom_page_block_template_takes_precedence_over_all_oth
$this->assertEquals( self::$post->post_content, $_wp_current_template_content );
}

/**
* Regression: https://github.com/WordPress/gutenberg/issues/31652.
*/
function test_gutenberg_template_remains_unchanged_if_templates_array_is_empty() {
$resolved_template_path = gutenberg_override_query_template( '', 'search', array() );
$this->assertEquals( '', $resolved_template_path );
}

static function change_theme_directory( $theme_dir, $theme ) {
return __DIR__ . '/fixtures/themes/' . $theme;
}
Expand Down