WordPress.org

Make WordPress Core

Changeset 22497


Ignore:
Timestamp:
11/09/2012 10:35:42 AM (9 years ago)
Author:
westi
Message:

Multisite: Move all the functions which calculate upload space usage to wp-includes so they apply correctly with front-end editors.

Fixes #22357 props wonderboymusic.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/ms.php

    r22378 r22497  
    291291
    292292/**
    293  * @since 3.0.0
    294  *
    295  * @return int of upload size limit in bytes
    296  */
    297 function upload_size_limit_filter( $size ) {
    298     $fileupload_maxk = 1024 * get_site_option( 'fileupload_maxk', 1500 );
    299     if ( get_site_option( 'upload_space_check_disabled' ) )
    300         return min( $size, $fileupload_maxk );
    301 
    302     return min( $size, $fileupload_maxk, get_upload_space_available() );
    303 }
    304 /**
    305  * Determines if there is any upload space left in the current blog's quota.
    306  *
    307  * @since 3.0.0
    308  *
    309  * @return int of upload space available in bytes
    310  */
    311 function get_upload_space_available() {
    312     $space_allowed = get_space_allowed() * 1024 * 1024;
    313     if ( get_site_option( 'upload_space_check_disabled' ) )
    314         return $space_allowed;
    315 
    316     $space_used = get_space_used() * 1024 * 1024;
    317 
    318     if ( ( $space_allowed - $space_used ) <= 0 )
    319         return 0;
    320 
    321     return $space_allowed - $space_used;
    322 }
    323 
    324 /**
    325293 * Check whether a blog has used its allotted upload space.
    326294 *
     
    347315        return false;
    348316    }
    349 }
    350 
    351 /**
    352  * Returns the space used by the current blog.
    353  *
    354  * @since 3.5.0
    355  *
    356  * @return int Used space in megabytes
    357  */
    358 function get_space_used() {
    359     // Allow for an alternative way of tracking storage space used
    360     $space_used = apply_filters( 'pre_get_space_used', false );
    361     if ( false === $space_used ) {
    362         $upload_dir = wp_upload_dir();
    363         $space_used = get_dirsize( $upload_dir['basedir'] ) / 1024 / 1024;
    364     }
    365 
    366     return $space_used;
    367 }
    368 
    369 /**
    370  * Returns the upload quota for the current blog.
    371  *
    372  * @since MU
    373  *
    374  * @return int Quota in megabytes
    375  */
    376 function get_space_allowed() {
    377     $space_allowed = get_option( 'blog_upload_space' );
    378 
    379     if ( ! is_numeric( $space_allowed ) )
    380         $space_allowed = get_site_option( 'blog_upload_space' );
    381 
    382     if ( empty( $space_allowed ) || ! is_numeric( $space_allowed ) )
    383         $space_allowed = 50;
    384 
    385     return $space_allowed;
    386317}
    387318
  • trunk/wp-includes/ms-functions.php

    r22461 r22497  
    19301930    update_site_option( 'user_count', $count );
    19311931}
     1932
     1933/**
     1934 * Returns the space used by the current blog.
     1935 *
     1936 * @since 3.5.0
     1937 *
     1938 * @return int Used space in megabytes
     1939 */
     1940function get_space_used() {
     1941    // Allow for an alternative way of tracking storage space used
     1942    $space_used = apply_filters( 'pre_get_space_used', false );
     1943    if ( false === $space_used ) {
     1944        $upload_dir = wp_upload_dir();
     1945        $space_used = get_dirsize( $upload_dir['basedir'] ) / 1024 / 1024;
     1946    }
     1947
     1948    return $space_used;
     1949}
     1950
     1951/**
     1952 * Returns the upload quota for the current blog.
     1953 *
     1954 * @since MU
     1955 *
     1956 * @return int Quota in megabytes
     1957 */
     1958function get_space_allowed() {
     1959    $space_allowed = get_option( 'blog_upload_space' );
     1960
     1961    if ( ! is_numeric( $space_allowed ) )
     1962        $space_allowed = get_site_option( 'blog_upload_space' );
     1963
     1964    if ( empty( $space_allowed ) || ! is_numeric( $space_allowed ) )
     1965        $space_allowed = 50;
     1966
     1967    return $space_allowed;
     1968}
     1969
     1970/**
     1971 * Determines if there is any upload space left in the current blog's quota.
     1972 *
     1973 * @since 3.0.0
     1974 *
     1975 * @return int of upload space available in bytes
     1976 */
     1977function get_upload_space_available() {
     1978    $space_allowed = get_space_allowed() * 1024 * 1024;
     1979    if ( get_site_option( 'upload_space_check_disabled' ) )
     1980        return $space_allowed;
     1981
     1982    $space_used = get_space_used() * 1024 * 1024;
     1983
     1984    if ( ( $space_allowed - $space_used ) <= 0 )
     1985        return 0;
     1986
     1987    return $space_allowed - $space_used;
     1988}
     1989
     1990/**
     1991 * @since 3.0.0
     1992 *
     1993 * @return int of upload size limit in bytes
     1994 */
     1995function upload_size_limit_filter( $size ) {
     1996    $fileupload_maxk = 1024 * get_site_option( 'fileupload_maxk', 1500 );
     1997    if ( get_site_option( 'upload_space_check_disabled' ) )
     1998        return min( $size, $fileupload_maxk );
     1999
     2000    return min( $size, $fileupload_maxk, get_upload_space_available() );
     2001}
Note: See TracChangeset for help on using the changeset viewer.