Making WordPress.org

Changeset 9887


Ignore:
Timestamp:
05/19/2020 08:14:31 PM (5 years ago)
Author:
ocean90
Message:

Theme/Plugin Directory: Use size_format() when displaying allowed upload file size.

See #5221.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-upload.php

    r9886 r9887  
    202202                                /* translators: Maximum allowed file size. */
    203203                                esc_html__( 'Maximum allowed file size: %s', 'wporg-plugins' ),
    204                                 esc_html( self::get_max_allowed_file_size() )
     204                                esc_html( size_format( wp_max_upload_size() ) )
    205205                            );
    206206                            ?>
     
    251251    }
    252252
    253     /**
    254      * Returns a human readable version of the max allowed upload size.
    255      *
    256      * @return string The allowed file size.
    257      */
    258     public static function get_max_allowed_file_size() {
    259         $upload_size_unit = wp_max_upload_size();
    260 
    261         $byte_sizes       = array( 'KB', 'MB', 'GB' );
    262 
    263         for ( $unit = - 1; $upload_size_unit > 1024 && $unit < count( $byte_sizes ) - 1; $unit ++ ) {
    264             $upload_size_unit /= 1024;
    265         }
    266 
    267         if ( $unit < 0 ) {
    268             $upload_size_unit = $unit = 0;
    269         } else {
    270             $upload_size_unit = (int) $upload_size_unit;
    271         }
    272 
    273         return $upload_size_unit . $byte_sizes[ $unit ];
    274     }
    275253}
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/upload.php

    r9725 r9887  
    4848            <button id="upload_button" class="button" type="submit" value="' . esc_attr__( 'Upload', 'wporg-themes' ) . '">' . esc_html__( 'Upload', 'wporg-themes' ) . '</button>
    4949            <p>
    50                 <small>' . sprintf( __( 'Maximum allowed file size: %s', 'wporg-themes' ), esc_html( wporg_themes_get_max_allowed_file_size() ) ) . '</small>
     50                <small>' . sprintf( __( 'Maximum allowed file size: %s', 'wporg-themes' ), esc_html( size_format( wp_max_upload_size() ) ) ) . '</small>
    5151            </p>
    5252        </form>';
    5353
    5454    return $notice . $form;
    55 }
    56 
    57 /**
    58  * Returns a human readable version of the max allowed upload size.
    59  *
    60  * @return string The allowed file size.
    61  */
    62 function wporg_themes_get_max_allowed_file_size() {
    63     $upload_size_unit = wp_max_upload_size();
    64     $byte_sizes       = array( 'KB', 'MB', 'GB' );
    65 
    66     for ( $unit = - 1; $upload_size_unit > 1024 && $unit < count( $byte_sizes ) - 1; $unit++ ) {
    67         $upload_size_unit /= 1024;
    68     }
    69     if ( $unit < 0 ) {
    70         $upload_size_unit = $unit = 0;
    71     } else {
    72         $upload_size_unit = (int) $upload_size_unit;
    73     }
    74     return $upload_size_unit . $byte_sizes[ $unit ];
    7555}
    7656
Note: See TracChangeset for help on using the changeset viewer.