Avoid an undefined offset notice in wp_convert_bytes_to_hr(). props soulseekah. fixes #23626.

git-svn-id: http://core.svn.wordpress.org/trunk@23502 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2013-02-28 05:25:15 +00:00
parent b6e33d56f9
commit 0cff4a5ea9

View File

@ -3377,9 +3377,18 @@ function gd_edit_image_support($mime_type) {
*/ */
function wp_convert_bytes_to_hr( $bytes ) { 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' ); $units = array( 0 => 'B', 1 => 'kB', 2 => 'MB', 3 => 'GB' );
$log = log( $bytes, 1024 ); $log = log( $bytes, 1024 );
$power = (int) $log; $power = (int) $log;
$size = pow( 1024, $log - $power );
return $size . $units[$power]; if ( array_key_exists( $power, $units ) ) {
$size = pow( 1024, $log - $power );
$unit = $units[ $power ];
} else {
$size = $bytes;
$unit = $units[0];
}
return $size . $unit;
} }