Make WordPress Core


Ignore:
Timestamp:
07/21/2020 03:19:58 PM (3 years ago)
Author:
whyisjake
Message:

Site Health: Include new tests to check for the ability to upload files.

Several new checks:

  • max_file_uploads
  • file_uploads
  • post_max_size
  • upload_max_filesize
  • upload_max
  • max_file_uploads

In addition, new function parse_ini_size() that converts shorthand byte strings to bytes. Useful for size comparisons.

Fixes #50038.
Props dd32, donmhico, JavierCasares, SergeyBiryukov, ayeshrajans, Clorith, ipstenu, sabernhardt, whyisjake.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-site-health.php

    r48475 r48535  
    19511951                );
    19521952            }
     1953        }
     1954
     1955        return $result;
     1956    }
     1957
     1958    /**
     1959     * Test if 'file_uploads' directive in PHP.ini is turned off
     1960     *
     1961     * @since 5.5.0
     1962     *
     1963     * @return array The test results.
     1964     */
     1965    public function get_test_file_uploads() {
     1966        $result = array(
     1967            'label'       => __( 'Files can be uploaded.' ),
     1968            'status'      => 'good',
     1969            'badge'       => array(
     1970                'label' => __( 'Performance' ),
     1971                'color' => 'blue',
     1972            ),
     1973            'description' => sprintf(
     1974                '<p>%s</p>',
     1975                sprintf(
     1976                    /* translators: %1$s: file_uploads %2$s: php.ini */
     1977                    __( 'The %1$s directive in %2$s determines if uploading to is allowed in your WordPress.' ),
     1978                    '<code>file_uploads</code>',
     1979                    '<code>php.ini</code>'
     1980                )
     1981            ),
     1982            'actions'     => '',
     1983            'test'        => 'file_uploads',
     1984        );
     1985
     1986        if ( ! function_exists( 'ini_get' ) ) {
     1987            $result['status']       = 'critical';
     1988            $result['description'] .= sprintf(
     1989                /* translators: %s: ini_get() */
     1990                __( 'The %s function has been disabled, some media settings are unavailable because of this.' ),
     1991                '<code>ini_get()</code>'
     1992            );
     1993            return $result;
     1994        }
     1995
     1996        if ( empty( ini_get( 'file_uploads' ) ) ) {
     1997            $result['status']       = 'critical';
     1998            $result['description'] .= sprintf(
     1999                '<p>%s</p>',
     2000                sprintf(
     2001                    /* translators: %1$s: file_uploads %2$s: 0 */
     2002                    __( '%1$s is set to %2$s. You won\'t be able to upload files in your WordPress.' ),
     2003                    '<code>file_uploads</code>',
     2004                    '<code>0</code>'
     2005                )
     2006            );
     2007            return $result;
     2008        }
     2009
     2010        if ( parse_ini_size( ini_get( 'post_max_size' ) ) !== parse_ini_size( ini_get( 'upload_max_filesize' ) ) ) {
     2011            $result['label']       = __( 'Mismatched "post_max_size" and "upload_max_filesize" values.' );
     2012            $result['status']      = 'recommended';
     2013            $result['description'] = sprintf(
     2014                '<p>%s</p>',
     2015                sprintf(
     2016                    /* translators: %1$s: post_max_size %2$s: upload_max_filesize */
     2017                    __( 'The settings for %1$s and %2$s are not the same, this could cause some problems when trying to upload files.' ),
     2018                    '<code>post_max_size</code>',
     2019                    '<code>upload_max_filesize</code>'
     2020                )
     2021            );
     2022            return $result;
    19532023        }
    19542024
     
    20262096                    'test'  => 'is_in_debug_mode',
    20272097                ),
     2098                'file_uploads'         => array(
     2099                    'label' => __( 'File uploads' ),
     2100                    'test'  => 'file_uploads',
     2101                ),
    20282102            ),
    20292103            'async'  => array(
Note: See TracChangeset for help on using the changeset viewer.