Halloween Sale 15% off Ends in See the plans
PHP

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.

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

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

  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.