Halloween Sale 15% off Ends in See the plans
PHP

Storage Used Column in the Network Sites List

Shows how much upload space each site uses next to its quota in Network Admin > Sites, highlighting sites that are close to the limit.

Don’t have WPIDE yet? Install it on your site

Code

if ( ! is_multisite() ) {
    return;
}

$wpide_warn_at = 80; // Highlight sites using more than this percentage of their quota.

add_filter( 'wpmu_blogs_columns', function ( $columns ) {
    $columns['wpide_storage'] = __( 'Storage' );

    return $columns;
} );

add_action( 'manage_sites_custom_column', function ( $column, $blog_id ) use ( $wpide_warn_at ) {
    if ( 'wpide_storage' !== $column ) {
        return;
    }

    switch_to_blog( $blog_id );
    $used    = (float) get_space_used();
    $allowed = (float) get_space_allowed();
    restore_current_blog();

    if ( get_site_option( 'upload_space_check_disabled' ) || $allowed <= 0 ) {
        echo esc_html( size_format( (int) ( $used * MB_IN_BYTES ), 1 ) );
        return;
    }

    $percent = min( 100, round( $used / $allowed * 100 ) );
    $style   = $percent >= $wpide_warn_at ? ' style="color:#b32d2e;font-weight:600"' : '';

    printf(
        '<span%1$s>%2$s / %3$s (%4$d%%)</span>',
        $style, // phpcs:ignore WordPress.Security.EscapeOutput -- static markup.
        esc_html( size_format( (int) ( $used * MB_IN_BYTES ), 1 ) ),
        esc_html( size_format( (int) ( $allowed * MB_IN_BYTES ) ) ),
        (int) $percent
    );
}, 10, 2 );

Notes

Disk usage is computed by WordPress and cached per site; sites with uploads unlimited show only the used size.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.