_get_block_templates_paths()
Finds all nested template part file paths in a theme's directory.
Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.
No Hooks.
Returns
String[]. A list of paths to all template part files.
Usage
_get_block_templates_paths( $base_directory );
- $base_directory(string) (required)
- The theme's file path.
Changelog
| Since 5.9.0 | Introduced. |
_get_block_templates_paths() get block templates paths code WP 6.8.3
function _get_block_templates_paths( $base_directory ) {
static $template_path_list = array();
if ( isset( $template_path_list[ $base_directory ] ) ) {
return $template_path_list[ $base_directory ];
}
$path_list = array();
if ( is_dir( $base_directory ) ) {
$nested_files = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $base_directory ) );
$nested_html_files = new RegexIterator( $nested_files, '/^.+\.html$/i', RecursiveRegexIterator::GET_MATCH );
foreach ( $nested_html_files as $path => $file ) {
$path_list[] = $path;
}
}
$template_path_list[ $base_directory ] = $path_list;
return $path_list;
}