WP_Theme::get_files() WordPress Method

The WP_Theme::get_files() method is used to get an array of all files included in a theme. This can be useful when you need to loop through all the files in a theme to perform some action on them.

WP_Theme::get_files( string[]|string $type = null, int $depth, bool $search_parent = false ) #

Returns files in the theme’s directory.


Parameters

$type

(string[]|string)(Optional) Array of extensions to find, string of a single extension, or null for all extensions.

Default value: null

$depth

(int)(Optional) How deep to search for files. Defaults to a flat scan (0 depth). -1 depth is infinite.

$search_parent

(bool)(Optional) Whether to return parent files.

Default value: false


Top ↑

Return

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


Top ↑

Source

File: wp-includes/class-wp-theme.php

	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 );
	}


Top ↑

Changelog

Changelog
VersionDescription
3.4.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.