WP_Upgrader::flatten_dirlist() WordPress Method

The flatten_dirlist() method of the WP_Upgrader class is used to flatten an array of file paths into a single list of files. The method accepts an array of file paths as its only argument and returns a flattened array of file paths.

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

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


Parameters

$nested_files

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

$path

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

Default value: ''


Top ↑

Return

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


Top ↑

Source

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

357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
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;
}


Top ↑

Changelog

Changelog
VersionDescription
4.9.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.