Ticket #6531: 6531.8.diff
File 6531.8.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 ( ! empty( $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' ); 989 $all_files = get_transient( $label ); 990 if ( empty( $all_files ) ) { 991 $all_files = (array) self::scandir( $this->get_stylesheet_directory(), null, -1 ); 988 992 989 if ( $search_parent && $this->parent() ) 990 $files += (array) self::scandir( $this->get_template_directory(), $type, $depth ); 993 if ( $search_parent && $this->parent() ) { 994 $all_files += (array) self::scandir( $this->get_template_directory(), null, -1 ); 995 } 991 996 997 set_transient( $label, $all_files, HOUR_IN_SECONDS ); 998 } 999 1000 // Filter $all_files by $type & $depth. 1001 $files = array(); 1002 if ( $type ) { 1003 $type = (array) $type; 1004 $_extensions = implode( '|', $type ); 1005 } 1006 foreach ( $all_files as $key => $file ) { 1007 if ( $depth >= 0 && substr_count( $key, '/' ) > $depth ) { 1008 continue; // Filter by depth. 1009 } 1010 if ( ! $type || preg_match( '~\.(' . $_extensions . ')$~', $file ) ) { // Filter by type. 1011 $files[ $key ] = $file; 1012 } 1013 } 1014 992 1015 return $files; 993 1016 } 994 1017 … … 1107 1130 * with `$relative_path`, with the values being absolute paths. False otherwise. 1108 1131 */ 1109 1132 private static function scandir( $path, $extensions = null, $depth = 0, $relative_path = '' ) { 1110 if ( ! is_dir( $path ) ) 1133 if ( ! is_dir( $path ) ) { 1111 1134 return false; 1135 } 1112 1136 1113 1137 if ( $extensions ) { 1114 1138 $extensions = (array) $extensions; … … 1116 1140 } 1117 1141 1118 1142 $relative_path = trailingslashit( $relative_path ); 1119 if ( '/' == $relative_path ) 1143 if ( '/' == $relative_path ) { 1120 1144 $relative_path = ''; 1145 } 1121 1146 1122 1147 $results = scandir( $path ); 1123 1148 $files = array(); … … 1125 1150 /** 1126 1151 * Filters the array of excluded directories and files while scanning theme folder. 1127 1152 * 1128 1153 * @since 4.7.4 1129 1154 * 1130 1155 * @param array $exclusions Array of excluded directories and files. 1131 1156 */ 1132 $exclusions = (array) apply_filters( 'theme_scandir_exclusions', array( 'CVS', 'node_modules' ) );1157 $exclusions = (array) apply_filters( 'theme_scandir_exclusions', array( 'CVS', 'node_modules', 'vendor', 'bower_components' ) ); 1133 1158 1134 1159 foreach ( $results as $result ) { 1135 1160 if ( '.' == $result[0] || in_array( $result, $exclusions, true ) ) { … … 1136 1161 continue; 1137 1162 } 1138 1163 if ( is_dir( $path . '/' . $result ) ) { 1139 if ( ! $depth ) 1164 if ( ! $depth ) { 1140 1165 continue; 1166 } 1141 1167 $found = self::scandir( $path . '/' . $result, $extensions, $depth - 1 , $relative_path . $result ); 1142 1168 $files = array_merge_recursive( $files, $found ); 1143 1169 } elseif ( ! $extensions || preg_match( '~\.(' . $_extensions . ')$~', $result ) ) {