Make WordPress Core


Ignore:
Timestamp:
07/21/2020 03:19:58 PM (4 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-debug-data.php

    r48125 r48535  
    519519            'value' => ( is_array( $imagick_version ) ? $imagick_version['versionString'] : $imagick_version ),
    520520        );
     521
     522        if ( ! function_exists( 'ini_get' ) ) {
     523            $info['wp-media']['fields']['ini_get'] = array(
     524                'label' => __( 'File upload settings' ),
     525                'value' => sprintf(
     526                    /* translators: %s: ini_get() */
     527                    __( 'Unable to determine some settings, as the %s function has been disabled.' ),
     528                    'ini_get()'
     529                ),
     530                'debug' => 'ini_get() is disabled',
     531            );
     532        } else {
     533            // Get the PHP ini directive values.
     534            $post_max_size    = ini_get( 'post_max_size' );
     535            $upload_max_size  = ini_get( 'upload_max_filesize' );
     536            $max_file_uploads = ini_get( 'max_file_uploads' );
     537            $effective        = min( parse_ini_size( $post_max_size ), parse_ini_size( $upload_max_size ) );
     538
     539            // Add info in Media section.
     540            $info['wp-media']['fields']['file_uploads']        = array(
     541                'label' => __( 'File uploads' ),
     542                'value' => empty( ini_get( 'file_uploads' ) ) ? __( 'Disabled' ) : __( 'Enabled' ),
     543                'debug' => 'File uploads is turned off',
     544            );
     545            $info['wp-media']['fields']['post_max_size']       = array(
     546                'label' => __( 'Max size of post data allowed' ),
     547                'value' => $post_max_size,
     548            );
     549            $info['wp-media']['fields']['upload_max_filesize'] = array(
     550                'label' => __( 'Max size of an uploaded file' ),
     551                'value' => $upload_max_size,
     552            );
     553            $info['wp-media']['fields']['upload_max']          = array(
     554                'label' => __( 'Max effective file size' ),
     555                'value' => size_format( $effective ),
     556            );
     557            $info['wp-media']['fields']['max_file_uploads']    = array(
     558                'label' => __( 'Max number of files allowed' ),
     559                'value' => number_format( $max_file_uploads ),
     560            );
     561        }
    521562
    522563        // If Imagick is used as our editor, provide some more information about its limitations.
Note: See TracChangeset for help on using the changeset viewer.