Warn Site Admins Before They Run Out of Upload Space
Shows an admin notice on the Media screens and the dashboard once a site has used more than a set share of its upload quota, before uploads start failing.
Opens WPIDE on
Code
if ( ! is_multisite() ) {
return;
}
$wpide_threshold = 80; // Warn above this percentage.
add_action( 'admin_notices', function () use ( $wpide_threshold ) {
$screen = get_current_screen();
if ( ! $screen || ! in_array( $screen->id, array( 'dashboard', 'upload', 'media' ), true ) || ! current_user_can( 'upload_files' ) || get_site_option( 'upload_space_check_disabled' ) ) {
return;
}
$allowed = (float) get_space_allowed();
$used = (float) get_space_used();
if ( $allowed <= 0 || ( $used / $allowed * 100 ) < $wpide_threshold ) {
return;
}
printf(
'<div class="notice notice-warning"><p>%s</p></div>',
esc_html( sprintf(
'This site has used %1$d%% of its upload space (%2$s left). Delete unused media or ask the network administrator for more space.',
min( 100, round( $used / $allowed * 100 ) ),
size_format( (int) ( max( 0, $allowed - $used ) * MB_IN_BYTES ), 1 )
) )
);
} );
Notes
Change $wpide_threshold (percent). The message includes the remaining space.
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.