Skip to content

Commit

Permalink
Template Loader: Optimizations.
Browse files Browse the repository at this point in the history
  • Loading branch information
epiqueras committed Nov 4, 2019
1 parent 36a8cf3 commit 2cc7330
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/template-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,16 @@ function gutenberg_find_template( $template_file ) {
$current_template_post = array_shift( $template_posts );

// Build map of template slugs to their priority in the current hierarchy.
$slug_priorities = array();
foreach ( $slugs as $index => $slug ) {
$slug_priorities[ $slug ] = $index;
}
$slug_priorities = array_flip( $slugs );

// See if there is a theme block template with higher priority than the resolved template post.
$higher_priority_block_template_path = null;
$higher_priority_block_template_priority = PHP_INT_MAX;
foreach ( array_unique( array_merge( glob( get_stylesheet_directory() . '/block-templates/*.html', 1 ), glob( get_template_directory() . '/block-templates/*.html', 1 ) ) ) as $path ) {
$block_template_files = glob( get_stylesheet_directory() . '/block-templates/*.html', 1 );
if ( is_child_theme() ) {
$block_template_files = array_merge( $block_template_files, glob( get_template_directory() . '/block-templates/*.html', 1 ) );
}
foreach ( $block_template_files as $path ) {
$theme_block_template_priority = $slug_priorities[ basename( $path, '.html' ) ];
if (
isset( $theme_block_template_priority ) &&
Expand All @@ -131,7 +132,7 @@ function gutenberg_find_template( $template_file ) {

// If there is, use it instead.
if ( isset( $higher_priority_block_template_path ) ) {
$post_name = basename( $path, '.html' );
$post_name = basename( $path, '.html' );
$current_template_post = array(
'post_content' => file_get_contents( $higher_priority_block_template_path ),
'post_title' => ucfirst( $post_name ),
Expand Down

0 comments on commit 2cc7330

Please sign in to comment.