WordPress.org

Make WordPress Core

Ticket #17725: 17725.3.diff

File 17725.3.diff, 1.1 KB (added by hakre, 3 years ago)

Update of .2: substr(-1) issues a warning on empty string.

  • wp-admin/includes/template.php

     
    779779} 
    780780 
    781781/** 
    782  * {@internal Missing Short Description}} 
     782 * Convert a human readable (hr) memory setting value as in  
     783 * php.ini into the number of bytes (Shorthand Notation). 
    783784 * 
    784785 * @since 2.3.0 
    785786 * 
    786  * @param unknown_type $size 
    787  * @return unknown 
     787 * @param string $size memory setting value 
     788 * @return float bytes 
    788789 */ 
    789 function wp_convert_hr_to_bytes( $size ) { 
    790         $size = strtolower($size); 
    791         $bytes = (int) $size; 
    792         if ( strpos($size, 'k') !== false ) 
    793                 $bytes = intval($size) * 1024; 
    794         elseif ( strpos($size, 'm') !== false ) 
    795                 $bytes = intval($size) * 1024 * 1024; 
    796         elseif ( strpos($size, 'g') !== false ) 
    797                 $bytes = intval($size) * 1024 * 1024 * 1024; 
     790function wp_convert_hr_to_bytes( $size ) {       
     791        $bytes = (float) $size; 
     792        if ($bytes) {    
     793                $last = strtolower( substr( $size, -1 ) ); 
     794                $pos = strpos( ' kmg', $last , 1); 
     795                if ( $pos ) $bytes *= pow( 1024, $pos); 
     796                $bytes = round( $bytes ); 
     797        } 
    798798        return $bytes; 
    799799} 
    800800