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
This commit is contained in:
Joe McGill 2025-02-26 16:59:42 +00:00
parent 8c7fe3c809
commit cf198e8fc5

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