Make WordPress Core

Changeset 56238


Ignore:
Timestamp:
07/15/2023 09:02:37 AM (3 years ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Use strict comparison in wp-includes/load.php.

Includes minor code layout fixes for better readability.

Follow-up to [6058], [6208], [10217], [12732], [37677].

Props aristath, poena, afercia, SergeyBiryukov.
See #57839.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/load.php

    r56232 r56238  
    1515function wp_get_server_protocol() {
    1616        $protocol = isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : '';
     17
    1718        if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0', 'HTTP/3' ), true ) ) {
    1819                $protocol = 'HTTP/1.0';
    1920        }
     21
    2022        return $protocol;
    2123}
    … …  
    5961                        // Some IIS + PHP configurations put the script-name in the path-info (no need to append it twice).
    6062                        if ( isset( $_SERVER['PATH_INFO'] ) ) {
    61                                 if ( $_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME'] ) {
     63                                if ( $_SERVER['PATH_INFO'] === $_SERVER['SCRIPT_NAME'] ) {
    6264                                        $_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'];
    6365                                } else {
    … …  
    148150function wp_check_php_mysql_versions() {
    149151        global $required_php_version, $wp_version;
     152
    150153        $php_version = PHP_VERSION;
    151154
    … …  
    166169        $wp_content_dir = defined( 'WP_CONTENT_DIR' ) ? WP_CONTENT_DIR : ABSPATH . 'wp-content';
    167170
    168         if ( ! function_exists( 'mysqli_connect' )
    169                 && ! function_exists( 'mysql_connect' )
     171        if ( ! function_exists( 'mysqli_connect' ) && ! function_exists( 'mysql_connect' )
    170172                && ! file_exists( $wp_content_dir . '/db.php' )
    171173        ) {
    … …  
    308310                '',
    309311        );
     312
    310313        if ( ! in_array( $development_mode, $valid_modes, true ) ) {
    311314                $development_mode = '';
    … …  
    409412
    410413        require ABSPATH . '.maintenance';
     414
    411415        // If the $upgrading timestamp is older than 10 minutes, consider maintenance over.
    412416        if ( ( time() - $upgrading ) >= 10 * MINUTE_IN_SECONDS ) {
    … …  
    460464function timer_start() {
    461465        global $timestart;
     466
    462467        $timestart = microtime( true );
     468
    463469        return true;
    464470}
    … …  
    481487function timer_stop( $display = 0, $precision = 3 ) {
    482488        global $timestart, $timeend;
     489
    483490        $timeend   = microtime( true );
    484491        $timetotal = $timeend - $timestart;
    485         $r         = ( function_exists( 'number_format_i18n' ) ) ? number_format_i18n( $timetotal, $precision ) : number_format( $timetotal, $precision );
     492
     493        if ( function_exists( 'number_format_i18n' ) ) {
     494                $r = number_format_i18n( $timetotal, $precision );
     495        } else {
     496                $r = number_format( $timetotal, $precision );
     497        }
     498
    486499        if ( $display ) {
    487500                echo $r;
    488501        }
     502
    489503        return $r;
    490504}
    … …  
    582596        }
    583597
    584         if (
    585                 defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || defined( 'MS_FILES_REQUEST' ) ||
    586                 ( defined( 'WP_INSTALLING' ) && WP_INSTALLING ) ||
    587                 wp_doing_ajax() || wp_is_json_request() ) {
     598        if ( defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || defined( 'MS_FILES_REQUEST' )
     599                || ( defined( 'WP_INSTALLING' ) && WP_INSTALLING )
     600                || wp_doing_ajax() || wp_is_json_request()
     601        ) {
    588602                ini_set( 'display_errors', 0 );
    589603        }
    … …  
    605619function wp_set_lang_dir() {
    606620        if ( ! defined( 'WP_LANG_DIR' ) ) {
    607                 if ( file_exists( WP_CONTENT_DIR . '/languages' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) || ! @is_dir( ABSPATH . WPINC . '/languages' ) ) {
     621                if ( file_exists( WP_CONTENT_DIR . '/languages' ) && @is_dir( WP_CONTENT_DIR . '/languages' )
     622                        || ! @is_dir( ABSPATH . WPINC . '/languages' )
     623                ) {
    608624                        /**
    609625                         * Server path of the language directory.
    … …  
    614630                         */
    615631                        define( 'WP_LANG_DIR', WP_CONTENT_DIR . '/languages' );
     632
    616633                        if ( ! defined( 'LANGDIR' ) ) {
    617634                                // Old static relative path maintained for limited backward compatibility - won't work in some cases.
    … …  
    627644                         */
    628645                        define( 'WP_LANG_DIR', ABSPATH . WPINC . '/languages' );
     646
    629647                        if ( ! defined( 'LANGDIR' ) ) {
    630648                                // Old relative path maintained for backward compatibility.
    … …  
    677695function wp_set_wpdb_vars() {
    678696        global $wpdb, $table_prefix;
     697
    679698        if ( ! empty( $wpdb->error ) ) {
    680699                dead_db();
    … …  
    747766function wp_using_ext_object_cache( $using = null ) {
    748767        global $_wp_using_ext_object_cache;
     768
    749769        $current_using = $_wp_using_ext_object_cache;
     770
    750771        if ( null !== $using ) {
    751772                $_wp_using_ext_object_cache = $using;
    752773        }
     774
    753775        return $current_using;
    754776}
    … …  
    794816                        if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
    795817                                require_once WP_CONTENT_DIR . '/object-cache.php';
     818
    796819                                if ( function_exists( 'wp_cache_init' ) ) {
    797820                                        wp_using_ext_object_cache( true );
    … …  
    904927function wp_get_mu_plugins() {
    905928        $mu_plugins = array();
     929
    906930        if ( ! is_dir( WPMU_PLUGIN_DIR ) ) {
    907931                return $mu_plugins;
    908932        }
     933
    909934        $dh = opendir( WPMU_PLUGIN_DIR );
    910935        if ( ! $dh ) {
    911936                return $mu_plugins;
    912937        }
     938
    913939        while ( ( $plugin = readdir( $dh ) ) !== false ) {
    914940                if ( '.php' === substr( $plugin, -4 ) ) {
    … …  
    916942                }
    917943        }
     944
    918945        closedir( $dh );
     946
    919947        sort( $mu_plugins );
    920948
    … …  
    958986                        // Not already included as a network plugin.
    959987                        && ( ! $network_plugins || ! in_array( WP_PLUGIN_DIR . '/' . $plugin, $network_plugins, true ) )
    960                         ) {
     988                ) {
    961989                        $plugins[] = WP_PLUGIN_DIR . '/' . $plugin;
    962990                }
    … …  
    13871415function get_current_blog_id() {
    13881416        global $blog_id;
     1417
    13891418        return absint( $blog_id );
    13901419}
    … …  
    14291458function wp_load_translations_early() {
    14301459        global $wp_textdomain_registry, $wp_locale;
    1431 
    14321460        static $loaded = false;
     1461
    14331462        if ( $loaded ) {
    14341463                return;
    14351464        }
     1465
    14361466        $loaded = true;
    14371467
    … …  
    15021532                                if ( file_exists( $location . '/' . $locale . '.mo' ) ) {
    15031533                                        load_textdomain( 'default', $location . '/' . $locale . '.mo', $locale );
     1534
    15041535                                        if ( defined( 'WP_SETUP_CONFIG' ) && file_exists( $location . '/admin-' . $locale . '.mo' ) ) {
    15051536                                                load_textdomain( 'default', $location . '/admin-' . $locale . '.mo', $locale );
    15061537                                        }
     1538
    15071539                                        break 2;
    15081540                                }
    … …  
    15391571                $old_installing = $installing;
    15401572                $installing     = $is_installing;
     1573
    15411574                return (bool) $old_installing;
    15421575        }
    … …  
    15591592                }
    15601593
    1561                 if ( '1' == $_SERVER['HTTPS'] ) {
     1594                if ( '1' === (string) $_SERVER['HTTPS'] ) {
    15621595                        return true;
    15631596                }
    1564         } elseif ( isset( $_SERVER['SERVER_PORT'] ) && ( '443' == $_SERVER['SERVER_PORT'] ) ) {
     1597        } elseif ( isset( $_SERVER['SERVER_PORT'] ) && ( '443' === (string) $_SERVER['SERVER_PORT'] ) ) {
    15651598                return true;
    15661599        }
     1600
    15671601        return false;
    15681602}
    … …  
    16181652
    16191653        // Bit operator to workaround https://bugs.php.net/bug.php?id=44936 which changes access level to 63 in PHP 5.2.6 - 5.2.17.
    1620         if ( isset( $ini_all[ $setting ]['access'] ) && ( INI_ALL === ( $ini_all[ $setting ]['access'] & 7 ) || INI_USER === ( $ini_all[ $setting ]['access'] & 7 ) ) ) {
     1654        if ( isset( $ini_all[ $setting ]['access'] )
     1655                && ( INI_ALL === ( $ini_all[ $setting ]['access'] & 7 ) || INI_USER === ( $ini_all[ $setting ]['access'] & 7 ) )
     1656        ) {
    16211657                return true;
    16221658        }
    … …  
    17401776                return;
    17411777        }
     1778
    17421779        $key   = substr( sanitize_key( wp_unslash( $_REQUEST['wp_scrape_key'] ) ), 0, 32 );
    17431780        $nonce = wp_unslash( $_REQUEST['wp_scrape_nonce'] );
    … …  
    17541791                die();
    17551792        }
     1793
    17561794        if ( ! defined( 'WP_SANDBOX_SCRAPING' ) ) {
    17571795                define( 'WP_SANDBOX_SCRAPING', true );
    17581796        }
     1797
    17591798        register_shutdown_function( 'wp_finalize_scraping_edited_file_errors', $key );
    17601799}
    … …  
    17691808function wp_finalize_scraping_edited_file_errors( $scrape_key ) {
    17701809        $error = error_get_last();
     1810
    17711811        echo "\n###### wp_scraping_result_start:$scrape_key ######\n";
    1772         if ( ! empty( $error ) && in_array( $error['type'], array( E_CORE_ERROR, E_COMPILE_ERROR, E_ERROR, E_PARSE, E_USER_ERROR, E_RECOVERABLE_ERROR ), true ) ) {
     1812
     1813        if ( ! empty( $error )
     1814                && in_array( $error['type'], array( E_CORE_ERROR, E_COMPILE_ERROR, E_ERROR, E_PARSE, E_USER_ERROR, E_RECOVERABLE_ERROR ), true )
     1815        ) {
    17731816                $error = str_replace( ABSPATH, '', $error );
    17741817                echo wp_json_encode( $error );
    … …  
    17761819                echo wp_json_encode( true );
    17771820        }
     1821
    17781822        echo "\n###### wp_scraping_result_end:$scrape_key ######\n";
    17791823}
    … …  
    17881832 */
    17891833function wp_is_json_request() {
    1790 
    17911834        if ( isset( $_SERVER['HTTP_ACCEPT'] ) && wp_is_json_media_type( $_SERVER['HTTP_ACCEPT'] ) ) {
    17921835                return true;
    … …  
    17981841
    17991842        return false;
    1800 
    18011843}
    18021844
Note: See TracChangeset for help on using the changeset viewer.