Changeset 45220
- Timestamp:
- 04/16/2019 11:01:45 PM (5 years ago)
- Location:
- trunk/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/js/_enqueues/admin/site-health.js
r45198 r45220 277 277 window.clearTimeout( timeout ); 278 278 } 279 280 $( document ).trigger( 'site-health-info-dirsizes-done' ); 279 281 } ); 280 282 } -
trunk/src/wp-admin/includes/ajax-actions.php
r45190 r45220 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 ) { … … 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 } -
trunk/src/wp-admin/includes/class-wp-debug-data.php
r45200 r45220 393 393 394 394 $info['wp-paths-sizes']['fields'] = array( 395 ' uploads_path'=> array(396 'label' => __( ' Uploads Directory Location' ),397 'value' => $upload_dir['basedir'],398 ), 399 ' uploads_size'=> array(400 'label' => __( ' Uploads Directory Size' ),395 'wordpress_path' => array( 396 'label' => __( 'WordPress directory location' ), 397 'value' => untrailingslashit( ABSPATH ), 398 ), 399 'wordpress_size' => array( 400 'label' => __( 'WordPress directory size' ), 401 401 'value' => $not_calculated, 402 402 'debug' => 'not calculated', 403 403 ), 404 'themes_path' => array( 405 'label' => __( 'Themes Directory Location' ), 406 'value' => trailingslashit( get_theme_root() ), 407 ), 408 'current_theme_path' => array( 409 'label' => __( 'Current Theme Directory' ), 410 'value' => get_template_directory(), 411 ), 412 'themes_size' => array( 413 'label' => __( 'Themes Directory Size' ), 404 'uploads_path' => array( 405 'label' => __( 'Uploads directory location' ), 406 'value' => $upload_dir['basedir'], 407 ), 408 'uploads_size' => array( 409 'label' => __( 'Uploads directory size' ), 414 410 'value' => $not_calculated, 415 411 'debug' => 'not calculated', 416 412 ), 417 ' plugins_path'=> array(418 'label' => __( ' Plugins Directory Location' ),419 'value' => trailingslashit( WP_PLUGIN_DIR),420 ), 421 ' plugins_size'=> array(422 'label' => __( ' Plugins Directory Size' ),413 'themes_path' => array( 414 'label' => __( 'Themes directory location' ), 415 'value' => get_theme_root(), 416 ), 417 'themes_size' => array( 418 'label' => __( 'Themes directory size' ), 423 419 'value' => $not_calculated, 424 420 'debug' => 'not calculated', 425 421 ), 426 ' wordpress_path'=> array(427 'label' => __( ' WordPress Directory Location' ),428 'value' => ABSPATH,429 ), 430 ' wordpress_size'=> array(431 'label' => __( ' WordPress Directory Size' ),422 'plugins_path' => array( 423 'label' => __( 'Plugins directory location' ), 424 'value' => WP_PLUGIN_DIR, 425 ), 426 'plugins_size' => array( 427 'label' => __( 'Plugins directory size' ), 432 428 'value' => $not_calculated, 433 429 'debug' => 'not calculated', … … 898 894 'label' => __( 'Theme features' ), 899 895 'value' => implode( ', ', $theme_features ), 896 ), 897 'theme_path' => array( 898 'label' => __( 'Theme directory location' ), 899 'value' => get_template_directory(), 900 900 ), 901 901 ); … … 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 ), 1157 ); 1140 // No trailing slashes. 1141 $paths = array( 1142 'wordpress_size' => untrailingslashit( ABSPATH ), 1143 'themes_size' => get_theme_root(), 1144 'plugins_size' => WP_PLUGIN_DIR, 1145 'uploads_size' => $upload_dir['basedir'], 1146 ); 1147 1148 $exclude = $paths; 1149 unset( $exclude['wordpress_size'] ); 1150 $exclude = array_values( $exclude ); 1158 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 ( 'wordpress_size' === $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. … … 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']; 1193 } 1190 $results['raw'] = $dir_size; 1191 $results['size'] = size_format( $dir_size, 2 ); 1192 $results['debug'] = $results['size'] . " ({$dir_size} bytes)"; 1193 } 1194 1195 $all_sizes[ $name ] = $results; 1194 1196 } 1195 1197 … … 1198 1200 1199 1201 $all_sizes['database_size'] = array( 1202 'raw' => $size_db, 1200 1203 'size' => $database_size, 1201 'debug' => $database_size ,1204 'debug' => $database_size . " ({$size_db} bytes)", 1202 1205 ); 1203 1206 } else { … … 1209 1212 1210 1213 if ( null !== $size_total && $size_db > 0 ) { 1211 $total_size = size_format( $size_total + $size_db, 2 ); 1214 $total_size = $size_total + $size_db; 1215 $total_size_mb = size_format( $total_size, 2 ); 1212 1216 1213 1217 $all_sizes['total_size'] = array( 1214 'size' => $total_size, 1215 'debug' => $total_size, 1218 'raw' => $total_size, 1219 'size' => $total_size_mb, 1220 'debug' => $total_size_mb . " ({$total_size} bytes)", 1216 1221 ); 1217 1222 } else { -
trunk/src/wp-includes/functions.php
r45206 r45220 7072 7072 * @since 5.2.0 $max_execution_time parameter added. 7073 7073 * 7074 * @param string $directory Full path of a directory. 7075 * @param string $exclude Optional. Full path of a subdirectory to exclude from the total. 7076 * @param int $max_execution_time Maximum time to run before giving up. In seconds. 7077 * The timeout is global and is measured from the moment WordPress started to load. 7078 * @return int|false|null Size in MB if a valid directory. False if not. Null if timeout. 7074 * @param string $directory Full path of a directory. 7075 * @param string|array $exclude Optional. Full path of a subdirectory to exclude from the total, or array of paths. 7076 * Expected without trailing slash(es). 7077 * @param int $max_execution_time Maximum time to run before giving up. In seconds. 7078 * The timeout is global and is measured from the moment WordPress started to load. 7079 * @return int|false|null Size in bytes if a valid directory. False if not. Null if timeout. 7079 7080 */ 7080 7081 function recurse_dirsize( $directory, $exclude = null, $max_execution_time = null ) { … … 7083 7084 $directory = untrailingslashit( $directory ); 7084 7085 7085 if ( ! file_exists( $directory ) || ! is_dir( $directory ) || ! is_readable( $directory ) || $directory === $exclude ) { 7086 if ( ! file_exists( $directory ) || ! is_dir( $directory ) || ! is_readable( $directory ) ) { 7087 return false; 7088 } 7089 7090 if ( 7091 ( is_string( $exclude ) && $directory === $exclude ) || 7092 ( is_array( $exclude ) && in_array( $directory, $exclude, true ) ) 7093 ) { 7086 7094 return false; 7087 7095 }
Note: See TracChangeset
for help on using the changeset viewer.