From 3b0df77ab1902ebaf7db0b960c0820e1f09a8b93 Mon Sep 17 00:00:00 2001 From: Brandon Date: Sat, 30 Mar 2024 14:54:49 -0500 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=A9=B9=20Only=20prioritize=20block=20?= =?UTF-8?q?templates=20in=20block=20themes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Roots/Acorn/Sage/Concerns/FiltersTemplates.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Roots/Acorn/Sage/Concerns/FiltersTemplates.php b/src/Roots/Acorn/Sage/Concerns/FiltersTemplates.php index 39969091..134ceaba 100644 --- a/src/Roots/Acorn/Sage/Concerns/FiltersTemplates.php +++ b/src/Roots/Acorn/Sage/Concerns/FiltersTemplates.php @@ -14,11 +14,9 @@ trait FiltersTemplates */ public function filterTemplateHierarchy($files) { - $templates = [...$this->sageFinder->locate($files), ...$files]; - - return ! current_theme_supports('block-templates') - ? $templates - : array_reverse($templates); + return wp_is_block_theme() && current_theme_supports('block-templates') + ? [...$files, ...$this->sageFinder->locate($files)] + : [...$this->sageFinder->locate($files), ...$files]; } /** From 83c5de2bd38bc33b6cf27bbcfdcc29ec82421951 Mon Sep 17 00:00:00 2001 From: Brandon Date: Sat, 30 Mar 2024 15:53:20 -0500 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=8E=A8=20Improve=20template=20hierarc?= =?UTF-8?q?hy=20implementation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Acorn/Sage/Concerns/FiltersTemplates.php | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/Roots/Acorn/Sage/Concerns/FiltersTemplates.php b/src/Roots/Acorn/Sage/Concerns/FiltersTemplates.php index 134ceaba..e30fa6d7 100644 --- a/src/Roots/Acorn/Sage/Concerns/FiltersTemplates.php +++ b/src/Roots/Acorn/Sage/Concerns/FiltersTemplates.php @@ -14,9 +14,28 @@ trait FiltersTemplates */ public function filterTemplateHierarchy($files) { - return wp_is_block_theme() && current_theme_supports('block-templates') - ? [...$files, ...$this->sageFinder->locate($files)] - : [...$this->sageFinder->locate($files), ...$files]; + $templates = $this->sageFinder->locate($files); + + if ( + ! function_exists('wp_is_block_theme') || + ! wp_is_block_theme() || + ! current_theme_supports('block-templates') + ) { + return [...$templates, ...$files]; + } + + $paths = []; + + if ($template = get_page_template_slug()) { + $paths = array_filter( + $templates, + fn ($file) => str_contains($file, $template) + ); + + $templates = array_diff($templates, $paths); + } + + return [...$paths, ...$files, ...$templates]; } /** From 6479008ba01debae42890fb8cbfceb7f7714d4b5 Mon Sep 17 00:00:00 2001 From: Brandon Date: Sat, 30 Mar 2024 16:34:32 -0500 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=8E=A8=20Improve=20variable=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Roots/Acorn/Sage/Concerns/FiltersTemplates.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Roots/Acorn/Sage/Concerns/FiltersTemplates.php b/src/Roots/Acorn/Sage/Concerns/FiltersTemplates.php index e30fa6d7..f5055562 100644 --- a/src/Roots/Acorn/Sage/Concerns/FiltersTemplates.php +++ b/src/Roots/Acorn/Sage/Concerns/FiltersTemplates.php @@ -24,18 +24,18 @@ public function filterTemplateHierarchy($files) return [...$templates, ...$files]; } - $paths = []; + $pages = []; if ($template = get_page_template_slug()) { - $paths = array_filter( + $pages = array_filter( $templates, fn ($file) => str_contains($file, $template) ); - $templates = array_diff($templates, $paths); + $templates = array_diff($templates, $pages); } - return [...$paths, ...$files, ...$templates]; + return [...$pages, ...$files, ...$templates]; } /**