WordPress.org

Make WordPress Core

Changeset 28343


Ignore:
Timestamp:
05/07/2014 06:24:47 PM (7 years ago)
Author:
wonderboymusic
Message:

Leverage size_format() when displaying max_upload_size:

  • In media_upload_form()
  • The uploader-inline Underscore template in the media modal.

Replaces 2 buggy inline implementations that could display size units off by one, or size values off by one.

Fixes #25643.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/media.php

    r28297 r28343  
    16911691    $_tab = isset($tab) ? $tab : '';
    16921692
    1693     $upload_size_unit = $max_upload_size = wp_max_upload_size();
    1694     $sizes = array( 'KB', 'MB', 'GB' );
    1695 
    1696     for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ ) {
    1697         $upload_size_unit /= 1024;
    1698     }
    1699 
    1700     if ( $u < 0 ) {
    1701         $upload_size_unit = 0;
    1702         $u = 0;
    1703     } else {
    1704         $upload_size_unit = (int) $upload_size_unit;
     1693    $max_upload_size = wp_max_upload_size();
     1694    if ( ! $max_upload_size ) {
     1695        $max_upload_size = 0;
    17051696    }
    17061697?>
     
    17371728
    17381729$post_params = array(
    1739         "post_id" => $post_id,
    1740         "_wpnonce" => wp_create_nonce('media-form'),
    1741         "type" => $_type,
    1742         "tab" => $_tab,
    1743         "short" => "1",
     1730    "post_id" => $post_id,
     1731    "_wpnonce" => wp_create_nonce('media-form'),
     1732    "type" => $_type,
     1733    "tab" => $_tab,
     1734    "short" => "1",
    17441735);
    17451736
     
    18511842</div>
    18521843
    1853 <span class="max-upload-size"><?php printf( __( 'Maximum upload file size: %d%s.' ), esc_html($upload_size_unit), esc_html($sizes[$u]) ); ?></span>
     1844<span class="max-upload-size"><?php printf( __( 'Maximum upload file size: %s.' ), esc_html( size_format( $max_upload_size ) ) ); ?></span>
    18541845<?php
    18551846
  • trunk/src/wp-includes/media-template.php

    r28184 r28343  
    187187                }
    188188
    189                 $upload_size_unit = $max_upload_size = wp_max_upload_size();
    190                 $byte_sizes = array( 'KB', 'MB', 'GB' );
    191 
    192                 for ( $u = -1; $upload_size_unit > 1024 && $u < count( $byte_sizes ) - 1; $u++ ) {
    193                     $upload_size_unit /= 1024;
     189                $max_upload_size = wp_max_upload_size();
     190                if ( ! $max_upload_size ) {
     191                    $max_upload_size = 0;
    194192                }
    195 
    196                 if ( $u < 0 ) {
    197                     $upload_size_unit = 0;
    198                     $u = 0;
    199                 } else {
    200                     $upload_size_unit = (int) $upload_size_unit;
    201                 }
    202 
    203193                ?>
    204194
    205195                <p class="max-upload-size"><?php
    206                     printf( __( 'Maximum upload file size: %d%s.' ), esc_html($upload_size_unit), esc_html($byte_sizes[$u]) );
     196                    printf( __( 'Maximum upload file size: %s.' ), esc_html( size_format( $max_upload_size ) ) );
    207197                ?></p>
    208198
Note: See TracChangeset for help on using the changeset viewer.