WP_Theme::get_files()publicWP 3.4.0

Returns files in the theme's directory.

Method of the class: WP_Theme{}

No Hooks.

Return

String[]. Array of files, keyed by the path to the file relative to the theme's directory, with the values being absolute paths.

Usage

$WP_Theme = new WP_Theme();
$WP_Theme->get_files( $type, $depth, $search_parent );
$type(string[]|string)
Array of extensions to find, string of a single extension, or null for all extensions.
Default: null
$depth(int)
How deep to search for files.
-1 depth is infinite.
Default: flat scan (0 depth)
$search_parent(true|false)
Whether to return parent files.
Default: false

Changelog

Since 3.4.0 Introduced.

WP_Theme::get_files() code WP 6.5.2

public function get_files( $type = null, $depth = 0, $search_parent = false ) {
	$files = (array) self::scandir( $this->get_stylesheet_directory(), $type, $depth );

	if ( $search_parent && $this->parent() ) {
		$files += (array) self::scandir( $this->get_template_directory(), $type, $depth );
	}

	return array_filter( $files );
}