WordPress.org

Make WordPress Core

Ticket #22405: 22405.4.patch

File 22405.4.patch, 4.8 KB (added by sudar, 4 years ago)

Use *_IN_BYTES constants instead of hardcoded numbers

  • src/wp-admin/includes/ms.php

     
    2929
    3030        $file_size = filesize( $file['tmp_name'] );
    3131        if ( $space_left < $file_size )
    32                 $file['error'] = sprintf( __( 'Not enough space to upload. %1$s KB needed.' ), number_format( ($file_size - $space_left) /1024 ) );
    33         if ( $file_size > ( 1024 * get_site_option( 'fileupload_maxk', 1500 ) ) )
     32                $file['error'] = sprintf( __( 'Not enough space to upload. %1$s KB needed.' ), number_format( ($file_size - $space_left) / KB_IN_BYTES ) );
     33        if ( $file_size > ( KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 ) ) )
    3434                $file['error'] = sprintf(__('This file is too big. Files must be less than %1$s KB in size.'), get_site_option( 'fileupload_maxk', 1500 ) );
    3535        if ( upload_is_user_over_quota( false ) ) {
    3636                $file['error'] = __( 'You have used your space quota. Please delete files before uploading.' );
     
    11041104});
    11051105</script>
    11061106<?php
    1107 }
    1108  No newline at end of file
     1107}
  • src/wp-includes/cache.php

     
    691691                echo "</p>";
    692692                echo '<ul>';
    693693                foreach ($this->cache as $group => $cache) {
    694                         echo "<li><strong>Group:</strong> $group - ( " . number_format( strlen( serialize( $cache ) ) / 1024, 2 ) . 'k )</li>';
     694                        echo "<li><strong>Group:</strong> $group - ( " . number_format( strlen( serialize( $cache ) ) / KB_IN_BYTES, 2 ) . 'k )</li>';
    695695                }
    696696                echo '</ul>';
    697697        }
  • src/wp-includes/functions.php

     
    210210 */
    211211function size_format( $bytes, $decimals = 0 ) {
    212212        $quant = array(
    213                 // ========================= Origin ====
    214                 'TB' => 1099511627776,  // pow( 1024, 4)
    215                 'GB' => 1073741824,     // pow( 1024, 3)
    216                 'MB' => 1048576,        // pow( 1024, 2)
    217                 'kB' => 1024,           // pow( 1024, 1)
    218                 'B'  => 1,              // pow( 1024, 0)
     213                'TB' => TB_IN_BYTES,
     214                'GB' => GB_IN_BYTES,
     215                'MB' => MB_IN_BYTES,
     216                'kB' => KB_IN_BYTES,
     217                'B'  => 1,
    219218        );
    220219
    221220        foreach ( $quant as $unit => $mag ) {
  • src/wp-includes/media.php

     
    26112611        $size  = strtolower( $size );
    26122612        $bytes = (int) $size;
    26132613        if ( strpos( $size, 'k' ) !== false )
    2614                 $bytes = intval( $size ) * 1024;
     2614                $bytes = intval( $size ) * KB_IN_BYTES;
    26152615        elseif ( strpos( $size, 'm' ) !== false )
    2616                 $bytes = intval($size) * 1024 * 1024;
     2616                $bytes = intval($size) * MB_IN_BYTES;
    26172617        elseif ( strpos( $size, 'g' ) !== false )
    2618                 $bytes = intval( $size ) * 1024 * 1024 * 1024;
     2618                $bytes = intval( $size ) * GB_IN_BYTES;
    26192619        return $bytes;
    26202620}
    26212621
  • src/wp-includes/ms-functions.php

     
    18741874        if ( ! is_array( $upload ) || defined( 'WP_IMPORTING' ) || get_site_option( 'upload_space_check_disabled' ) )
    18751875                return $upload;
    18761876
    1877         if ( strlen( $upload['bits'] )  > ( 1024 * get_site_option( 'fileupload_maxk', 1500 ) ) )
     1877        if ( strlen( $upload['bits'] )  > ( KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 ) ) )
    18781878                return sprintf( __( 'This file is too big. Files must be less than %d KB in size.' ) . '<br />', get_site_option( 'fileupload_maxk', 1500 ));
    18791879
    18801880        return $upload;
     
    22782278        $space_used = apply_filters( 'pre_get_space_used', false );
    22792279        if ( false === $space_used ) {
    22802280                $upload_dir = wp_upload_dir();
    2281                 $space_used = get_dirsize( $upload_dir['basedir'] ) / 1024 / 1024;
     2281                $space_used = get_dirsize( $upload_dir['basedir'] ) / MB_IN_BYTES;
    22822282        }
    22832283
    22842284        return $space_used;
     
    23222322        if ( $allowed < 0 ) {
    23232323                $allowed = 0;
    23242324        }
    2325         $space_allowed = $allowed * 1024 * 1024;
     2325        $space_allowed = $allowed * MB_IN_BYTES;
    23262326        if ( get_site_option( 'upload_space_check_disabled' ) )
    23272327                return $space_allowed;
    23282328
    2329         $space_used = get_space_used() * 1024 * 1024;
     2329        $space_used = get_space_used() * MB_IN_BYTES;
    23302330
    23312331        if ( ( $space_allowed - $space_used ) <= 0 )
    23322332                return 0;
     
    23532353 * @return int of upload size limit in bytes
    23542354 */
    23552355function upload_size_limit_filter( $size ) {
    2356         $fileupload_maxk = 1024 * get_site_option( 'fileupload_maxk', 1500 );
     2356        $fileupload_maxk = KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 );
    23572357        if ( get_site_option( 'upload_space_check_disabled' ) )
    23582358                return min( $size, $fileupload_maxk );
    23592359