wp_convert_hr_to_bytes

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

WordPress Version: 6.3

/**
 * Converts a shorthand byte value to an integer byte value.
 *
 * @since 2.3.0
 * @since 4.6.0 Moved from media.php to load.php.
 *
 * @link https://www.php.net/manual/en/function.ini-get.php
 * @link https://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes
 *
 * @param string $value A (PHP ini) byte value, either shorthand or ordinary.
 * @return int An integer byte value.
 */
function wp_convert_hr_to_bytes($value)
{
    $value = strtolower(trim($value));
    $bytes = (int) $value;
    if (str_contains($value, 'g')) {
        $bytes *= GB_IN_BYTES;
    } elseif (str_contains($value, 'm')) {
        $bytes *= MB_IN_BYTES;
    } elseif (str_contains($value, 'k')) {
        $bytes *= KB_IN_BYTES;
    }
    // Deal with large (float) values which run into the maximum integer size.
    return min($bytes, PHP_INT_MAX);
}

WordPress Version: 5.4

/**
 * Converts a shorthand byte value to an integer byte value.
 *
 * @since 2.3.0
 * @since 4.6.0 Moved from media.php to load.php.
 *
 * @link https://www.php.net/manual/en/function.ini-get.php
 * @link https://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes
 *
 * @param string $value A (PHP ini) byte value, either shorthand or ordinary.
 * @return int An integer byte value.
 */
function wp_convert_hr_to_bytes($value)
{
    $value = strtolower(trim($value));
    $bytes = (int) $value;
    if (false !== strpos($value, 'g')) {
        $bytes *= GB_IN_BYTES;
    } elseif (false !== strpos($value, 'm')) {
        $bytes *= MB_IN_BYTES;
    } elseif (false !== strpos($value, 'k')) {
        $bytes *= KB_IN_BYTES;
    }
    // Deal with large (float) values which run into the maximum integer size.
    return min($bytes, PHP_INT_MAX);
}

WordPress Version: 4.7

/**
 * Converts a shorthand byte value to an integer byte value.
 *
 * @since 2.3.0
 * @since 4.6.0 Moved from media.php to load.php.
 *
 * @link https://secure.php.net/manual/en/function.ini-get.php
 * @link https://secure.php.net/manual/en/faq.using.php#faq.using.shorthandbytes
 *
 * @param string $value A (PHP ini) byte value, either shorthand or ordinary.
 * @return int An integer byte value.
 */
function wp_convert_hr_to_bytes($value)
{
    $value = strtolower(trim($value));
    $bytes = (int) $value;
    if (false !== strpos($value, 'g')) {
        $bytes *= GB_IN_BYTES;
    } elseif (false !== strpos($value, 'm')) {
        $bytes *= MB_IN_BYTES;
    } elseif (false !== strpos($value, 'k')) {
        $bytes *= KB_IN_BYTES;
    }
    // Deal with large (float) values which run into the maximum integer size.
    return min($bytes, PHP_INT_MAX);
}

WordPress Version: 4.6

/**
 * Converts a shorthand byte value to an integer byte value.
 *
 * @since 2.3.0
 * @since 4.6.0 Moved from media.php to load.php.
 *
 * @link http://php.net/manual/en/function.ini-get.php
 * @link http://php.net/manual/en/faq.using.php#faq.using.shorthandbytes
 *
 * @param string $value A (PHP ini) byte value, either shorthand or ordinary.
 * @return int An integer byte value.
 */
function wp_convert_hr_to_bytes($value)
{
    $value = strtolower(trim($value));
    $bytes = (int) $value;
    if (false !== strpos($value, 'g')) {
        $bytes *= GB_IN_BYTES;
    } elseif (false !== strpos($value, 'm')) {
        $bytes *= MB_IN_BYTES;
    } elseif (false !== strpos($value, 'k')) {
        $bytes *= KB_IN_BYTES;
    }
    // Deal with large (float) values which run into the maximum integer size.
    return min($bytes, PHP_INT_MAX);
}

WordPress Version: 4.4

/**
 * Converts a shorthand byte value to an integer byte value.
 *
 * @since 2.3.0
 *
 * @param string $size A shorthand byte value.
 * @return int An integer byte value.
 */
function wp_convert_hr_to_bytes($size)
{
    $size = strtolower($size);
    $bytes = (int) $size;
    if (strpos($size, 'k') !== false) {
        $bytes = intval($size) * KB_IN_BYTES;
    } elseif (strpos($size, 'm') !== false) {
        $bytes = intval($size) * MB_IN_BYTES;
    } elseif (strpos($size, 'g') !== false) {
        $bytes = intval($size) * GB_IN_BYTES;
    }
    return $bytes;
}

WordPress Version: 3.7

/**
 * Converts a shorthand byte value to an integer byte value.
 *
 * @since 2.3.0
 *
 * @param string $size A shorthand byte value.
 * @return int An integer byte value.
 */
function wp_convert_hr_to_bytes($size)
{
    $size = strtolower($size);
    $bytes = (int) $size;
    if (strpos($size, 'k') !== false) {
        $bytes = intval($size) * 1024;
    } elseif (strpos($size, 'm') !== false) {
        $bytes = intval($size) * 1024 * 1024;
    } elseif (strpos($size, 'g') !== false) {
        $bytes = intval($size) * 1024 * 1024 * 1024;
    }
    return $bytes;
}