Filesystem API: Allow optional inclusion of hidden files in `list_files()`.
Adds a new optional `$include_hidden` parameter to allow the inclusion of hidden (`.` prefixed) files. Defaults to false for backward compatibility. Props yani.iliev, sabernhardt, costdev, rutviksavsani, zunaid321, azaozz. Fixes #53659. Built from https://develop.svn.wordpress.org/trunk@56069 git-svn-id: http://core.svn.wordpress.org/trunk@55581 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
c11e87fbb8
commit
58fd744433
|
@ -127,13 +127,16 @@ function get_home_path() {
|
|||
*
|
||||
* @since 2.6.0
|
||||
* @since 4.9.0 Added the `$exclusions` parameter.
|
||||
* @since 6.3.0 Added the `$include_hidden` parameter.
|
||||
*
|
||||
* @param string $folder Optional. Full path to folder. Default empty.
|
||||
* @param int $levels Optional. Levels of folders to follow, Default 100 (PHP Loop limit).
|
||||
* @param string[] $exclusions Optional. List of folders and files to skip.
|
||||
* @param string $folder Optional. Full path to folder. Default empty.
|
||||
* @param int $levels Optional. Levels of folders to follow, Default 100 (PHP Loop limit).
|
||||
* @param string[] $exclusions Optional. List of folders and files to skip.
|
||||
* @param bool $include_hidden Optional. Whether to include details of hidden ("." prefixed) files.
|
||||
* Default false.
|
||||
* @return string[]|false Array of files on success, false on failure.
|
||||
*/
|
||||
function list_files( $folder = '', $levels = 100, $exclusions = array() ) {
|
||||
function list_files( $folder = '', $levels = 100, $exclusions = array(), $include_hidden = false ) {
|
||||
if ( empty( $folder ) ) {
|
||||
return false;
|
||||
}
|
||||
|
@ -156,12 +159,12 @@ function list_files( $folder = '', $levels = 100, $exclusions = array() ) {
|
|||
}
|
||||
|
||||
// Skip hidden and excluded files.
|
||||
if ( '.' === $file[0] || in_array( $file, $exclusions, true ) ) {
|
||||
if ( ( ! $include_hidden && '.' === $file[0] ) || in_array( $file, $exclusions, true ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( is_dir( $folder . $file ) ) {
|
||||
$files2 = list_files( $folder . $file, $levels - 1 );
|
||||
$files2 = list_files( $folder . $file, $levels - 1, array(), $include_hidden );
|
||||
if ( $files2 ) {
|
||||
$files = array_merge( $files, $files2 );
|
||||
} else {
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.3-alpha-56068';
|
||||
$wp_version = '6.3-alpha-56069';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue