WordPress.org

Make WordPress Core

Ticket #23895: 23895.patch

File 23895.patch, 2.5 KB (added by biskobe, 4 years ago)

Properly determine the file size if one of the values, checked in the function is zero, meaning unlimited.

  • src/wp-includes/media.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    26022602/**
    26032603 * Determines the maximum upload size allowed in php.ini.
    26042604 *
     2605 * The optional arguments should be supplied only for testing
     2606 * the function.
     2607 *
    26052608 * @since 2.5.0
    26062609 *
     2610 * @param int $upl_max_filesize_bytes A value for upload_max_filesize.
     2611 * @param int $post_max_size_bytes A value for post_max_size.
     2612 *
    26072613 * @return int Allowed upload size.
    26082614 */
    2609 function wp_max_upload_size() {
    2610         $u_bytes = wp_convert_hr_to_bytes( ini_get( 'upload_max_filesize' ) );
    2611         $p_bytes = wp_convert_hr_to_bytes( ini_get( 'post_max_size' ) );
     2615function wp_max_upload_size( $upl_max_filesize_bytes = null, $post_max_size_bytes = null ) {
    26122616
    26132617        /**
     2618         * Initialize the values, if none are provided by the tests.
     2619         */
     2620        if (!$upl_max_filesize_bytes) {
     2621                $upl_max_filesize_bytes = wp_convert_hr_to_bytes( ini_get( 'upload_max_filesize' ) );
     2622        }
     2623
     2624        if (!$post_max_size_bytes) {
     2625                $post_max_size_bytes = wp_convert_hr_to_bytes( ini_get( 'post_max_size' ) );
     2626        }
     2627
     2628        /**
     2629         * Get an accurate max upload size.
     2630         *
     2631         * If one of the limits is set to 0, but the other one isn't
     2632         * this value will be wrong.
     2633         * PHP treats 0 values as "unlimited", so actually the limit
     2634         * is the larger value in this case.
     2635         *
     2636         * This is handled here, to make sure the proper limit is returned.
     2637     *
     2638     */
     2639
     2640        // get the lower limit
     2641        $upload_size_limit_bytes = min( $upl_max_filesize_bytes, $post_max_size_bytes );
     2642
     2643        // if the limit is 0, make sure to get the correct one
     2644        if ( 0 ===  $upload_size_limit_bytes ) {
     2645                $upload_size_limit_bytes = max( $upl_max_filesize_bytes, $post_max_size_bytes );
     2646        }
     2647
     2648        /**
    26142649         * Filter the maximum upload size allowed in php.ini.
    26152650         *
    26162651         * @since 2.5.0
    26172652         *
    26182653         * @param int $size    Max upload size limit in bytes.
    2619          * @param int $u_bytes Maximum upload filesize in bytes.
    2620          * @param int $p_bytes Maximum size of POST data in bytes.
     2654         * @param int $upl_max_filesize_bytes Maximum upload filesize in bytes.
     2655         * @param int $post_max_size_bytes Maximum size of POST data in bytes.
    26212656         */
    2622         return apply_filters( 'upload_size_limit', min( $u_bytes, $p_bytes ), $u_bytes, $p_bytes );
     2657        return apply_filters( 'upload_size_limit', $upload_size_limit_bytes, $upl_max_filesize_bytes, $post_max_size_bytes );
    26232658}
    26242659
    26252660/**