Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 121 additions & 1 deletion src/wp-admin/includes/class-wp-debug-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,73 @@
'value' => $loading,
'debug' => 'loading...',
),
);

// Add individual plugin size fields.
if ( is_dir( WP_PLUGIN_DIR ) ) {
$plugins = get_plugins();
$plugin_fields = array();

foreach ( $plugins as $plugin_path => $plugin_data ) {
// Get the plugin directory name (slug).
$plugin_dir = dirname( $plugin_path );
if ( '.' === $plugin_dir ) {
// Single file plugin, skip.
continue;
}

$plugin_slug = sanitize_file_name( $plugin_dir );
$plugin_key = 'plugin_' . $plugin_slug . '_size';

// Skip if we already added this plugin.
if ( isset( $plugin_fields[ $plugin_key ] ) ) {
continue;
}

// Use lowercase plugin slug for display (as shown in example).
$plugin_display_name = strtolower( $plugin_slug );

$plugin_fields[ $plugin_key ] = array(
'plugin_name' => $plugin_display_name, // Store for sorting.
'plugin_slug' => $plugin_slug, // Store slug for reference.
'label' => $plugin_display_name, // Will be formatted in display.
'value' => $loading,
'debug' => 'loading...',
'is_plugin_individual' => true, // Mark as individual plugin field.
);
}

// Sort plugins by name for consistent display.
uasort( $plugin_fields, function( $a, $b ) {

Check failure on line 911 in src/wp-admin/includes/class-wp-debug-data.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Expected 1 space after FUNCTION keyword; 0 found

Check failure on line 911 in src/wp-admin/includes/class-wp-debug-data.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Only one argument is allowed per line in a multi-line function call

Check failure on line 911 in src/wp-admin/includes/class-wp-debug-data.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Opening parenthesis of a multi-line function call must be the last content on the line
return strcasecmp( $a['plugin_name'], $b['plugin_name'] );
} );

Check failure on line 913 in src/wp-admin/includes/class-wp-debug-data.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Closing parenthesis of a multi-line function call must be on a line by itself

// Add "Plugins (individual)" header before plugin fields.
$plugins_individual_header = array(
'plugins_individual_header' => array(
'label' => 'Plugins (individual)',
'value' => '',
'debug' => '',
'is_plugins_header' => true, // Mark as header field.
),
);

// Remove temporary plugin_name key and format labels with tree characters.
$plugin_count = count( $plugin_fields );
$index = 0;
foreach ( $plugin_fields as $key => $field ) {
$index++;
$is_last = ( $index === $plugin_count );
$tree_char = $is_last ? '└─' : '├─';
$plugin_fields[ $key ]['label'] = ' ' . $tree_char . ' ' . $field['plugin_name'];
unset( $plugin_fields[ $key ]['plugin_name'] );
}

// Merge header and plugin fields.
$fields = array_merge( $fields, $plugins_individual_header, $plugin_fields );
}

$fields = array_merge( $fields, array(

Check failure on line 940 in src/wp-admin/includes/class-wp-debug-data.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Whitespace found at end of line

Check failure on line 940 in src/wp-admin/includes/class-wp-debug-data.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Spaces must be used for mid-line alignment; tabs are not allowed

Check failure on line 940 in src/wp-admin/includes/class-wp-debug-data.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Only one argument is allowed per line in a multi-line function call

Check failure on line 940 in src/wp-admin/includes/class-wp-debug-data.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Opening parenthesis of a multi-line function call must be the last content on the line
'fonts_path' => array(
'label' => __( 'Fonts directory location' ),
'value' => wp_get_font_dir()['basedir'],
Expand All @@ -890,7 +957,7 @@
'value' => $loading,
'debug' => 'loading...',
),
);
) );

return array(
/* translators: Filesystem directory paths and storage sizes. */
Expand Down Expand Up @@ -1994,6 +2061,59 @@
$all_sizes[ $name ] = $results;
}

