Make WordPress Core

Changeset 62634


Ignore:
Timestamp:
07/04/2026 11:32:48 PM (6 weeks ago)
Author:
SergeyBiryukov
Message:

Site Health: Remove redundant function_exists( 'ini_get' ) checks.

The ini_get() function is called unconditionally early in the bootstrap process, so there is no need for subsequent function_exists( 'ini_get' ) checks.

Follow-up to [44986], [45104].

Props siliconforks, shreyasikhar26, ankitkumarshah, westonruter, SergeyBiryukov.
Fixes #65423.

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-debug-data.php

    r61657 r62634  
    388388                );
    389389
    390                 // Some servers disable `ini_set()` and `ini_get()`, we check this before trying to get configuration values.
    391                 if ( ! function_exists( 'ini_get' ) ) {
    392                         $fields['ini_get'] = array(
    393                                 'label' => __( 'Server settings' ),
    394                                 'value' => sprintf(
    395                                 /* translators: %s: ini_get() */
    396                                         __( 'Unable to determine some settings, as the %s function has been disabled.' ),
    397                                         'ini_get()'
    398                                 ),
    399                                 'debug' => 'ini_get() is disabled',
     390                $fields['max_input_variables'] = array(
     391                        'label' => __( 'PHP max input variables' ),
     392                        'value' => ini_get( 'max_input_vars' ),
     393                );
     394                $fields['time_limit']          = array(
     395                        'label' => __( 'PHP time limit' ),
     396                        'value' => ini_get( 'max_execution_time' ),
     397                );
     398
     399                if ( WP_Site_Health::get_instance()->php_memory_limit !== ini_get( 'memory_limit' ) ) {
     400                        $fields['memory_limit']       = array(
     401                                'label' => __( 'PHP memory limit' ),
     402                                'value' => WP_Site_Health::get_instance()->php_memory_limit,
     403                        );
     404                        $fields['admin_memory_limit'] = array(
     405                                'label' => __( 'PHP memory limit (only for admin screens)' ),
     406                                'value' => ini_get( 'memory_limit' ),
    400407                        );
    401408                } else {
    402                         $fields['max_input_variables'] = array(
    403                                 'label' => __( 'PHP max input variables' ),
    404                                 'value' => ini_get( 'max_input_vars' ),
    405                         );
    406                         $fields['time_limit']          = array(
    407                                 'label' => __( 'PHP time limit' ),
    408                                 'value' => ini_get( 'max_execution_time' ),
    409                         );
    410 
    411                         if ( WP_Site_Health::get_instance()->php_memory_limit !== ini_get( 'memory_limit' ) ) {
    412                                 $fields['memory_limit']       = array(
    413                                         'label' => __( 'PHP memory limit' ),
    414                                         'value' => WP_Site_Health::get_instance()->php_memory_limit,
    415                                 );
    416                                 $fields['admin_memory_limit'] = array(
    417                                         'label' => __( 'PHP memory limit (only for admin screens)' ),
    418                                         'value' => ini_get( 'memory_limit' ),
    419                                 );
    420                         } else {
    421                                 $fields['memory_limit'] = array(
    422                                         'label' => __( 'PHP memory limit' ),
    423                                         'value' => ini_get( 'memory_limit' ),
    424                                 );
    425                         }
    426 
    427                         $fields['max_input_time']      = array(
    428                                 'label' => __( 'Max input time' ),
    429                                 'value' => ini_get( 'max_input_time' ),
    430                         );
    431                         $fields['upload_max_filesize'] = array(
    432                                 'label' => __( 'Upload max filesize' ),
    433                                 'value' => ini_get( 'upload_max_filesize' ),
    434                         );
    435                         $fields['php_post_max_size']   = array(
    436                                 'label' => __( 'PHP post max size' ),
    437                                 'value' => ini_get( 'post_max_size' ),
    438                         );
    439                 }
     409                        $fields['memory_limit'] = array(
     410                                'label' => __( 'PHP memory limit' ),
     411                                'value' => ini_get( 'memory_limit' ),
     412                        );
     413                }
     414
     415                $fields['max_input_time']      = array(
     416                        'label' => __( 'Max input time' ),
     417                        'value' => ini_get( 'max_input_time' ),
     418                );
     419                $fields['upload_max_filesize'] = array(
     420                        'label' => __( 'Upload max filesize' ),
     421                        'value' => ini_get( 'upload_max_filesize' ),
     422                );
     423                $fields['php_post_max_size']   = array(
     424                        'label' => __( 'PHP post max size' ),
     425                        'value' => ini_get( 'post_max_size' ),
     426                );
    440427
    441428                if ( function_exists( 'curl_version' ) ) {
     
    677664                );
    678665
    679                 if ( ! function_exists( 'ini_get' ) ) {
    680                         $fields['ini_get'] = array(
    681                                 'label' => __( 'File upload settings' ),
    682                                 'value' => sprintf(
    683                                 /* translators: %s: ini_get() */
    684                                         __( 'Unable to determine some settings, as the %s function has been disabled.' ),
    685                                         'ini_get()'
    686                                 ),
    687                                 'debug' => 'ini_get() is disabled',
    688                         );
    689                 } else {
    690                         // Get the PHP ini directive values.
    691                         $file_uploads        = ini_get( 'file_uploads' );
    692                         $post_max_size       = ini_get( 'post_max_size' );
    693                         $upload_max_filesize = ini_get( 'upload_max_filesize' );
    694                         $max_file_uploads    = ini_get( 'max_file_uploads' );
    695                         $effective           = min( wp_convert_hr_to_bytes( $post_max_size ), wp_convert_hr_to_bytes( $upload_max_filesize ) );
    696 
    697                         // Add info in Media section.
    698                         $fields['file_uploads']        = array(
    699                                 'label' => __( 'File uploads' ),
    700                                 'value' => $file_uploads ? __( 'Enabled' ) : __( 'Disabled' ),
    701                                 'debug' => $file_uploads,
    702                         );
    703                         $fields['post_max_size']       = array(
    704                                 'label' => __( 'Max size of post data allowed' ),
    705                                 'value' => $post_max_size,
    706                         );
    707                         $fields['upload_max_filesize'] = array(
    708                                 'label' => __( 'Max size of an uploaded file' ),
    709                                 'value' => $upload_max_filesize,
    710                         );
    711                         $fields['max_effective_size']  = array(
    712                                 'label' => __( 'Max effective file size' ),
    713                                 'value' => size_format( $effective ),
    714                         );
    715                         $fields['max_file_uploads']    = array(
    716                                 'label' => __( 'Max simultaneous file uploads' ),
    717                                 'value' => $max_file_uploads,
    718                         );
    719                 }
     666                // Get the PHP ini directive values.
     667                $file_uploads        = ini_get( 'file_uploads' );
     668                $post_max_size       = ini_get( 'post_max_size' );
     669                $upload_max_filesize = ini_get( 'upload_max_filesize' );
     670                $max_file_uploads    = ini_get( 'max_file_uploads' );
     671                $effective           = min( wp_convert_hr_to_bytes( $post_max_size ), wp_convert_hr_to_bytes( $upload_max_filesize ) );
     672
     673                // Add info in Media section.
     674                $fields['file_uploads']        = array(
     675                        'label' => __( 'File uploads' ),
     676                        'value' => $file_uploads ? __( 'Enabled' ) : __( 'Disabled' ),
     677                        'debug' => $file_uploads,
     678                );
     679                $fields['post_max_size']       = array(
     680                        'label' => __( 'Max size of post data allowed' ),
     681                        'value' => $post_max_size,
     682                );
     683                $fields['upload_max_filesize'] = array(
     684                        'label' => __( 'Max size of an uploaded file' ),
     685                        'value' => $upload_max_filesize,
     686                );
     687                $fields['max_effective_size']  = array(
     688                        'label' => __( 'Max effective file size' ),
     689                        'value' => size_format( $effective ),
     690                );
     691                $fields['max_file_uploads']    = array(
     692                        'label' => __( 'Max simultaneous file uploads' ),
     693                        'value' => $max_file_uploads,
     694                );
    720695
    721696                // If Imagick is used as our editor, provide some more information about its limitations.
     
    19781953                 * hosts do not allow you to read configuration values.
    19791954                 */
    1980                 if ( function_exists( 'ini_get' ) ) {
    1981                         $max_execution_time = ini_get( 'max_execution_time' );
    1982                 }
     1955                $max_execution_time = ini_get( 'max_execution_time' );
    19831956
    19841957                /*
  • trunk/src/wp-admin/includes/class-wp-site-health.php

    r62550 r62634  
    23222322                        'test'        => 'file_uploads',
    23232323                );
    2324 
    2325                 if ( ! function_exists( 'ini_get' ) ) {
    2326                         $result['status']       = 'critical';
    2327                         $result['description'] .= sprintf(
    2328                                 /* translators: %s: ini_get() */
    2329                                 __( 'The %s function has been disabled, some media settings are unavailable because of this.' ),
    2330                                 '<code>ini_get()</code>'
    2331                         );
    2332                         return $result;
    2333                 }
    23342324
    23352325                if ( empty( ini_get( 'file_uploads' ) ) ) {
  • trunk/src/wp-includes/functions.php

    r62633 r62634  
    88798879        if ( null === $max_execution_time ) {
    88808880                // Keep the previous behavior but attempt to prevent fatal errors from timeout if possible.
    8881                 if ( function_exists( 'ini_get' ) ) {
    8882                         $max_execution_time = ini_get( 'max_execution_time' );
    8883                 } else {
    8884                         // Disable...
    8885                         $max_execution_time = 0;
    8886                 }
     8881                $max_execution_time = ini_get( 'max_execution_time' );
    88878882
    88888883                // Leave 1 second "buffer" for other operations if $max_execution_time has reasonable value.
Note: See TracChangeset for help on using the changeset viewer.