Halloween Sale 15% off Ends in See the plans
PHP

Show Upload Space Used in the Admin Bar

Shows site admins how much of their upload quota they have used, as a percentage in the toolbar, turning amber at 75% and red at 90%.

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

Code

if ( ! is_multisite() ) {
    return;
}

add_action( 'admin_bar_menu', function ( $bar ) {
    if ( ! is_admin() || ! current_user_can( 'upload_files' ) || get_site_option( 'upload_space_check_disabled' ) ) {
        return;
    }

    $allowed = (float) get_space_allowed();

    if ( $allowed <= 0 ) {
        return;
    }

    $used    = (float) get_space_used();
    $percent = min( 100, (int) round( $used / $allowed * 100 ) );
    $color   = $percent >= 90 ? '#f86368' : ( $percent >= 75 ? '#f0b849' : 'inherit' );

    $bar->add_node( array(
        'id'    => 'wpide-storage',
        'title' => sprintf( '<span style="color:%1$s">%2$s</span>', esc_attr( $color ), esc_html( sprintf( 'Storage %d%%', $percent ) ) ),
        'href'  => admin_url( 'upload.php' ),
        'meta'  => array(
            'title' => sprintf( '%1$s of %2$s used', size_format( (int) ( $used * MB_IN_BYTES ), 1 ), size_format( (int) ( $allowed * MB_IN_BYTES ) ) ),
        ),
    ) );
}, 90 );

Notes

Hidden when the network has upload space checks turned off.

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.