Making WordPress.org

Ticket #5221: 5221.2.patch

File 5221.2.patch, 3.3 KB (added by ocean90, 5 years ago)

Includes https://meta.trac.wordpress.org/changeset/9886 for the theme directory

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

     
    201201                                                        printf(
    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                                                        ?>
    207207                                                </small>
     
    250250                return ob_get_clean();
    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                 $byte_sizes       = array( 'KB', 'MB', 'GB' );
    261 
    262                 for ( $unit = - 1; $upload_size_unit > 1024 && $unit < count( $byte_sizes ) - 1; $unit ++ ) {
    263                         $upload_size_unit /= 1024;
    264                 }
    265 
    266                 if ( $unit < 0 ) {
    267                         $upload_size_unit = $unit = 0;
    268                 } else {
    269                         $upload_size_unit = (int) $upload_size_unit;
    270                 }
    271 
    272                 return $upload_size_unit . $byte_sizes[ $unit ];
    273         }
    274253}
  • trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/upload.php

     
    99add_action( 'init', 'wporg_themes_upload_shortcode' );
    1010
    1111/**
     12 * Sets upload size limit to limit theme ZIP file uploads to 10 MB.
     13 */
     14function wporg_themes_upload_size_limit() {
     15        return 10 * MB_IN_BYTES;
     16}
     17add_filter( 'upload_size_limit', 'wporg_themes_upload_size_limit', 10, 0 );
     18
     19/**
    1220 * Renders the upload shortcode.
    1321 */
    1422function wporg_themes_render_upload_shortcode() {
     
    4755                        <input type="file" id="zip_file" name="zip_file" size="25"/>
    4856                        <button id="upload_button" class="button" type="submit" value="' . esc_attr__( 'Upload', 'wporg-themes' ) . '">' . esc_html__( 'Upload', 'wporg-themes' ) . '</button>
    4957                        <p>
    50                                 <small>' . sprintf( __( 'Maximum allowed file size: %s', 'wporg-themes' ), esc_html( wporg_themes_get_max_allowed_file_size() ) ) . '</small>
     58                                <small>' . sprintf( __( 'Maximum allowed file size: %s', 'wporg-themes' ), esc_html( size_format( wp_max_upload_size() ) ) ) . '</small>
    5159                        </p>
    5260                </form>';
    5361
     
    5563}
    5664
    5765/**
    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 ];
    75 }
    76 
    77 /**
    7866 * Runs basic checks and hands off to the upload processor.
    7967 *
    8068 * @return string Failure or success message.