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.


Built from https://develop.svn.wordpress.org/trunk@28343


git-svn-id: http://core.svn.wordpress.org/trunk@28171 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2014-05-07 18:25:14 +00:00
parent 3bbed6ceac
commit 1daa7d6723
2 changed files with 13 additions and 32 deletions

View File

@ -1690,18 +1690,9 @@ function media_upload_form( $errors = null ) {
$_type = isset($type) ? $type : ''; $_type = isset($type) ? $type : '';
$_tab = isset($tab) ? $tab : ''; $_tab = isset($tab) ? $tab : '';
$upload_size_unit = $max_upload_size = wp_max_upload_size(); $max_upload_size = wp_max_upload_size();
$sizes = array( 'KB', 'MB', 'GB' ); if ( ! $max_upload_size ) {
$max_upload_size = 0;
for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ ) {
$upload_size_unit /= 1024;
}
if ( $u < 0 ) {
$upload_size_unit = 0;
$u = 0;
} else {
$upload_size_unit = (int) $upload_size_unit;
} }
?> ?>
@ -1850,7 +1841,7 @@ do_action( 'post-html-upload-ui' );
?> ?>
</div> </div>
<span class="max-upload-size"><?php printf( __( 'Maximum upload file size: %d%s.' ), esc_html($upload_size_unit), esc_html($sizes[$u]) ); ?></span> <span class="max-upload-size"><?php printf( __( 'Maximum upload file size: %s.' ), esc_html( size_format( $max_upload_size ) ) ); ?></span>
<?php <?php
/** /**

View File

@ -186,24 +186,14 @@ function wp_print_media_templates() {
do_action( 'post-plupload-upload-ui' ); do_action( 'post-plupload-upload-ui' );
} }
$upload_size_unit = $max_upload_size = wp_max_upload_size(); $max_upload_size = wp_max_upload_size();
$byte_sizes = array( 'KB', 'MB', 'GB' ); if ( ! $max_upload_size ) {
$max_upload_size = 0;
for ( $u = -1; $upload_size_unit > 1024 && $u < count( $byte_sizes ) - 1; $u++ ) {
$upload_size_unit /= 1024;
} }
if ( $u < 0 ) {
$upload_size_unit = 0;
$u = 0;
} else {
$upload_size_unit = (int) $upload_size_unit;
}
?> ?>
<p class="max-upload-size"><?php <p class="max-upload-size"><?php
printf( __( 'Maximum upload file size: %d%s.' ), esc_html($upload_size_unit), esc_html($byte_sizes[$u]) ); printf( __( 'Maximum upload file size: %s.' ), esc_html( size_format( $max_upload_size ) ) );
?></p> ?></p>
<# if ( data.suggestedWidth && data.suggestedHeight ) { #> <# if ( data.suggestedWidth && data.suggestedHeight ) { #>