Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scan the /patterns directory recursively to find patterns in subfolders. #53668

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion lib/compat/wordpress-6.2/block-patterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ function gutenberg_register_theme_block_patterns() {
continue;
}
if ( file_exists( $dirpath ) ) {
$files = glob( $dirpath . '*.php' );
$files = _get_block_pattern_paths( $dirpath);
if ( $files ) {
foreach ( $files as $file ) {
$pattern_data = get_file_data( $file, $default_headers );
Expand Down Expand Up @@ -331,3 +331,24 @@ function gutenberg_normalize_remote_pattern( $pattern ) {

return (array) $pattern;
}

/**
* Finds all nested pattern file paths in a theme's directory.
*
* @since ?
* @access private
*
* @param string $base_directory The theme's file path.
* @return string[] A list of paths to all pattern files.
*/
function _get_block_pattern_paths( $base_directory ) {
$path_list = array();
if ( file_exists( $base_directory ) ) {
$nested_files = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $base_directory ) );
$nested_html_files = new RegexIterator( $nested_files, '/^.+\.php$/i', RecursiveRegexIterator::GET_MATCH );
foreach ( $nested_html_files as $path => $file ) {
$path_list[] = $path;
}
}
return $path_list;
}