WordPress.org

Make WordPress Core

Ticket #13418: 13418.admin-tempate-wp_convert_hr_to_bytes.patch

File 13418.admin-tempate-wp_convert_hr_to_bytes.patch, 1.1 KB (added by hakre, 8 years ago)

Following the technical specification of shorthand parsing on php.net

  • wp-admin/includes/template.php

     
    26852685 *
    26862686 * @since unknown
    26872687 *
    2688  * @param unknown_type $size
    2689  * @return unknown
     2688 * @param string $size bytes as shorthand byte values
     2689 * @return int bytes
    26902690 */
    26912691function wp_convert_hr_to_bytes( $size ) {
    2692         $size = strtolower($size);
    2693         $bytes = (int) $size;
    2694         if ( strpos($size, 'k') !== false )
    2695                 $bytes = intval($size) * 1024;
    2696         elseif ( strpos($size, 'm') !== false )
    2697                 $bytes = intval($size) * 1024 * 1024;
    2698         elseif ( strpos($size, 'g') !== false )
    2699                 $bytes = intval($size) * 1024 * 1024 * 1024;
    2700         return $bytes;
     2692        $size = trim( $size );
     2693        $last = strtolower( $size[strlen( $size )-1] );
     2694        switch($last) {
     2695        // The 'G' modifier is available since PHP 5.1.0
     2696        case 'g':
     2697            $size *= 1024;
     2698        case 'm':
     2699            $size *= 1024;
     2700        case 'k':
     2701            $size *= 1024;
     2702    }
     2703    return $size;
    27012704}
    27022705
    27032706/**