Ticket #46707: 46707.4.diff
| File 46707.4.diff, 9.7 KB (added by , 7 years ago) |
|---|
-
src/js/_enqueues/admin/site-health.js
276 276 // Cancel the announcement. 277 277 window.clearTimeout( timeout ); 278 278 } 279 280 $( document ).trigger( 'site-health-info-dirsizes-done' ); 279 281 } ); 280 282 } 281 283 -
src/wp-admin/includes/ajax-actions.php
4976 4976 } 4977 4977 4978 4978 $sizes_data = WP_Debug_Data::get_sizes(); 4979 $all_sizes = array( );4979 $all_sizes = array( 'raw' => 0 ); 4980 4980 4981 4981 foreach ( $sizes_data as $name => $value ) { 4982 4982 $name = sanitize_text_field( $name ); … … 4998 4998 } 4999 4999 } 5000 5000 5001 if ( ! empty( $value['raw'] ) ) { 5002 $data['raw'] = (int) $value['raw']; 5003 } 5004 5001 5005 $all_sizes[ $name ] = $data; 5002 5006 } 5003 5007 -
src/wp-admin/includes/class-wp-debug-data.php
392 392 $not_calculated = __( 'Not calculated' ); 393 393 394 394 $info['wp-paths-sizes']['fields'] = array( 395 'wordpress_path' => array( 396 'label' => __( 'WordPress directory location' ), 397 'value' => untrailingslashit( ABSPATH ), 398 ), 395 399 'uploads_path' => array( 396 'label' => __( 'Uploads Directory Location' ),400 'label' => __( 'Uploads directory location' ), 397 401 'value' => $upload_dir['basedir'], 398 402 ), 399 403 'uploads_size' => array( 400 'label' => __( 'Uploads Directory Size' ),404 'label' => __( 'Uploads directory size' ), 401 405 'value' => $not_calculated, 402 406 'debug' => 'not calculated', 403 407 ), 404 408 'themes_path' => array( 405 'label' => __( 'Themes Directory Location' ),406 'value' => trailingslashit( get_theme_root()),409 'label' => __( 'Themes directory location' ), 410 'value' => get_theme_root(), 407 411 ), 408 412 'current_theme_path' => array( 409 'label' => __( 'Current Theme Directory' ),413 'label' => __( 'Current theme directory' ), 410 414 'value' => get_template_directory(), 411 415 ), 412 416 'themes_size' => array( 413 'label' => __( 'Themes Directory Size' ),417 'label' => __( 'Themes directory size' ), 414 418 'value' => $not_calculated, 415 419 'debug' => 'not calculated', 416 420 ), 417 421 'plugins_path' => array( 418 'label' => __( 'Plugins Directory Location' ),419 'value' => trailingslashit( WP_PLUGIN_DIR ),422 'label' => __( 'Plugins directory location' ), 423 'value' => WP_PLUGIN_DIR, 420 424 ), 421 425 'plugins_size' => array( 422 'label' => __( 'Plugins Directory Size' ),426 'label' => __( 'Plugins directory size' ), 423 427 'value' => $not_calculated, 424 428 'debug' => 'not calculated', 425 429 ), 426 'wordpress_path' => array(427 'label' => __( 'WordPress Directory Location' ),428 'value' => ABSPATH,429 ),430 430 'wordpress_size' => array( 431 'label' => __( 'WordPress Directory Size' ),431 'label' => __( 'WordPress size' ), 432 432 'value' => $not_calculated, 433 433 'debug' => 'not calculated', 434 434 ), … … 1137 1137 } 1138 1138 1139 1139 // Go through the various installation directories and calculate their sizes. 1140 $all_sizes = array( 1141 'wordpress_size' => array( 1142 'path' => ABSPATH, 1143 'size' => 0, 1144 ), 1145 'themes_size' => array( 1146 'path' => trailingslashit( get_theme_root() ), 1147 'size' => 0, 1148 ), 1149 'plugins_size' => array( 1150 'path' => trailingslashit( WP_PLUGIN_DIR ), 1151 'size' => 0, 1152 ), 1153 'uploads_size' => array( 1154 'path' => $upload_dir['basedir'], 1155 'size' => 0, 1156 ), 1140 // No trailing slashes. 1141 $paths = array( 1142 'wp_root_dir' => untrailingslashit( ABSPATH ), 1143 'themes_size' => get_theme_root(), 1144 'plugins_size' => WP_PLUGIN_DIR, 1145 'uploads_size' => $upload_dir['basedir'], 1157 1146 ); 1158 1147 1148 $exclude = $paths; 1149 unset( $exclude['wp_root_dir'] ); 1150 $exclude = array_values( $exclude ); 1151 1159 1152 $size_total = 0; 1153 $all_sizes = array(); 1160 1154 1161 1155 // Loop over all the directories we want to gather the sizes for. 1162 foreach ( $ all_sizes as $name => $attributes) {1156 foreach ( $paths as $name => $path ) { 1163 1157 $dir_size = null; // Default to timeout. 1158 $results = array( 1159 'path' => $path, 1160 'raw' => 0, 1161 ); 1164 1162 1165 1163 if ( microtime( true ) - WP_START_TIMESTAMP < $max_execution_time ) { 1166 $dir_size = recurse_dirsize( $attributes['path'], null, $max_execution_time ); 1164 if ( 'wp_root_dir' === $name ) { 1165 $dir_size = recurse_dirsize( $path, $exclude, $max_execution_time ); 1166 } else { 1167 $dir_size = recurse_dirsize( $path, null, $max_execution_time ); 1168 } 1167 1169 } 1168 1170 1169 1171 if ( false === $dir_size ) { 1170 1172 // Error reading. 1171 $ all_sizes[ $name ]['size'] = __( 'The size cannot be calculated. The directory is not accessible. Usually caused by invalid permissions.' );1172 $ all_sizes[ $name ]['debug'] = 'not accessible';1173 $results['size'] = __( 'The size cannot be calculated. The directory is not accessible. Usually caused by invalid permissions.' ); 1174 $results['debug'] = 'not accessible'; 1173 1175 1174 1176 // Stop total size calculation. 1175 1177 $size_total = null; 1176 1178 } elseif ( null === $dir_size ) { 1177 1179 // Timeout. 1178 $ all_sizes[ $name ]['size'] = __( 'The directory size calculation has timed out. Usually caused by a very large number of sub-directories and files.' );1179 $ all_sizes[ $name ]['debug'] = 'timeout while calculating size';1180 $results['size'] = __( 'The directory size calculation has timed out. Usually caused by a very large number of sub-directories and files.' ); 1181 $results['debug'] = 'timeout while calculating size'; 1180 1182 1181 1183 // Stop total size calculation. 1182 1184 $size_total = null; 1183 1185 } else { 1184 $is_subdir = ( strpos( $attributes['path'], ABSPATH ) === 0 ); 1185 1186 // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled 1187 if ( null !== $size_total && ( 'wordpress_size' === $name || ! $is_subdir ) ) { 1186 if ( null !== $size_total ) { 1188 1187 $size_total += $dir_size; 1189 1188 } 1190 1189 1191 $all_sizes[ $name ]['size'] = size_format( $dir_size, 2 ); 1192 $all_sizes[ $name ]['debug'] = $all_sizes[ $name ]['size']; 1190 $results['raw'] = $dir_size; 1191 $results['size'] = size_format( $dir_size, 2 ); 1192 $results['debug'] = $results['size'] . " ({$dir_size} bytes)"; 1193 1193 } 1194 1195 $all_sizes[ $name ] = $results; 1194 1196 } 1195 1197 1198 // Remove the "total size" helper. 1199 unset( $all_sizes['wp_root_dir'] ); 1200 1196 1201 if ( $size_db > 0 ) { 1197 1202 $database_size = size_format( $size_db, 2 ); 1198 1203 1199 1204 $all_sizes['database_size'] = array( 1205 'raw' => $size_db, 1200 1206 'size' => $database_size, 1201 'debug' => $database_size ,1207 'debug' => $database_size . " ({$size_db} bytes)", 1202 1208 ); 1203 1209 } else { 1204 1210 $all_sizes['database_size'] = array( … … 1207 1213 ); 1208 1214 } 1209 1215 1216 if ( null !== $size_total ) { 1217 $size_total_mb = size_format( $size_total, 2 ); 1218 1219 $all_sizes['wordpress_size'] = array( 1220 'raw' => $size_total, 1221 'size' => $size_total_mb, 1222 'debug' => $size_total_mb . " ({$size_total} bytes)", 1223 ); 1224 } else { 1225 $all_sizes['wordpress_size'] = array( 1226 'size' => __( 'Not available' ), 1227 'debug' => 'not available', 1228 ); 1229 } 1230 1210 1231 if ( null !== $size_total && $size_db > 0 ) { 1211 $total_size = size_format( $size_total + $size_db, 2 ); 1232 $total_size = $size_total + $size_db; 1233 $total_size_mb = size_format( $total_size, 2 ); 1212 1234 1213 1235 $all_sizes['total_size'] = array( 1214 'size' => $total_size, 1215 'debug' => $total_size, 1236 'raw' => $total_size, 1237 'size' => $total_size_mb, 1238 'debug' => $total_size_mb . " ({$total_size} bytes)", 1216 1239 ); 1217 1240 } else { 1218 1241 $all_sizes['total_size'] = array( -
src/wp-includes/functions.php
7067 7067 * @since 4.3.0 $exclude parameter added. 7068 7068 * @since 5.2.0 $max_execution_time parameter added. 7069 7069 * 7070 * @param string $directory Full path of a directory. 7071 * @param string $exclude Optional. Full path of a subdirectory to exclude from the total. 7072 * @param int $max_execution_time Maximum time to run before giving up. In seconds. 7073 * The timeout is global and is measured from the moment WordPress started to load. 7074 * @return int|false|null Size in MB if a valid directory. False if not. Null if timeout. 7070 * @param string $directory Full path of a directory. 7071 * @param string|array $exclude Optional. Full path of a subdirectory to exclude from the total, or array of paths. 7072 * Expected without trailing slash(es). 7073 * @param int $max_execution_time Maximum time to run before giving up. In seconds. 7074 * The timeout is global and is measured from the moment WordPress started to load. 7075 * @return int|false|null Size in bytes if a valid directory. False if not. Null if timeout. 7075 7076 */ 7076 7077 function recurse_dirsize( $directory, $exclude = null, $max_execution_time = null ) { 7077 7078 $size = 0; … … 7078 7079 7079 7080 $directory = untrailingslashit( $directory ); 7080 7081 7081 if ( ! file_exists( $directory ) || ! is_dir( $directory ) || ! is_readable( $directory ) || $directory === $exclude) {7082 if ( ! file_exists( $directory ) || ! is_dir( $directory ) || ! is_readable( $directory ) ) { 7082 7083 return false; 7083 7084 } 7084 7085 7086 if ( 7087 ( is_string( $exclude ) && $directory === $exclude ) || 7088 ( is_array( $exclude ) && in_array( $directory, $exclude, true ) ) 7089 ) { 7090 return false; 7091 } 7092 7085 7093 if ( $max_execution_time === null ) { 7086 7094 // Keep the previous behavior but attempt to prevent fatal errors from timeout if possible. 7087 7095 if ( function_exists( 'ini_get' ) ) {