// Calculate individual plugin sizes.
if ( isset( $all_sizes['plugins_size'] ) && is_dir( WP_PLUGIN_DIR ) ) {
$plugins = get_plugins();
$plugin_sizes = array();

foreach ( $plugins as $plugin_path => $plugin_data ) {
// Get the plugin directory name (slug).
$plugin_dir = dirname( $plugin_path );
if ( '.' === $plugin_dir ) {
// Single file plugin, skip as it's already counted in plugins_size.
continue;
}

$plugin_dir_path = WP_PLUGIN_DIR . '/' . $plugin_dir;
$plugin_slug = sanitize_file_name( $plugin_dir );
$plugin_key = 'plugin_' . $plugin_slug . '_size';

// Skip if we already calculated this plugin size.
if ( isset( $plugin_sizes[ $plugin_key ] ) ) {
continue;
}

$plugin_dir_size = null;
$plugin_results = array(
'path' => $plugin_dir_path,
'raw' => 0,
);

// Only calculate if we still have time.
if ( microtime( true ) - WP_START_TIMESTAMP < $max_execution_time ) {
$plugin_dir_size = recurse_dirsize( $plugin_dir_path, null, $max_execution_time );
}

if ( false === $plugin_dir_size ) {
$plugin_results['size'] = __( 'The size cannot be calculated. The directory is not accessible.' );
$plugin_results['debug'] = 'not accessible';
} elseif ( null === $plugin_dir_size ) {
$plugin_results['size'] = __( 'The directory size calculation has timed out.' );
$plugin_results['debug'] = 'timeout while calculating size';
} else {
$plugin_results['raw'] = $plugin_dir_size;
$plugin_results['size'] = size_format( $plugin_dir_size, 2 );
$plugin_results['debug'] = $plugin_results['size'] . " ({$plugin_dir_size} bytes)";
}

$plugin_sizes[ $plugin_key ] = $plugin_results;
}

// Merge plugin sizes into all_sizes, sorted by plugin name.
ksort( $plugin_sizes );
$all_sizes = array_merge( $all_sizes, $plugin_sizes );
}

if ( $size_db > 0 ) {
$database_size = size_format( $size_db, 2 );

Expand Down
40 changes: 37 additions & 3 deletions src/wp-admin/site-health-info.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,18 @@
<div id="health-check-debug" class="health-check-accordion">

<?php

// Build sizes_fields array to include all plugin size fields dynamically.
$sizes_fields = array( 'uploads_size', 'themes_size', 'plugins_size', 'fonts_size', 'wordpress_size', 'database_size', 'total_size' );

// Add individual plugin size fields if they exist in the info data.
if ( isset( $info['wp-paths-sizes'] ) && isset( $info['wp-paths-sizes']['fields'] ) ) {
foreach ( $info['wp-paths-sizes']['fields'] as $field_name => $field ) {
if ( strpos( $field_name, 'plugin_' ) === 0 && strpos( $field_name, '_size' ) !== false ) {
$sizes_fields[] = $field_name;
}
}
}

foreach ( $info as $section => $details ) {
if ( ! isset( $details['fields'] ) || empty( $details['fields'] ) ) {
continue;
Expand Down Expand Up @@ -113,6 +122,17 @@
<?php

foreach ( $details['fields'] as $field_name => $field ) {
// Check if this is the plugins individual header.
if ( isset( $field['is_plugins_header'] ) && $field['is_plugins_header'] ) {
// Format header with tree character.
$header_label = ' ├─ ' . esc_html( $field['label'] );
printf( '<tr><th scope="row">%s</th><td></td></tr>', $header_label );
continue;
}

// Check if this is an individual plugin field.
$is_plugin_individual = isset( $field['is_plugin_individual'] ) && $field['is_plugin_individual'];

Check failure on line 135 in src/wp-admin/site-health-info.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Whitespace found at end of line
if ( is_array( $field['value'] ) ) {
$values = '<ul>';

Expand All @@ -125,10 +145,24 @@
$values = esc_html( $field['value'] );
}

// Format plugin individual fields: show plugin name with tree character in label, "plugin_name: size" in value.
if ( $is_plugin_individual ) {
// Label already has tree character and plugin name from class-wp-debug-data.php.
$label = esc_html( $field['label'] );
// Format value as "plugin_name: size" if we have a size value.
if ( ! empty( $values ) && $values !== esc_html( __( 'Loading&hellip;' ) ) ) {

Check failure on line 153 in src/wp-admin/site-health-info.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Use Yoda Condition checks, you must.
// Extract plugin name from label (remove tree characters and spaces).
$plugin_name = preg_replace( '/^\s*[├└]─\s*/', '', $field['label'] );
$values = esc_html( $plugin_name ) . ': ' . $values;
}
} else {
$label = esc_html( $field['label'] );
}

if ( in_array( $field_name, $sizes_fields, true ) ) {
printf( '<tr><th scope="row">%s</th><td class="%s">%s</td></tr>', esc_html( $field['label'] ), esc_attr( $field_name ), $values );
printf( '<tr><th scope="row">%s</th><td class="%s">%s</td></tr>', $label, esc_attr( $field_name ), $values );
} else {
printf( '<tr><th scope="row">%s</th><td>%s</td></tr>', esc_html( $field['label'] ), $values );
printf( '<tr><th scope="row">%s</th><td>%s</td></tr>', $label, $values );
}
}

Expand Down
Loading