Make WordPress Core

Ticket #6531: 6531.5a.2.2.diff

File 6531.5a.2.2.diff, 2.6 KB (added by WraithKenny, 7 years ago)
  • src/wp-admin/includes/file.php

     
    132132        if ( ! $levels )
    133133                return false;
    134134
     135        /**
     136         * Filters the array of excluded directories and files while scanning the folder.
     137         *
     138         * @since 4.9
     139         *
     140         * @param array $exclusions Array of excluded directories and files.
     141         */
     142        $exclusions = (array) apply_filters( 'list_files_exclusions', array( 'CVS', 'node_modules' ) );
     143
    135144        $files = array();
    136145        if ( $dir = @opendir( $folder ) ) {
    137146                while (($file = readdir( $dir ) ) !== false ) {
    138147                        if ( in_array($file, array('.', '..') ) )
    139148                                continue;
     149
     150                        if ( '.' == $file[0] || in_array( $file, $exclusions, true ) )
     151                                continue;
     152
    140153                        if ( is_dir( $folder . '/' . $file ) ) {
    141154                                $files2 = list_files( $folder . '/' . $file, $levels - 1);
    142155                                if ( $files2 )
  • src/wp-admin/includes/plugin.php

     
    193193function get_plugin_files($plugin) {
    194194        $plugin_file = WP_PLUGIN_DIR . '/' . $plugin;
    195195        $dir = dirname($plugin_file);
     196
     197        $data = get_plugin_data($plugin_file);
     198        $label = isset($data['Version']) ? 'list_files_cache_' . $dir . '-' . $data['Version'] : 'list_files_cache_' . $dir;
     199
     200        $plugin_files = get_transient( $label );
     201        if ( ! empty( $plugin_files ) )
     202                return $plugin_files;
     203
    196204        $plugin_files = array($plugin);
    197205        if ( is_dir($dir) && $dir != WP_PLUGIN_DIR ) {
    198                 $plugins_dir = @ opendir( $dir );
    199                 if ( $plugins_dir ) {
    200                         while (($file = readdir( $plugins_dir ) ) !== false ) {
    201                                 if ( substr($file, 0, 1) == '.' )
    202                                         continue;
    203                                 if ( is_dir( $dir . '/' . $file ) ) {
    204                                         $plugins_subdir = @ opendir( $dir . '/' . $file );
    205                                         if ( $plugins_subdir ) {
    206                                                 while (($subfile = readdir( $plugins_subdir ) ) !== false ) {
    207                                                         if ( substr($subfile, 0, 1) == '.' )
    208                                                                 continue;
    209                                                         $plugin_files[] = plugin_basename("$dir/$file/$subfile");
    210                                                 }
    211                                                 @closedir( $plugins_subdir );
    212                                         }
    213                                 } else {
    214                                         if ( plugin_basename("$dir/$file") != $plugin )
    215                                                 $plugin_files[] = plugin_basename("$dir/$file");
    216                                 }
    217                         }
    218                         @closedir( $plugins_dir );
    219                 }
     206
     207                $list_files = list_files( $dir );
     208                $list_files = array_map( 'plugin_basename', $list_files );
     209
     210                $plugin_files += $list_files;
     211                $plugin_files = array_unique( $plugin_files );
     212
    220213        }
    221214
     215        set_transient( $label, $plugin_files, HOUR_IN_SECONDS );
     216
    222217        return $plugin_files;
    223218}
    224219