Changeset 41806 for trunk/src/wp-admin/includes/file.php
- Timestamp:
- 10/10/2017 05:33:57 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/file.php
r41805 r41806 121 121 * 122 122 * @since 2.6.0 123 * @since 4.9.0 Added the `$exclusions` parameter. 123 124 * 124 125 * @param string $folder Optional. Full path to folder. Default empty. 125 126 * @param int $levels Optional. Levels of folders to follow, Default 100 (PHP Loop limit). 127 * @param array $exclusions Optional. List of folders and files to skip. 126 128 * @return bool|array False on failure, Else array of files 127 129 */ 128 function list_files( $folder = '', $levels = 100 ) {129 if ( empty( $folder) )130 function list_files( $folder = '', $levels = 100, $exclusions = array() ) { 131 if ( empty( $folder ) ) { 130 132 return false; 131 132 if ( ! $levels ) 133 } 134 135 $folder = trailingslashit( $folder ); 136 137 if ( ! $levels ) { 133 138 return false; 139 } 134 140 135 141 $files = array(); 136 if ( $dir = @opendir( $folder ) ) { 137 while (($file = readdir( $dir ) ) !== false ) { 138 if ( in_array($file, array('.', '..') ) ) 142 143 $dir = @opendir( $folder ); 144 if ( $dir ) { 145 while ( ( $file = readdir( $dir ) ) !== false ) { 146 // Skip current and parent folder links. 147 if ( in_array( $file, array( '.', '..' ), true ) ) { 139 148 continue; 140 if ( is_dir( $folder . '/' . $file ) ) { 141 $files2 = list_files( $folder . '/' . $file, $levels - 1); 142 if ( $files2 ) 149 } 150 151 // Skip hidden and excluded files. 152 if ( '.' === $file[0] || in_array( $file, $exclusions, true ) ) { 153 continue; 154 } 155 156 if ( is_dir( $folder . $file ) ) { 157 $files2 = list_files( $folder . $file, $levels - 1 ); 158 if ( $files2 ) { 143 159 $files = array_merge($files, $files2 ); 144 else 145 $files[] = $folder . '/' . $file . '/'; 160 } else { 161 $files[] = $folder . $file . '/'; 162 } 146 163 } else { 147 $files[] = $folder . '/' .$file;164 $files[] = $folder . $file; 148 165 } 149 166 } 150 167 } 151 168 @closedir( $dir ); 169 152 170 return $files; 153 171 }
Note: See TracChangeset
for help on using the changeset viewer.