From 58fd74443300e6baba1de2114ae012d938de83d5 Mon Sep 17 00:00:00 2001 From: Mike Schroder Date: Tue, 27 Jun 2023 16:08:27 +0000 Subject: [PATCH] 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 --- wp-admin/includes/file.php | 15 +++++++++------ wp-includes/version.php | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php index 3ead3d98cd..6ef2aed553 100644 --- a/wp-admin/includes/file.php +++ b/wp-admin/includes/file.php @@ -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 { diff --git a/wp-includes/version.php b/wp-includes/version.php index c0e1e28d52..cb75e41512 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.