WP_Upgrader::flatten_dirlist( array $nested_files, string $path =  ): array

In this article

Flattens the results of WP_Filesystem_Base::dirlist() for iterating over.

Parameters

$nested_filesarrayrequired
Array of files as returned by WP_Filesystem_Base::dirlist().
$pathstringoptional
Relative path to prepend to child nodes. Optional.

Default:''

Return

array A flattened array of the $nested_files specified.

Source

protected function flatten_dirlist( $nested_files, $path = '' ) {
	$files = array();

	foreach ( $nested_files as $name => $details ) {
		$files[ $path . $name ] = $details;

		// Append children recursively.
		if ( ! empty( $details['files'] ) ) {
			$children = $this->flatten_dirlist( $details['files'], $path . $name . '/' );

			// Merge keeping possible numeric keys, which array_merge() will reindex from 0..n.
			$files = $files + $children;
		}
	}

	return $files;
}

Changelog

VersionDescription
4.9.0Introduced.

User Contributed Notes

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