From 953dfc113178605087222f038b401752e28b01af Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 16 Feb 2021 10:15:53 +0200 Subject: [PATCH 1/6] Allow falling back to php templates --- lib/full-site-editing/template-loader.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/full-site-editing/template-loader.php b/lib/full-site-editing/template-loader.php index e0047b81c21f1c..413cf81a0ed54c 100644 --- a/lib/full-site-editing/template-loader.php +++ b/lib/full-site-editing/template-loader.php @@ -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 ); + $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; + } + } + if ( $current_template ) { $_wp_current_template_content = empty( $current_template->content ) ? __( 'Empty template.', 'gutenberg' ) : $current_template->content; From d930f7d4439222286aa9aaf8636e2495d4770421 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 16 Feb 2021 10:17:53 +0200 Subject: [PATCH 2/6] inline doc --- lib/full-site-editing/template-loader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/full-site-editing/template-loader.php b/lib/full-site-editing/template-loader.php index 413cf81a0ed54c..bc143fac4526d7 100644 --- a/lib/full-site-editing/template-loader.php +++ b/lib/full-site-editing/template-loader.php @@ -65,9 +65,9 @@ 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 ); From 0878b04efbe1b6e5264d5e2649f9aa85dc6ec20b Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 26 Feb 2021 11:26:51 +0200 Subject: [PATCH 3/6] Massaging var names - pros @draganescu --- lib/full-site-editing/template-loader.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/full-site-editing/template-loader.php b/lib/full-site-editing/template-loader.php index bc143fac4526d7..1d70591f8d4e2c 100644 --- a/lib/full-site-editing/template-loader.php +++ b/lib/full-site-editing/template-loader.php @@ -66,12 +66,14 @@ function gutenberg_override_query_template( $template, $type, array $templates = $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 ) { + $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; } } From 5a0f1080896643dbd2e8a8be9ee6ebe62a9b0d0e Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 26 Feb 2021 11:38:36 +0200 Subject: [PATCH 4/6] Run phpcbf to fix PHP CS issues --- phpunit/class-gutenberg-utils-test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpunit/class-gutenberg-utils-test.php b/phpunit/class-gutenberg-utils-test.php index ed7e5ebea9fd6f..f683cbd6a64fda 100644 --- a/phpunit/class-gutenberg-utils-test.php +++ b/phpunit/class-gutenberg-utils-test.php @@ -134,7 +134,7 @@ public function test_invalid_parameters_set() { public function test_gutenberg_get_minified_styles() { $cases = array( array( - 'in' => ' + 'in' => ' /** * Comment */ @@ -145,7 +145,7 @@ public function test_gutenberg_get_minified_styles() { 'out' => '.foo{bar:1}', ), array( - 'in' => '/* Comment */#foo{content:" "; bar: 0; + 'in' => '/* Comment */#foo{content:" "; bar: 0; }', 'out' => '#foo{content:" ";bar:0}', ), From 1fe8fcedb7030fcea925d3c7af40c3c4a8b54a76 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 26 Feb 2021 11:42:17 +0200 Subject: [PATCH 5/6] CS fix --- lib/full-site-editing/template-loader.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/full-site-editing/template-loader.php b/lib/full-site-editing/template-loader.php index 1d70591f8d4e2c..fc1a1c6eaaeea1 100644 --- a/lib/full-site-editing/template-loader.php +++ b/lib/full-site-editing/template-loader.php @@ -68,12 +68,12 @@ function gutenberg_override_query_template( $template, $type, array $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); + 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) { + if ( $current_template_slug !== $current_block_template_slug && $current_template_slug === $template_item_slug ) { return $template; } } From ce824059e4a940808ace8aa93293607e89bc419f Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 26 Feb 2021 12:01:37 +0200 Subject: [PATCH 6/6] full-stop --- lib/full-site-editing/template-loader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/full-site-editing/template-loader.php b/lib/full-site-editing/template-loader.php index fc1a1c6eaaeea1..f90f07c02fff55 100644 --- a/lib/full-site-editing/template-loader.php +++ b/lib/full-site-editing/template-loader.php @@ -72,7 +72,7 @@ function gutenberg_override_query_template( $template, $type, array $templates = $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 + // 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; }