1414 */
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}
2224
@@ -58,7 +60,7 @@ function wp_fix_server_vars() {
5860
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 {
6466 $ _SERVER ['REQUEST_URI ' ] = $ _SERVER ['SCRIPT_NAME ' ] . $ _SERVER ['PATH_INFO ' ];
@@ -147,6 +149,7 @@ function wp_populate_basic_auth_from_authorization_header() {
147149 */
148150function wp_check_php_mysql_versions () {
149151 global $ required_php_version , $ wp_version ;
152+
150153 $ php_version = PHP_VERSION ;
151154
152155 if ( version_compare ( $ required_php_version , $ php_version , '> ' ) ) {
@@ -165,8 +168,7 @@ function wp_check_php_mysql_versions() {
165168 // This runs before default constants are defined, so we can't assume WP_CONTENT_DIR is set yet.
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 ) {
172174 require_once ABSPATH . WPINC . '/functions.php ' ;
@@ -307,6 +309,7 @@ function wp_get_development_mode() {
307309 'all ' ,
308310 '' ,
309311 );
312+
310313 if ( ! in_array ( $ development_mode , $ valid_modes , true ) ) {
311314 $ development_mode = '' ;
312315 }
@@ -408,6 +411,7 @@ function wp_is_maintenance_mode() {
408411 }
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 ) {
413417 return false ;
@@ -459,7 +463,9 @@ function timer_float() {
459463 */
460464function timer_start () {
461465 global $ timestart ;
466+
462467 $ timestart = microtime ( true );
468+
463469 return true ;
464470}
465471
@@ -480,12 +486,20 @@ function timer_start() {
480486 */
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}
491505
@@ -581,10 +595,10 @@ function wp_debug_mode() {
581595 error_reporting ( E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR );
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 }
590604}
@@ -604,7 +618,9 @@ function wp_debug_mode() {
604618 */
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.
610626 *
@@ -613,6 +629,7 @@ function wp_set_lang_dir() {
613629 * @since 2.1.0
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.
618635 define ( 'LANGDIR ' , 'wp-content/languages ' );
@@ -626,6 +643,7 @@ function wp_set_lang_dir() {
626643 * @since 2.1.0
627644 */
628645 define ( 'WP_LANG_DIR ' , ABSPATH . WPINC . '/languages ' );
646+
629647 if ( ! defined ( 'LANGDIR ' ) ) {
630648 // Old relative path maintained for backward compatibility.
631649 define ( 'LANGDIR ' , WPINC . '/languages ' );
@@ -676,6 +694,7 @@ function require_wp_db() {
676694 */
677695function wp_set_wpdb_vars () {
678696 global $ wpdb , $ table_prefix ;
697+
679698 if ( ! empty ( $ wpdb ->error ) ) {
680699 dead_db ();
681700 }
@@ -746,10 +765,13 @@ function wp_set_wpdb_vars() {
746765 */
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}
755777
@@ -793,6 +815,7 @@ function wp_start_object_cache() {
793815 */
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 );
798821 }
@@ -903,19 +926,24 @@ function wp_not_installed() {
903926 */
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 ) ) {
915941 $ mu_plugins [] = WPMU_PLUGIN_DIR . '/ ' . $ plugin ;
916942 }
917943 }
944+
918945 closedir ( $ dh );
946+
919947 sort ( $ mu_plugins );
920948
921949 return $ mu_plugins ;
@@ -957,7 +985,7 @@ function wp_get_active_and_valid_plugins() {
957985 && file_exists ( WP_PLUGIN_DIR . '/ ' . $ plugin ) // $plugin must exist.
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 }
963991 }
@@ -1386,6 +1414,7 @@ function is_multisite() {
13861414 */
13871415function get_current_blog_id () {
13881416 global $ blog_id ;
1417+
13891418 return absint ( $ blog_id );
13901419}
13911420
@@ -1428,11 +1457,12 @@ function get_current_network_id() {
14281457 */
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
14381468 if ( function_exists ( 'did_action ' ) && did_action ( 'init ' ) ) {
@@ -1501,9 +1531,11 @@ function wp_load_translations_early() {
15011531 foreach ( $ locations as $ location ) {
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 }
15091541 }
@@ -1538,6 +1570,7 @@ function wp_installing( $is_installing = null ) {
15381570 if ( ! is_null ( $ is_installing ) ) {
15391571 $ old_installing = $ installing ;
15401572 $ installing = $ is_installing ;
1573+
15411574 return (bool ) $ old_installing ;
15421575 }
15431576
@@ -1558,12 +1591,13 @@ function is_ssl() {
15581591 return true ;
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}
15691603
@@ -1617,7 +1651,9 @@ function wp_is_ini_value_changeable( $setting ) {
16171651 }
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 }
16231659
@@ -1739,6 +1775,7 @@ function wp_start_scraping_edited_file_errors() {
17391775 if ( ! isset ( $ _REQUEST ['wp_scrape_key ' ] ) || ! isset ( $ _REQUEST ['wp_scrape_nonce ' ] ) ) {
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 ' ] );
17441781
@@ -1753,9 +1790,11 @@ function wp_start_scraping_edited_file_errors() {
17531790 echo "###### wp_scraping_result_end: $ key ###### " ;
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}
17611800
@@ -1768,13 +1807,18 @@ function wp_start_scraping_edited_file_errors() {
17681807 */
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 );
17751818 } else {
17761819 echo wp_json_encode ( true );
17771820 }
1821+
17781822 echo "\n###### wp_scraping_result_end: $ scrape_key ###### \n" ;
17791823}
17801824
@@ -1787,7 +1831,6 @@ function wp_finalize_scraping_edited_file_errors( $scrape_key ) {
17871831 * False otherwise.
17881832 */
17891833function wp_is_json_request () {
1790-
17911834 if ( isset ( $ _SERVER ['HTTP_ACCEPT ' ] ) && wp_is_json_media_type ( $ _SERVER ['HTTP_ACCEPT ' ] ) ) {
17921835 return true ;
17931836 }
@@ -1797,7 +1840,6 @@ function wp_is_json_request() {
17971840 }
17981841
17991842 return false ;
1800-
18011843}
18021844
18031845/**
0 commit comments