On this page
WP_Theme::get_files( string[]|string $type = null, int $depth, bool $search_parent = false ): string[]
Returns files in the theme’s directory.
Parameters
$typestring[]|string Optional-
Array of extensions to find, string of a single extension, or null for all extensions.
Default:
null $depthint Optional-
How deep to search for files. Defaults to a flat scan (0 depth).
-1 depth is infinite. $search_parentbool Optional-
Whether to return parent files.
Default:
false
Return
string[] Array of files, keyed by the path to the file relative to the theme's directory, with the values being absolute paths.
Source
File: wp-includes/class-wp-theme.php. View all references
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 );
}
Related
Uses
| Uses | Description |
|---|---|
| WP_Theme::scandir() wp-includes/class-wp-theme.php | Scans a directory for files of a certain extension. |
| WP_Theme::get_stylesheet_directory() wp-includes/class-wp-theme.php | Returns the absolute path to the directory of a theme’s “stylesheet” files. |
| WP_Theme::get_template_directory() wp-includes/class-wp-theme.php | Returns the absolute path to the directory of a theme’s “template” files. |
| WP_Theme::parent() wp-includes/class-wp-theme.php | Returns reference to the parent theme. |
Used By
| Used By | Description |
|---|---|
| WP_Theme::get_post_templates() wp-includes/class-wp-theme.php | Returns the theme’s post templates. |
| WP_Theme::offsetGet() wp-includes/class-wp-theme.php |
Changelog
| Version | Description |
|---|---|
| 3.4.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_theme/get_files