From cf198e8fc5d537a6be8adf05c5292a1d774df73c Mon Sep 17 00:00:00 2001 From: Joe McGill Date: Wed, 26 Feb 2025 16:59:42 +0000 Subject: [PATCH] Themes: Allow pattern files to be organized into sub-folders. This allows theme pattern files located in a theme's `/patterns/` directory to be organized into sub-folders and will automatically be located by `WP_Theme::get_block_patterns()` method. Props juanfra, joemcgill, poena, flixos90. Fixes #62378. git-svn-id: https://develop.svn.wordpress.org/trunk@59872 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-theme.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/class-wp-theme.php b/src/wp-includes/class-wp-theme.php index dd9dfde5da..ee74099766 100644 --- a/src/wp-includes/class-wp-theme.php +++ b/src/wp-includes/class-wp-theme.php @@ -1848,7 +1848,7 @@ final class WP_Theme implements ArrayAccess { $this->delete_pattern_cache(); } - $dirpath = $this->get_stylesheet_directory() . '/patterns/'; + $dirpath = $this->get_stylesheet_directory() . '/patterns'; $pattern_data = array(); if ( ! file_exists( $dirpath ) ) { @@ -1857,7 +1857,11 @@ final class WP_Theme implements ArrayAccess { } return $pattern_data; } - $files = glob( $dirpath . '*.php' ); + + $files = (array) self::scandir( $dirpath, 'php', -1 ); + + $dirpath = trailingslashit( $dirpath ); + if ( ! $files ) { if ( $can_use_cached ) { $this->set_pattern_cache( $pattern_data );