wp_convert_bytes_to_hr

The timeline below displays how wordpress function wp_convert_bytes_to_hr has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.3

/**
 * Converts an integer byte value to a shorthand byte value.
 *
 * @since 2.3.0
 * @deprecated 3.6.0 Use size_format()
 * @see size_format()
 *
 * @param int $bytes An integer byte value.
 * @return string A shorthand byte value.
 */
function wp_convert_bytes_to_hr($bytes)
{
    _deprecated_function(__FUNCTION__, '3.6.0', 'size_format()');
    $units = array(0 => 'B', 1 => 'KB', 2 => 'MB', 3 => 'GB', 4 => 'TB');
    $log = log($bytes, KB_IN_BYTES);
    $power = (int) $log;
    $size = KB_IN_BYTES ** ($log - $power);
    if (!is_nan($size) && array_key_exists($power, $units)) {
        $unit = $units[$power];
    } else {
        $size = $bytes;
        $unit = $units[0];
    }
    return $size . $unit;
}

WordPress Version: 4.6

/**
 * Converts an integer byte value to a shorthand byte value.
 *
 * @since 2.3.0
 * @deprecated 3.6.0 Use size_format()
 * @see size_format()
 *
 * @param int $bytes An integer byte value.
 * @return string A shorthand byte value.
 */
function wp_convert_bytes_to_hr($bytes)
{
    _deprecated_function(__FUNCTION__, '3.6.0', 'size_format()');
    $units = array(0 => 'B', 1 => 'KB', 2 => 'MB', 3 => 'GB', 4 => 'TB');
    $log = log($bytes, KB_IN_BYTES);
    $power = (int) $log;
    $size = pow(KB_IN_BYTES, $log - $power);
    if (!is_nan($size) && array_key_exists($power, $units)) {
        $unit = $units[$power];
    } else {
        $size = $bytes;
        $unit = $units[0];
    }
    return $size . $unit;
}

WordPress Version: 4.4

/**
 * Converts an integer byte value to a shorthand byte value.
 *
 * @since 2.3.0
 * @deprecated 3.6.0 Use size_format()
 * @see size_format()
 *
 * @param int $bytes An integer byte value.
 * @return string A shorthand byte value.
 */
function wp_convert_bytes_to_hr($bytes)
{
    _deprecated_function(__FUNCTION__, '3.6', 'size_format()');
    $units = array(0 => 'B', 1 => 'kB', 2 => 'MB', 3 => 'GB', 4 => 'TB');
    $log = log($bytes, KB_IN_BYTES);
    $power = (int) $log;
    $size = pow(KB_IN_BYTES, $log - $power);
    if (!is_nan($size) && array_key_exists($power, $units)) {
        $unit = $units[$power];
    } else {
        $size = $bytes;
        $unit = $units[0];
    }
    return $size . $unit;
}

WordPress Version: 3.7

/**
 * Converts an integer byte value to a shorthand byte value.
 *
 * @since 2.3.0
 * @deprecated 3.6.0
 * @deprecated Use size_format()
 *
 * @param int $bytes An integer byte value.
 * @return string A shorthand byte value.
 */
function wp_convert_bytes_to_hr($bytes)
{
    _deprecated_function(__FUNCTION__, '3.6', 'size_format()');
    $units = array(0 => 'B', 1 => 'kB', 2 => 'MB', 3 => 'GB', 4 => 'TB');
    $log = log($bytes, 1024);
    $power = (int) $log;
    $size = pow(1024, $log - $power);
    if (!is_nan($size) && array_key_exists($power, $units)) {
        $unit = $units[$power];
    } else {
        $size = $bytes;
        $unit = $units[0];
    }
    return $size . $unit;
}