Ticket #6531: 6531.9.diff
File 6531.9.diff, 7.8 KB (added by , 7 years ago) |
---|
-
src/wp-admin/includes/file.php
126 126 * @return bool|array False on failure, Else array of files 127 127 */ 128 128 function list_files( $folder = '', $levels = 100 ) { 129 if ( empty( $folder) )129 if ( empty( $folder ) ) { 130 130 return false; 131 } 131 132 132 if ( ! $levels ) 133 if ( ! $levels ) { 133 134 return false; 135 } 134 136 137 /** 138 * Filters the array of excluded directories and files while scanning the folder. 139 * 140 * @since 4.9 141 * 142 * @param array $exclusions Array of excluded directories and files. 143 */ 144 $exclusions = (array) apply_filters( 'list_files_exclusions', array( 'CVS', 'node_modules', 'vendor', 'bower_components' ) ); 145 135 146 $files = array(); 136 if ( $dir = @opendir( $folder ) ) { 137 while (($file = readdir( $dir ) ) !== false ) { 138 if ( in_array($file, array('.', '..') ) ) 147 $dir = @opendir( $folder ); 148 if ( $dir ) { 149 while ( ( $file = readdir( $dir ) ) !== false ) { 150 if ( in_array( $file, array( '.', '..' ) ) ) { 139 151 continue; 152 } 153 154 if ( '.' === $file[0] || in_array( $file, $exclusions, true ) ) { 155 continue; 156 } 157 140 158 if ( is_dir( $folder . '/' . $file ) ) { 141 $files2 = list_files( $folder . '/' . $file, $levels - 1 );142 if ( $files2 ) 159 $files2 = list_files( $folder . '/' . $file, $levels - 1 ); 160 if ( $files2 ) { 143 161 $files = array_merge($files, $files2 ); 144 else162 } else { 145 163 $files[] = $folder . '/' . $file . '/'; 164 } 146 165 } else { 147 166 $files[] = $folder . '/' . $file; 148 167 } -
src/wp-admin/includes/plugin.php
190 190 * @param string $plugin Path to the main plugin file from plugins directory. 191 191 * @return array List of files relative to the plugin root. 192 192 */ 193 function get_plugin_files( $plugin) {193 function get_plugin_files( $plugin ) { 194 194 $plugin_file = WP_PLUGIN_DIR . '/' . $plugin; 195 $dir = dirname($plugin_file); 196 $plugin_files = array($plugin); 197 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 } 195 $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 ( false !== $plugin_files ) { 202 return $plugin_files; 220 203 } 221 204 205 $plugin_files = array( $plugin ); 206 if ( is_dir( $dir ) && WP_PLUGIN_DIR !== $dir ) { 207 208 $list_files = list_files( $dir ); 209 $list_files = array_map( 'plugin_basename', $list_files ); 210 211 $plugin_files += $list_files; 212 $plugin_files = array_unique( $plugin_files ); 213 } 214 215 set_transient( $label, $plugin_files, HOUR_IN_SECONDS ); 216 222 217 return $plugin_files; 223 218 } 224 219 -
src/wp-admin/theme-editor.php
75 75 foreach ( $file_types as $type ) { 76 76 switch ( $type ) { 77 77 case 'php': 78 $allowed_files += $theme->get_files( 'php', 1 );78 $allowed_files += $theme->get_files( 'php', -1 ); 79 79 $has_templates = ! empty( $allowed_files ); 80 80 break; 81 81 case 'css': 82 $style_files = $theme->get_files( 'css' );82 $style_files = $theme->get_files( 'css', -1 ); 83 83 $allowed_files['style.css'] = $style_files['style.css']; 84 84 $allowed_files += $style_files; 85 85 break; 86 86 default: 87 $allowed_files += $theme->get_files( $type );87 $allowed_files += $theme->get_files( $type, -1 ); 88 88 break; 89 89 } 90 90 } -
src/wp-includes/class-wp-theme.php
981 981 * @param int $depth Optional. How deep to search for files. Defaults to a flat scan (0 depth). -1 depth is infinite. 982 982 * @param bool $search_parent Optional. Whether to return parent files. Defaults to false. 983 983 * @return array Array of files, keyed by the path to the file relative to the theme's directory, with the values 984 * 984 * being absolute paths. 985 985 */ 986 986 public function get_files( $type = null, $depth = 0, $search_parent = false ) { 987 $files = (array) self::scandir( $this->get_stylesheet_directory(), $type, $depth ); 987 // get and cache all theme files to start with. 988 $label = 'list_files_cache_' . $this->get( 'Name' ) . '-' . $this->get( 'Version' ); 988 989 989 if ( $search_parent && $this->parent() ) 990 $files += (array) self::scandir( $this->get_template_directory(), $type, $depth ); 990 $all_files = get_transient( $label ); 991 if ( false === $all_files ) { 992 $all_files = (array) self::scandir( $this->get_stylesheet_directory(), null, -1 ); 991 993 994 if ( $search_parent && $this->parent() ) { 995 $all_files += (array) self::scandir( $this->get_template_directory(), null, -1 ); 996 } 997 998 set_transient( $label, $all_files, HOUR_IN_SECONDS ); 999 } 1000 1001 // Filter $all_files by $type & $depth. 1002 $files = array(); 1003 if ( $type ) { 1004 $type = (array) $type; 1005 $_extensions = implode( '|', $type ); 1006 } 1007 foreach ( $all_files as $key => $file ) { 1008 if ( $depth >= 0 && substr_count( $key, '/' ) > $depth ) { 1009 continue; // Filter by depth. 1010 } 1011 if ( ! $type || preg_match( '~\.(' . $_extensions . ')$~', $file ) ) { // Filter by type. 1012 $files[ $key ] = $file; 1013 } 1014 } 1015 992 1016 return $files; 993 1017 } 994 1018 … … 1107 1131 * with `$relative_path`, with the values being absolute paths. False otherwise. 1108 1132 */ 1109 1133 private static function scandir( $path, $extensions = null, $depth = 0, $relative_path = '' ) { 1110 if ( ! is_dir( $path ) ) 1134 if ( ! is_dir( $path ) ) { 1111 1135 return false; 1136 } 1112 1137 1113 1138 if ( $extensions ) { 1114 1139 $extensions = (array) $extensions; … … 1116 1141 } 1117 1142 1118 1143 $relative_path = trailingslashit( $relative_path ); 1119 if ( '/' == $relative_path ) 1144 if ( '/' == $relative_path ) { 1120 1145 $relative_path = ''; 1146 } 1121 1147 1122 1148 $results = scandir( $path ); 1123 1149 $files = array(); … … 1125 1151 /** 1126 1152 * Filters the array of excluded directories and files while scanning theme folder. 1127 1153 * 1128 1154 * @since 4.7.4 1129 1155 * 1130 1156 * @param array $exclusions Array of excluded directories and files. 1131 1157 */ 1132 $exclusions = (array) apply_filters( 'theme_scandir_exclusions', array( 'CVS', 'node_modules' ) );1158 $exclusions = (array) apply_filters( 'theme_scandir_exclusions', array( 'CVS', 'node_modules', 'vendor', 'bower_components' ) ); 1133 1159 1134 1160 foreach ( $results as $result ) { 1135 1161 if ( '.' == $result[0] || in_array( $result, $exclusions, true ) ) { … … 1136 1162 continue; 1137 1163 } 1138 1164 if ( is_dir( $path . '/' . $result ) ) { 1139 if ( ! $depth ) 1165 if ( ! $depth ) { 1140 1166 continue; 1167 } 1141 1168 $found = self::scandir( $path . '/' . $result, $extensions, $depth - 1 , $relative_path . $result ); 1142 1169 $files = array_merge_recursive( $files, $found ); 1143 1170 } elseif ( ! $extensions || preg_match( '~\.(' . $_extensions . ')$~', $result ) ) {