Feature Request: Add “Plugin Size” Column to the Plugins Page
-
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
- 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). - 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.
- Use the server’s file system to calculate the total size of each plugin directory within the
- 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.
- Adjust the column width to fit the content properly (e.g.,
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' ); - New Column for Plugin Size
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- You must be logged in to reply to this topic.