diff --git a/wp-admin/includes/ms.php b/wp-admin/includes/ms.php index d1651d1bb..80d5c9cd6 100644 --- a/wp-admin/includes/ms.php +++ b/wp-admin/includes/ms.php @@ -399,11 +399,28 @@ function is_upload_space_available() { if ( get_site_option( 'upload_space_check_disabled' ) ) return true; - $space_allowed = get_space_allowed(); + if ( !( $space_allowed = get_upload_space_available() ) ) + return false; + + return true; +} + +function upload_size_limit_filter( $size ) { + return min( $size, get_upload_space_available() ); +} +/** + * Determines if there is any upload space left in the current blog's quota. + * + * @return int of upload space available in bytes + */ +function get_upload_space_available() { + $space_allowed = get_space_allowed() * 1024 * 1024; + if ( get_site_option( 'upload_space_check_disabled' ) ) + return $space_allowed; $dir_name = trailingslashit( BLOGUPLOADDIR ); if ( !( is_dir( $dir_name) && is_readable( $dir_name ) ) ) - return true; + return $space_allowed; $dir = dir( $dir_name ); $size = 0; @@ -418,12 +435,11 @@ function is_upload_space_available() { } } $dir->close(); - $size = $size / 1024 / 1024; if ( ( $space_allowed - $size ) <= 0 ) - return false; + return 0; - return true; + return $space_allowed - $size; } /** diff --git a/wp-includes/ms-default-filters.php b/wp-includes/ms-default-filters.php index 2f5854087..47d4d4e3a 100644 --- a/wp-includes/ms-default-filters.php +++ b/wp-includes/ms-default-filters.php @@ -45,6 +45,7 @@ add_filter( 'wp_upload_bits', 'upload_is_file_too_big' ); add_filter( 'import_upload_size_limit', 'fix_import_form_size' ); add_filter( 'upload_mimes', 'check_upload_mimes' ); add_action( 'admin_notices', 'ms_deprecated_blogs_file' ); +add_action( 'upload_size_limit', 'upload_size_limit_filter' ); // Mail add_filter( 'wp_mail_from', 'wordpressmu_wp_mail_from' );