Make WordPress Core


Ignore:
Timestamp:
08/01/2012 01:52:06 PM (12 years ago)
Author:
westi
Message:

Multisite: Rework the upload space usage tracking code so as to be fully pluggable.

  • Moves some admin only functions into wp-admin/includes/ms.php from wp-includes/ms-functions.php
  • Reworked the variable naming to be more in line with the Coding Standards
  • Introduced a new get_space_used() function instead of calculating it in multiple places.

Fixes #21181 props dllh and jkudish for inital work on this.

File:
1 edited

Legend:

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

    r21237 r21387  
    14601460
    14611461/**
    1462  * Check whether a blog has used its allotted upload space.
    1463  *
    1464  * @since MU
    1465  * @uses get_dirsize()
    1466  *
    1467  * @param bool $echo Optional. If $echo is set and the quota is exceeded, a warning message is echoed. Default is true.
    1468  * @return int
    1469  */
    1470 function upload_is_user_over_quota( $echo = true ) {
    1471     if ( get_site_option( 'upload_space_check_disabled' ) )
    1472         return false;
    1473 
    1474     $spaceAllowed = get_space_allowed();
    1475     if ( empty( $spaceAllowed ) || !is_numeric( $spaceAllowed ) )
    1476         $spaceAllowed = 10; // Default space allowed is 10 MB
    1477 
    1478     $size = get_dirsize( BLOGUPLOADDIR ) / 1024 / 1024;
    1479 
    1480     if ( ($spaceAllowed-$size) < 0 ) {
    1481         if ( $echo )
    1482             _e( 'Sorry, you have used your space allocation. Please delete some files to upload more files.' ); // No space left
    1483         return true;
    1484     } else {
    1485         return false;
    1486     }
    1487 }
    1488 
    1489 /**
    14901462 * Check an array of MIME types against a whitelist.
    14911463 *
     
    15391511    $user = new WP_User( (int) $user_id );
    15401512    $wpdb->insert( $wpdb->registration_log, array('email' => $user->user_email, 'IP' => preg_replace( '/[^0-9., ]/', '',$_SERVER['REMOTE_ADDR'] ), 'blog_id' => $blog_id, 'date_registered' => current_time('mysql')) );
    1541 }
    1542 
    1543 /**
    1544  * Get the remaining upload space for this blog.
    1545  *
    1546  * @since MU
    1547  * @uses upload_is_user_over_quota()
    1548  * @uses get_space_allowed()
    1549  * @uses get_dirsize()
    1550  *
    1551  * @param int $size
    1552  * @return int
    1553  */
    1554 function fix_import_form_size( $size ) {
    1555     if ( upload_is_user_over_quota( false ) == true )
    1556         return 0;
    1557 
    1558     $spaceAllowed = 1024 * 1024 * get_space_allowed();
    1559     $dirsize = get_dirsize( BLOGUPLOADDIR );
    1560     if ( $size > $spaceAllowed - $dirsize )
    1561         return $spaceAllowed - $dirsize; // remaining space
    1562     else
    1563         return $size; // default
    15641513}
    15651514
Note: See TracChangeset for help on using the changeset viewer.