_get_block_templates_paths( string $base_directory ): string[]

In this article

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

Finds all nested template part file paths in a theme’s directory.

Parameters

$base_directorystringrequired
The theme’s file path.

Return

string[] A list of paths to all template part files.

Source

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();
	try {
		$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;
		}
	} catch ( Exception $e ) {
		// Do nothing.
	}
	$template_path_list[ $base_directory ] = $path_list;
	return $path_list;
}

Changelog

VersionDescription
5.9.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.