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.

Built from https://develop.svn.wordpress.org/trunk@59872


git-svn-id: http://core.svn.wordpress.org/trunk@59214 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Joe McGill
2025-02-26 17:01:26 +00:00
parent 91f31a5169
commit 210b222613
2 changed files with 7 additions and 3 deletions

View File

@@ -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 );