• Resolved DJABHipHop

    (@pressthemes1)


    Requesting the addition of a “Size” column to the WordPress Plugins admin page to provide users with detailed insights into the storage footprint of each installed plugin.Proposed Functionality

    1. New Column for Plugin Size
      Introduce a custom “Size” column to display the total size of each plugin’s directory in human-readable format (e.g., KB, MB).
    2. Column Data Calculation
      • Use the server’s file system to calculate the total size of each plugin directory within the wp-content/plugins directory.
      • Display the calculated size in the new column using appropriate formatting.
    3. Custom Styling
      • Adjust the column width to fit the content properly (e.g., 7rem width).
      • Ensure the column aligns seamlessly with existing columns in the admin interface.

    Benefits

    • Transparency: Provides administrators with a quick overview of how much disk space each plugin consumes.
    • Efficiency: Helps identify resource-heavy plugins that may require optimization or removal.
    • User Experience: Enhances the Plugins page with actionable information that improves site management.

    Mock Implementation

    • Add a new column using the manage_plugins_columns filter.
    • Populate the column with the calculated size using the manage_plugins_custom_column action.
    • Include a helper function to calculate the folder size using PHP’s RecursiveDirectoryIterator.
    • Add lightweight CSS directly to the Plugins page to ensure proper alignment and display.

    Example Code

    function custom_plugins_columns( $columns ) {
    $columns['plugin_size'] = __( 'Size', 'text-domain' );
    return $columns;
    }
    add_filter( 'manage_plugins_columns', 'custom_plugins_columns' );

    function custom_plugins_column_content( $column_name, $plugin_file ) {
    if ( 'plugin_size' === $column_name ) {
    $plugin_dir = WP_PLUGIN_DIR . '/' . dirname( $plugin_file );
    $size_in_bytes = folder_size( $plugin_dir );
    $size = size_format( $size_in_bytes );
    echo esc_html( $size );
    }
    }
    add_action( 'manage_plugins_custom_column', 'custom_plugins_column_content', 10, 2 );

    function folder_size( $dir ) {
    $size = 0;
    if ( is_dir( $dir ) ) {
    foreach ( new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $dir, FilesystemIterator::SKIP_DOTS ) ) as $file ) {
    $size += $file->getSize();
    }
    }
    return $size;
    }

    function custom_plugins_page_styles() {
    echo '<style>.column-plugin_size { width: 7rem; }</style>';
    }
    add_action( 'admin_head', 'custom_plugins_page_styles' );
    • This topic was modified 3 months ago by DJABHipHop.
Viewing 1 replies (of 1 total)
  • Plugin Author Bowo

    (@qriouslad)

    @pressthemes1 thanks for the detailed suggestion. However, I have never needed a feature like this in the many years developing for WordPress. I’ve also never had any issue with a plugin folder size getting big. Maybe when they store something in the /uploads/ folder, e.g. backup files, but not in the /plugins/ folder. On the other hand, https://www.ads-software.com/plugins/disk-usage-sunburst/ might be sufficient for achieving what you suggested every once in a while / as needed.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.