Ticket #6531: 6531.7.diff
File 6531.7.diff, 6.5 KB (added by , 7 years ago) |
---|
-
src/wp-admin/includes/file.php
diff --git src/wp-admin/includes/file.php src/wp-admin/includes/file.php index 05bfde46a4..6c15bded98 100644
$wp_file_descriptions = array( 70 70 * @since 1.5.0 71 71 * 72 72 * @global array $wp_file_descriptions Theme file descriptions. 73 * @global array $allowed_files List of allowed files. 73 * @global array $allowed_files List of allowed files. 74 74 * @param string $file Filesystem path or filename 75 75 * @return string Description of file from $wp_file_descriptions or basename of $file if description doesn't exist. 76 76 * Appends 'Page Template' to basename of $file if the file is a page template … … function get_home_path() { 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 } 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' ) ); 134 145 135 146 $files = array(); 136 147 if ( $dir = @opendir( $folder ) ) { 137 while (($file = readdir( $dir ) ) !== false ) { 138 if ( in_array($file, array('.', '..') ) ) 148 while ( ( $file = readdir( $dir ) ) !== false ) { 149 if ( in_array( $file, array( '.', '..' ), true ) ) { 150 continue; 151 } 152 153 if ( '.' === $file[0] || in_array( $file, $exclusions, true ) ) { 139 154 continue; 155 } 156 140 157 if ( is_dir( $folder . '/' . $file ) ) { 141 $files2 = list_files( $folder . '/' . $file, $levels - 1 );142 if ( $files2 ) 143 $files = array_merge( $files, $files2 );144 else158 $files2 = list_files( $folder . '/' . $file, $levels - 1 ); 159 if ( $files2 ) { 160 $files = array_merge( $files, $files2 ); 161 } else { 145 162 $files[] = $folder . '/' . $file . '/'; 163 } 146 164 } else { 147 165 $files[] = $folder . '/' . $file; 148 166 } -
src/wp-admin/includes/plugin.php
diff --git src/wp-admin/includes/plugin.php src/wp-admin/includes/plugin.php index 97dd767850..802f9884be 100644
function _get_plugin_data_markup_translate( $plugin_file, $plugin_data, $markup 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; 203 } 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 ); 220 213 } 221 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
diff --git src/wp-admin/theme-editor.php src/wp-admin/theme-editor.php index 2a593dee64..3247bb7d14 100644
$file_types = array_unique( array_merge( $file_types, $default_types ) ); 120 120 foreach ( $file_types as $type ) { 121 121 switch ( $type ) { 122 122 case 'php': 123 $allowed_files += $theme->get_files( 'php', 1 );123 $allowed_files += $theme->get_files( 'php', -1 ); 124 124 $has_templates = ! empty( $allowed_files ); 125 125 break; 126 126 case 'css': 127 $style_files = $theme->get_files( 'css' );127 $style_files = $theme->get_files( 'css', -1 ); 128 128 $allowed_files['style.css'] = $style_files['style.css']; 129 129 $allowed_files += $style_files; 130 130 break; 131 131 default: 132 $allowed_files += $theme->get_files( $type );132 $allowed_files += $theme->get_files( $type, -1 ); 133 133 break; 134 134 } 135 135 } -
src/wp-includes/class-wp-theme.php
diff --git src/wp-includes/class-wp-theme.php src/wp-includes/class-wp-theme.php index 3e6c62906b..1ae904579e 100644
final class WP_Theme implements ArrayAccess { 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 ); 992 993 if ( $search_parent && $this->parent() ) { 994 $all_files += (array) self::scandir( $this->get_template_directory(), null, -1 ); 995 } 996 997 set_transient( $label, $all_files, HOUR_IN_SECONDS ); 998 } 988 999 989 if ( $search_parent && $this->parent() ) 990 $files += (array) self::scandir( $this->get_template_directory(), $type, $depth ); 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 } 991 1014 992 1015 return $files; 993 1016 }