Filesystem: Following the introduction of the `KB|MB|GB|TB_IN_BYTES` constants in [35286], use them in various places in core.
Props sudar. Fixes #22405. Built from https://develop.svn.wordpress.org/trunk@35325 git-svn-id: http://core.svn.wordpress.org/trunk@35291 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
6a51505a23
commit
81524f3bfc
|
@ -28,13 +28,18 @@ function check_upload_size( $file ) {
|
||||||
$space_left = get_upload_space_available();
|
$space_left = get_upload_space_available();
|
||||||
|
|
||||||
$file_size = filesize( $file['tmp_name'] );
|
$file_size = filesize( $file['tmp_name'] );
|
||||||
if ( $space_left < $file_size )
|
if ( $space_left < $file_size ) {
|
||||||
$file['error'] = sprintf( __( 'Not enough space to upload. %1$s KB needed.' ), number_format( ($file_size - $space_left) /1024 ) );
|
$file['error'] = sprintf( __( 'Not enough space to upload. %1$s KB needed.' ), number_format( ( $file_size - $space_left ) / KB_IN_BYTES ) );
|
||||||
if ( $file_size > ( 1024 * get_site_option( 'fileupload_maxk', 1500 ) ) )
|
}
|
||||||
$file['error'] = sprintf(__('This file is too big. Files must be less than %1$s KB in size.'), get_site_option( 'fileupload_maxk', 1500 ) );
|
|
||||||
|
if ( $file_size > ( KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 ) ) ) {
|
||||||
|
$file['error'] = sprintf( __( 'This file is too big. Files must be less than %1$s KB in size.' ), get_site_option( 'fileupload_maxk', 1500 ) );
|
||||||
|
}
|
||||||
|
|
||||||
if ( upload_is_user_over_quota( false ) ) {
|
if ( upload_is_user_over_quota( false ) ) {
|
||||||
$file['error'] = __( 'You have used your space quota. Please delete files before uploading.' );
|
$file['error'] = __( 'You have used your space quota. Please delete files before uploading.' );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $file['error'] != '0' && ! isset( $_POST['html-upload'] ) && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
|
if ( $file['error'] != '0' && ! isset( $_POST['html-upload'] ) && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
|
||||||
wp_die( $file['error'] . ' <a href="javascript:history.go(-1)">' . __( 'Back' ) . '</a>' );
|
wp_die( $file['error'] . ' <a href="javascript:history.go(-1)">' . __( 'Back' ) . '</a>' );
|
||||||
}
|
}
|
||||||
|
@ -443,7 +448,7 @@ function display_space_usage() {
|
||||||
$percent_used = ( $space_used / $space_allowed ) * 100;
|
$percent_used = ( $space_used / $space_allowed ) * 100;
|
||||||
|
|
||||||
if ( $space_allowed > 1000 ) {
|
if ( $space_allowed > 1000 ) {
|
||||||
$space = number_format( $space_allowed / 1024 );
|
$space = number_format( $space_allowed / KB_IN_BYTES );
|
||||||
/* translators: Gigabytes */
|
/* translators: Gigabytes */
|
||||||
$space .= __( 'GB' );
|
$space .= __( 'GB' );
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -691,7 +691,7 @@ class WP_Object_Cache {
|
||||||
echo "</p>";
|
echo "</p>";
|
||||||
echo '<ul>';
|
echo '<ul>';
|
||||||
foreach ($this->cache as $group => $cache) {
|
foreach ($this->cache as $group => $cache) {
|
||||||
echo "<li><strong>Group:</strong> $group - ( " . number_format( strlen( serialize( $cache ) ) / 1024, 2 ) . 'k )</li>';
|
echo "<li><strong>Group:</strong> $group - ( " . number_format( strlen( serialize( $cache ) ) / KB_IN_BYTES, 2 ) . 'k )</li>';
|
||||||
}
|
}
|
||||||
echo '</ul>';
|
echo '</ul>';
|
||||||
}
|
}
|
||||||
|
|
|
@ -3284,9 +3284,9 @@ function wp_convert_bytes_to_hr( $bytes ) {
|
||||||
_deprecated_function( __FUNCTION__, '3.6', 'size_format()' );
|
_deprecated_function( __FUNCTION__, '3.6', 'size_format()' );
|
||||||
|
|
||||||
$units = array( 0 => 'B', 1 => 'kB', 2 => 'MB', 3 => 'GB', 4 => 'TB' );
|
$units = array( 0 => 'B', 1 => 'kB', 2 => 'MB', 3 => 'GB', 4 => 'TB' );
|
||||||
$log = log( $bytes, 1024 );
|
$log = log( $bytes, KB_IN_BYTES );
|
||||||
$power = (int) $log;
|
$power = (int) $log;
|
||||||
$size = pow( 1024, $log - $power );
|
$size = pow( KB_IN_BYTES, $log - $power );
|
||||||
|
|
||||||
if ( ! is_nan( $size ) && array_key_exists( $power, $units ) ) {
|
if ( ! is_nan( $size ) && array_key_exists( $power, $units ) ) {
|
||||||
$unit = $units[ $power ];
|
$unit = $units[ $power ];
|
||||||
|
|
|
@ -210,12 +210,11 @@ function number_format_i18n( $number, $decimals = 0 ) {
|
||||||
*/
|
*/
|
||||||
function size_format( $bytes, $decimals = 0 ) {
|
function size_format( $bytes, $decimals = 0 ) {
|
||||||
$quant = array(
|
$quant = array(
|
||||||
// ========================= Origin ====
|
'TB' => TB_IN_BYTES,
|
||||||
'TB' => 1099511627776, // pow( 1024, 4)
|
'GB' => GB_IN_BYTES,
|
||||||
'GB' => 1073741824, // pow( 1024, 3)
|
'MB' => MB_IN_BYTES,
|
||||||
'MB' => 1048576, // pow( 1024, 2)
|
'kB' => KB_IN_BYTES,
|
||||||
'kB' => 1024, // pow( 1024, 1)
|
'B' => 1,
|
||||||
'B' => 1, // pow( 1024, 0)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ( $quant as $unit => $mag ) {
|
foreach ( $quant as $unit => $mag ) {
|
||||||
|
|
|
@ -2638,11 +2638,11 @@ function wp_convert_hr_to_bytes( $size ) {
|
||||||
$size = strtolower( $size );
|
$size = strtolower( $size );
|
||||||
$bytes = (int) $size;
|
$bytes = (int) $size;
|
||||||
if ( strpos( $size, 'k' ) !== false )
|
if ( strpos( $size, 'k' ) !== false )
|
||||||
$bytes = intval( $size ) * 1024;
|
$bytes = intval( $size ) * KB_IN_BYTES;
|
||||||
elseif ( strpos( $size, 'm' ) !== false )
|
elseif ( strpos( $size, 'm' ) !== false )
|
||||||
$bytes = intval($size) * 1024 * 1024;
|
$bytes = intval($size) * MB_IN_BYTES;
|
||||||
elseif ( strpos( $size, 'g' ) !== false )
|
elseif ( strpos( $size, 'g' ) !== false )
|
||||||
$bytes = intval( $size ) * 1024 * 1024 * 1024;
|
$bytes = intval( $size ) * GB_IN_BYTES;
|
||||||
return $bytes;
|
return $bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1874,8 +1874,9 @@ function upload_is_file_too_big( $upload ) {
|
||||||
if ( ! is_array( $upload ) || defined( 'WP_IMPORTING' ) || get_site_option( 'upload_space_check_disabled' ) )
|
if ( ! is_array( $upload ) || defined( 'WP_IMPORTING' ) || get_site_option( 'upload_space_check_disabled' ) )
|
||||||
return $upload;
|
return $upload;
|
||||||
|
|
||||||
if ( strlen( $upload['bits'] ) > ( 1024 * get_site_option( 'fileupload_maxk', 1500 ) ) )
|
if ( strlen( $upload['bits'] ) > ( KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 ) ) ) {
|
||||||
return sprintf( __( 'This file is too big. Files must be less than %d KB in size.' ) . '<br />', get_site_option( 'fileupload_maxk', 1500 ));
|
return sprintf( __( 'This file is too big. Files must be less than %d KB in size.' ) . '<br />', get_site_option( 'fileupload_maxk', 1500 ) );
|
||||||
|
}
|
||||||
|
|
||||||
return $upload;
|
return $upload;
|
||||||
}
|
}
|
||||||
|
@ -2278,7 +2279,7 @@ function get_space_used() {
|
||||||
$space_used = apply_filters( 'pre_get_space_used', false );
|
$space_used = apply_filters( 'pre_get_space_used', false );
|
||||||
if ( false === $space_used ) {
|
if ( false === $space_used ) {
|
||||||
$upload_dir = wp_upload_dir();
|
$upload_dir = wp_upload_dir();
|
||||||
$space_used = get_dirsize( $upload_dir['basedir'] ) / 1024 / 1024;
|
$space_used = get_dirsize( $upload_dir['basedir'] ) / MB_IN_BYTES;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $space_used;
|
return $space_used;
|
||||||
|
@ -2322,11 +2323,11 @@ function get_upload_space_available() {
|
||||||
if ( $allowed < 0 ) {
|
if ( $allowed < 0 ) {
|
||||||
$allowed = 0;
|
$allowed = 0;
|
||||||
}
|
}
|
||||||
$space_allowed = $allowed * 1024 * 1024;
|
$space_allowed = $allowed * MB_IN_BYTES;
|
||||||
if ( get_site_option( 'upload_space_check_disabled' ) )
|
if ( get_site_option( 'upload_space_check_disabled' ) )
|
||||||
return $space_allowed;
|
return $space_allowed;
|
||||||
|
|
||||||
$space_used = get_space_used() * 1024 * 1024;
|
$space_used = get_space_used() * MB_IN_BYTES;
|
||||||
|
|
||||||
if ( ( $space_allowed - $space_used ) <= 0 )
|
if ( ( $space_allowed - $space_used ) <= 0 )
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -2353,7 +2354,7 @@ function is_upload_space_available() {
|
||||||
* @return int of upload size limit in bytes
|
* @return int of upload size limit in bytes
|
||||||
*/
|
*/
|
||||||
function upload_size_limit_filter( $size ) {
|
function upload_size_limit_filter( $size ) {
|
||||||
$fileupload_maxk = 1024 * get_site_option( 'fileupload_maxk', 1500 );
|
$fileupload_maxk = KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 );
|
||||||
if ( get_site_option( 'upload_space_check_disabled' ) )
|
if ( get_site_option( 'upload_space_check_disabled' ) )
|
||||||
return min( $size, $fileupload_maxk );
|
return min( $size, $fileupload_maxk );
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.4-alpha-35324';
|
$wp_version = '4.4-alpha-35325';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue