Make WordPress Core

Ticket #23895: 23895.3.patch

File 23895.3.patch, 2.6 KB (added by biskobe, 9 years ago)

Added proper check for the optional parameters values. It would've failed with zero inputs.

  • 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
     2609 * @since 4.4.0 Introduced the `$upl_max_filesize_bytes` and `$post_max_size_bytes` parameters.
    26062610 *
     2611 * @param int $upl_max_filesize_bytes A value for upload_max_filesize.
     2612 * @param int $post_max_size_bytes A value for post_max_size.
     2613 *
    26072614 * @return int Allowed upload size.
    26082615 */
    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' ) );
     2616function wp_max_upload_size( $upl_max_filesize_bytes = null, $post_max_size_bytes = null ) {
    26122617
    26132618        /**
     2619         * Initialize the values, if none are provided by the tests.
     2620         */
     2621        if ( is_null( $upl_max_filesize_bytes ) ) {
     2622                $upl_max_filesize_bytes = wp_convert_hr_to_bytes( ini_get( 'upload_max_filesize' ) );
     2623        }
     2624
     2625        if ( is_null( $post_max_size_bytes ) ) {
     2626                $post_max_size_bytes = wp_convert_hr_to_bytes( ini_get( 'post_max_size' ) );
     2627        }
     2628
     2629        /**
     2630         * Get an accurate max upload size.
     2631         *
     2632         * If one of the limits is set to 0, but the other one isn't
     2633         * this value will be wrong.
     2634         * PHP treats 0 values as "unlimited", so actually the limit
     2635         * is the larger value in this case.
     2636         *
     2637         * This is handled here, to make sure the proper limit is returned.
     2638     *
     2639     */
     2640
     2641        // get the lower limit
     2642        $upload_size_limit_bytes = min( $upl_max_filesize_bytes, $post_max_size_bytes );
     2643
     2644        // if the limit is 0, make sure to get the correct one
     2645        if ( 0 ===  $upload_size_limit_bytes ) {
     2646                $upload_size_limit_bytes = max( $upl_max_filesize_bytes, $post_max_size_bytes );
     2647        }
     2648
     2649        /**
    26142650         * Filter the maximum upload size allowed in php.ini.
    26152651         *
    26162652         * @since 2.5.0
    26172653         *
    26182654         * @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.
     2655         * @param int $upl_max_filesize_bytes Maximum upload filesize in bytes.
     2656         * @param int $post_max_size_bytes Maximum size of POST data in bytes.
    26212657         */
    2622         return apply_filters( 'upload_size_limit', min( $u_bytes, $p_bytes ), $u_bytes, $p_bytes );
     2658        return apply_filters( 'upload_size_limit', $upload_size_limit_bytes, $upl_max_filesize_bytes, $post_max_size_bytes );
    26232659}
    26242660
    26252661/**