WordPress.org

Make WordPress Core

Changeset 45220


Ignore:
Timestamp:
04/16/2019 11:01:45 PM (4 months ago)
Author:
azaozz
Message:

Site health, info tab:

  • Change recurse_dirsize() to accept an array of excluded paths.
  • Change so we don't calculate the sizes of dirs in wp-content twice.
  • Add the size in bytes to the "debug" into.
  • Add a custom DOM event after the dir sizes request is done. Can be used by plugins to "daisy chain" more requests.
  • Move "WordPress directory location" and "WordPress directory size" to the top in the "Directories and Sizes" section.
  • Move "Theme directory location" to the "Active Theme" section.
  • Fix labels capitalization.

Props xkon, afercia, Clorith, azaozz.
Fixes #46707.

Location:
trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/admin/site-health.js

    r45198 r45220  
    277277                window.clearTimeout( timeout );
    278278            }
     279
     280            $( document ).trigger( 'site-health-info-dirsizes-done' );
    279281        } );
    280282    }
  • trunk/src/wp-admin/includes/ajax-actions.php

    r45190 r45220  
    49774977
    49784978    $sizes_data = WP_Debug_Data::get_sizes();
    4979     $all_sizes  = array();
     4979    $all_sizes  = array( 'raw' => 0 );
    49804980
    49814981    foreach ( $sizes_data as $name => $value ) {
     
    49994999        }
    50005000
     5001        if ( ! empty( $value['raw'] ) ) {
     5002            $data['raw'] = (int) $value['raw'];
     5003        }
     5004
    50015005        $all_sizes[ $name ] = $data;
    50025006    }
  • trunk/src/wp-admin/includes/class-wp-debug-data.php

    r45200 r45220  
    393393
    394394        $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' ),
    401401                'value' => $not_calculated,
    402402                'debug' => 'not calculated',
    403403            ),
    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' ),
    414410                'value' => $not_calculated,
    415411                'debug' => 'not calculated',
    416412            ),
    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' ),
    423419                'value' => $not_calculated,
    424420                'debug' => 'not calculated',
    425421            ),
    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' ),
    432428                'value' => $not_calculated,
    433429                'debug' => 'not calculated',
     
    898894                'label' => __( 'Theme features' ),
    899895                'value' => implode( ', ', $theme_features ),
     896            ),
     897            'theme_path'     => array(
     898                'label' => __( 'Theme directory location' ),
     899                'value' => get_template_directory(),
    900900            ),
    901901        );
     
    11381138
    11391139        // 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 );
    11581151
    11591152        $size_total = 0;
     1153        $all_sizes  = array();
    11601154
    11611155        // 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 ) {
    11631157            $dir_size = null; // Default to timeout.
     1158            $results  = array(
     1159                'path' => $path,
     1160                'raw'  => 0,
     1161            );
    11641162
    11651163            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                }
    11671169            }
    11681170
    11691171            if ( false === $dir_size ) {
    11701172                // 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';
    11731175
    11741176                // Stop total size calculation.
     
    11761178            } elseif ( null === $dir_size ) {
    11771179                // 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';
    11801182
    11811183                // Stop total size calculation.
    11821184                $size_total = null;
    11831185            } 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 ) {
    11881187                    $size_total += $dir_size;
    11891188                }
    11901189
    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;
    11941196        }
    11951197
     
    11981200
    11991201            $all_sizes['database_size'] = array(
     1202                'raw'   => $size_db,
    12001203                'size'  => $database_size,
    1201                 'debug' => $database_size,
     1204                'debug' => $database_size . " ({$size_db} bytes)",
    12021205            );
    12031206        } else {
     
    12091212
    12101213        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 );
    12121216
    12131217            $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)",
    12161221            );
    12171222        } else {
  • trunk/src/wp-includes/functions.php

    r45206 r45220  
    70727072 * @since 5.2.0 $max_execution_time parameter added.
    70737073 *
    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.
    70797080 */
    70807081function recurse_dirsize( $directory, $exclude = null, $max_execution_time = null ) {
     
    70837084    $directory = untrailingslashit( $directory );
    70847085
    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    ) {
    70867094        return false;
    70877095    }
Note: See TracChangeset for help on using the changeset viewer.