Skip to content

Commit

Permalink
Multisite: Fix the new get_space_used() function to correctly calcula…
Browse files Browse the repository at this point in the history
…te Megabytes used and update some phpdoc. Props SergeyBiryukov.

git-svn-id: http://core.svn.wordpress.org/trunk@21474 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
westi committed Aug 8, 2012
1 parent f02bacd commit c702fe6
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions wp-admin/includes/ms.php
Expand Up @@ -302,6 +302,8 @@ function upload_size_limit_filter( $size ) {
/**
* Determines if there is any upload space left in the current blog's quota.
*
* @since 3.0.0
*
* @return int of upload space available in bytes
*/
function get_upload_space_available() {
Expand Down Expand Up @@ -331,11 +333,11 @@ function upload_is_user_over_quota( $echo = true ) {

$space_allowed = get_space_allowed();
if ( empty( $space_allowed ) || !is_numeric( $space_allowed ) )
$space_allowed = 10;// Default space allowed is 10 MB
$space_allowed = 10; // Default space allowed is 10 MB

$space_used = get_space_used();

if ( ($space_allowed - $space_used ) < 0 ) {
if ( ( $space_allowed - $space_used ) < 0 ) {
if ( $echo )
_e( 'Sorry, you have used your space allocation. Please delete some files to upload more files.' );
return true;
Expand All @@ -344,19 +346,28 @@ function upload_is_user_over_quota( $echo = true ) {
}
}

/**
* Returns the space used by the current blog.
*
* @since 3.5.0
*
* @return int Used space in megabytes
*/
function get_space_used() {
// Allow for an alternative way of tracking storage space used
$space_used = apply_filters( 'pre_get_space_used', false );
if ( false === $space_used )
$space_used = get_dirsize( BLOGUPLOADDIR );
$space_used = get_dirsize( BLOGUPLOADDIR ) / 1024 / 1024;

return $space_used;
}

/**
* Returns the upload quota for the current blog.
*
* @return int Quota
* @since MU
*
* @return int Quota in megabytes
*/
function get_space_allowed() {
$space_allowed = get_option( 'blog_upload_space' );
Expand All @@ -370,6 +381,11 @@ function get_space_allowed() {
return $space_allowed;
}

/**
* Displays the amount of disk space used by the current blog. Not used in core.
*
* @since MU
*/
function display_space_usage() {
$space_allowed = get_space_allowed();
$space_used = get_space_used();
Expand Down Expand Up @@ -406,7 +422,7 @@ function fix_import_form_size( $size ) {
return 0;

$available = get_upload_space_available();
return min( $size, $available);
return min( $size, $available );
}

// Edit blog upload space setting on Edit Blog page
Expand Down

0 comments on commit c702fe6

Please sign in to comment.