Make WordPress Core

Changeset 56069

Timestamp:
06/27/2023 04:06:16 PM (14 months ago)
Author:
mikeschroder
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/file.php

    r55990 r56069  
    128128 * @since 2.6.0
    129129 * @since 4.9.0 Added the `$exclusions` parameter.
    130  *
    131  * @param string   $folder     Optional. Full path to folder. Default empty.
    132  * @param int      $levels     Optional. Levels of folders to follow, Default 100 (PHP Loop limit).
    133  * @param string[] $exclusions Optional. List of folders and files to skip.
     130 * @since 6.3.0 Added the `$include_hidden` parameter.
     131 *
     132 * @param string   $folder         Optional. Full path to folder. Default empty.
     133 * @param int      $levels         Optional. Levels of folders to follow, Default 100 (PHP Loop limit).
     134 * @param string[] $exclusions     Optional. List of folders and files to skip.
     135 * @param bool     $include_hidden Optional. Whether to include details of hidden ("." prefixed) files.
     136 *                                 Default false.
    134137 * @return string[]|false Array of files on success, false on failure.
    135138 */
    136 function list_files( $folder = '', $levels = 100, $exclusions = array() ) {
     139function list_files( $folder = '', $levels = 100, $exclusions = array() ) {
    137140    if ( empty( $folder ) ) {
    138141        return false;
     
    157160
    158161            // Skip hidden and excluded files.
    159             if ( '.' === $file[0] || in_array( $file, $exclusions, true ) ) {
     162            if ( || in_array( $file, $exclusions, true ) ) {
    160163                continue;
    161164            }
    162165
    163166            if ( is_dir( $folder . $file ) ) {
    164                 $files2 = list_files( $folder . $file, $levels - 1 );
     167                $files2 = list_files( $folder . $file, $levels - 1 );
    165168                if ( $files2 ) {
    166169                    $files = array_merge( $files, $files2 );
  • trunk/tests/phpunit/tests/functions/listFiles.php

    r51331 r56069  
    2020        $this->assertNotContains( ABSPATH . 'wp-admin/index.php', $admin_files );
    2121    }
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
    2281}
Note: See TracChangeset for help on using the changeset viewer.