Make WordPress Core

Changeset 59175


Ignore:
Timestamp:
10/05/2024 04:26:17 PM (16 months ago)
Author:
dmsnell
Message:

WP_Debug_Data: Extract wp-paths-sizes data into separate methods.

This is the tenth part in a larger modularization of the data in WP_Debug_Data. Previously this was a single massive method drawing in debug data from various groups of related data, where the groups were independent from each other.

This patch separates the eleventh of twelve groups, the wp-paths-sizes info, into a separate method focused on that data.

This work precedes changes to make the WP_Debug_Data class more extensible for better use by plugin and theme code.

Developed in https://github.com/wordpress/wordpress-develop/pull/7445
Discussed in https://core.trac.wordpress.org/ticket/61648

Props apermo, dmsnell.
See #61648.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-debug-data.php

    r59174 r59175  
    5757        $info = array(
    5858            'wp-core'             => self::get_wp_core(),
    59             'wp-paths-sizes'      => array(),
     59            'wp-paths-sizes'      => self::get_wp_paths_sizes(),
    6060            'wp-dropins'          => self::get_wp_dropins(),
    6161            'wp-active-theme'     => array(),
     
    7272        );
    7373
    74         // Remove debug data which is only relevant on single-site installs.
    75         if ( is_multisite() ) {
    76             unset( $info['wp-paths-sizes'] );
    77         }
    78 
    79         if ( ! $is_multisite ) {
    80             $info['wp-paths-sizes'] = array(
    81                 /* translators: Filesystem directory paths and storage sizes. */
    82                 'label'  => __( 'Directories and Sizes' ),
    83                 'fields' => array(),
    84             );
    85         }
     74        /*
     75         * Remove null elements from the array. The individual methods are
     76         * allowed to return `null`, which communicates that the category
     77         * of debug data isn't relevant and shouldn't be passed through.
     78         */
     79        $info = array_filter(
     80            $info,
     81            static function ( $section ) {
     82                return isset( $section );
     83            }
     84        );
    8685
    8786        $info['wp-active-theme'] = array(
     
    10099            'fields'     => array(),
    101100        );
    102 
    103         // Remove accordion for Directories and Sizes if in Multisite.
    104         if ( ! $is_multisite ) {
    105             $loading = __( 'Loading…' );
    106 
    107             $info['wp-paths-sizes']['fields'] = array(
    108                 'wordpress_path' => array(
    109                     'label' => __( 'WordPress directory location' ),
    110                     'value' => untrailingslashit( ABSPATH ),
    111                 ),
    112                 'wordpress_size' => array(
    113                     'label' => __( 'WordPress directory size' ),
    114                     'value' => $loading,
    115                     'debug' => 'loading...',
    116                 ),
    117                 'uploads_path'   => array(
    118                     'label' => __( 'Uploads directory location' ),
    119                     'value' => $upload_dir['basedir'],
    120                 ),
    121                 'uploads_size'   => array(
    122                     'label' => __( 'Uploads directory size' ),
    123                     'value' => $loading,
    124                     'debug' => 'loading...',
    125                 ),
    126                 'themes_path'    => array(
    127                     'label' => __( 'Themes directory location' ),
    128                     'value' => get_theme_root(),
    129                 ),
    130                 'themes_size'    => array(
    131                     'label' => __( 'Themes directory size' ),
    132                     'value' => $loading,
    133                     'debug' => 'loading...',
    134                 ),
    135                 'plugins_path'   => array(
    136                     'label' => __( 'Plugins directory location' ),
    137                     'value' => WP_PLUGIN_DIR,
    138                 ),
    139                 'plugins_size'   => array(
    140                     'label' => __( 'Plugins directory size' ),
    141                     'value' => $loading,
    142                     'debug' => 'loading...',
    143                 ),
    144                 'fonts_path'     => array(
    145                     'label' => __( 'Fonts directory location' ),
    146                     'value' => wp_get_font_dir()['basedir'],
    147                 ),
    148                 'fonts_size'     => array(
    149                     'label' => __( 'Fonts directory size' ),
    150                     'value' => $loading,
    151                     'debug' => 'loading...',
    152                 ),
    153                 'database_size'  => array(
    154                     'label' => __( 'Database size' ),
    155                     'value' => $loading,
    156                     'debug' => 'loading...',
    157                 ),
    158                 'total_size'     => array(
    159                     'label' => __( 'Total installation size' ),
    160                     'value' => $loading,
    161                     'debug' => 'loading...',
    162                 ),
    163             );
    164         }
    165101
    166102        // Populate the section for the currently active theme.
     
    11341070
    11351071    /**
    1136      * Gets the WordPress plugins section of the debug data.
     1072     * Gets the WordPress MU plugins section of the debug data.
    11371073     *
    11381074     * @since 6.7.0
     
    11811117            'show_count' => true,
    11821118            'fields'     => $fields,
     1119        );
     1120    }
     1121
     1122    /**
     1123     * Gets the WordPress paths and sizes section of the debug data.
     1124     *
     1125     * @since 6.7.0
     1126     *
     1127     * @return array|null Paths and sizes debug data for single sites,
     1128     *                    otherwise `null` for multi-site installs.
     1129     */
     1130    private static function get_wp_paths_sizes(): ?array {
     1131        if ( is_multisite() ) {
     1132            return null;
     1133        }
     1134
     1135        $loading = __( 'Loading…' );
     1136
     1137        $fields = array(
     1138            'wordpress_path' => array(
     1139                'label' => __( 'WordPress directory location' ),
     1140                'value' => untrailingslashit( ABSPATH ),
     1141            ),
     1142            'wordpress_size' => array(
     1143                'label' => __( 'WordPress directory size' ),
     1144                'value' => $loading,
     1145                'debug' => 'loading...',
     1146            ),
     1147            'uploads_path'   => array(
     1148                'label' => __( 'Uploads directory location' ),
     1149                'value' => wp_upload_dir()['basedir'],
     1150            ),
     1151            'uploads_size'   => array(
     1152                'label' => __( 'Uploads directory size' ),
     1153                'value' => $loading,
     1154                'debug' => 'loading...',
     1155            ),
     1156            'themes_path'    => array(
     1157                'label' => __( 'Themes directory location' ),
     1158                'value' => get_theme_root(),
     1159            ),
     1160            'themes_size'    => array(
     1161                'label' => __( 'Themes directory size' ),
     1162                'value' => $loading,
     1163                'debug' => 'loading...',
     1164            ),
     1165            'plugins_path'   => array(
     1166                'label' => __( 'Plugins directory location' ),
     1167                'value' => WP_PLUGIN_DIR,
     1168            ),
     1169            'plugins_size'   => array(
     1170                'label' => __( 'Plugins directory size' ),
     1171                'value' => $loading,
     1172                'debug' => 'loading...',
     1173            ),
     1174            'fonts_path'     => array(
     1175                'label' => __( 'Fonts directory location' ),
     1176                'value' => wp_get_font_dir()['basedir'],
     1177            ),
     1178            'fonts_size'     => array(
     1179                'label' => __( 'Fonts directory size' ),
     1180                'value' => $loading,
     1181                'debug' => 'loading...',
     1182            ),
     1183            'database_size'  => array(
     1184                'label' => __( 'Database size' ),
     1185                'value' => $loading,
     1186                'debug' => 'loading...',
     1187            ),
     1188            'total_size'     => array(
     1189                'label' => __( 'Total installation size' ),
     1190                'value' => $loading,
     1191                'debug' => 'loading...',
     1192            ),
     1193        );
     1194
     1195        return array(
     1196            /* translators: Filesystem directory paths and storage sizes. */
     1197            'label'  => __( 'Directories and Sizes' ),
     1198            'fields' => $fields,
    11831199        );
    11841200    }
Note: See TracChangeset for help on using the changeset viewer.