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%.
Opens WPIDE on
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
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.