WP_Upgrader::flatten_dirlist

Advertisement

Summery Summery

Flatten the results of WP_Filesystem::dirlist() for iterating over.

Syntax Syntax

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

Parameters Parameters

$nested_files

(array) (Required) Array of files as returned by WP_Filesystem::dirlist()

$path

(string) (Optional) Relative path to prepend to child nodes. Optional.

Default value: ''

Return Return

(array) A flattened array of the $nested_files specified.

Source Source

File: wp-admin/includes/class-wp-upgrader.php

	 * @param string $path         Relative path to prepend to child nodes. Optional.
	 * @return array A flattened array of the $nested_files specified.
	 */
	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;
			}
		}

Advertisement

Changelog Changelog

Changelog
Version Description
4.9.0 Introduced.

Advertisement

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.