[ Index ] |
PHP Cross Reference of WordPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * These functions are needed to load WordPress. 4 * 5 * @package WordPress 6 */ 7 8 /** 9 * Return the HTTP protocol sent by the server. 10 * 11 * @since 4.4.0 12 * 13 * @return string The HTTP protocol. Default: HTTP/1.0. 14 */ 15 function wp_get_server_protocol() { 16 $protocol = isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : ''; 17 if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0', 'HTTP/3' ), true ) ) { 18 $protocol = 'HTTP/1.0'; 19 } 20 return $protocol; 21 } 22 23 /** 24 * Fix `$_SERVER` variables for various setups. 25 * 26 * @since 3.0.0 27 * @access private 28 * 29 * @global string $PHP_SELF The filename of the currently executing script, 30 * relative to the document root. 31 */ 32 function wp_fix_server_vars() { 33 global $PHP_SELF; 34 35 $default_server_values = array( 36 'SERVER_SOFTWARE' => '', 37 'REQUEST_URI' => '', 38 ); 39 40 $_SERVER = array_merge( $default_server_values, $_SERVER ); 41 42 // Fix for IIS when running with PHP ISAPI. 43 if ( empty( $_SERVER['REQUEST_URI'] ) || ( 'cgi-fcgi' !== PHP_SAPI && preg_match( '/^Microsoft-IIS\//', $_SERVER['SERVER_SOFTWARE'] ) ) ) { 44 45 if ( isset( $_SERVER['HTTP_X_ORIGINAL_URL'] ) ) { 46 // IIS Mod-Rewrite. 47 $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL']; 48 } elseif ( isset( $_SERVER['HTTP_X_REWRITE_URL'] ) ) { 49 // IIS Isapi_Rewrite. 50 $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL']; 51 } else { 52 // Use ORIG_PATH_INFO if there is no PATH_INFO. 53 if ( ! isset( $_SERVER['PATH_INFO'] ) && isset( $_SERVER['ORIG_PATH_INFO'] ) ) { 54 $_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO']; 55 } 56 57 // Some IIS + PHP configurations put the script-name in the path-info (no need to append it twice). 58 if ( isset( $_SERVER['PATH_INFO'] ) ) { 59 if ( $_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME'] ) { 60 $_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO']; 61 } else { 62 $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO']; 63 } 64 } 65 66 // Append the query string if it exists and isn't null. 67 if ( ! empty( $_SERVER['QUERY_STRING'] ) ) { 68 $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; 69 } 70 } 71 } 72 73 // Fix for PHP as CGI hosts that set SCRIPT_FILENAME to something ending in php.cgi for all requests. 74 if ( isset( $_SERVER['SCRIPT_FILENAME'] ) && ( strpos( $_SERVER['SCRIPT_FILENAME'], 'php.cgi' ) == strlen( $_SERVER['SCRIPT_FILENAME'] ) - 7 ) ) { 75 $_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED']; 76 } 77 78 // Fix for Dreamhost and other PHP as CGI hosts. 79 if ( isset( $_SERVER['SCRIPT_NAME'] ) && ( strpos( $_SERVER['SCRIPT_NAME'], 'php.cgi' ) !== false ) ) { 80 unset( $_SERVER['PATH_INFO'] ); 81 } 82 83 // Fix empty PHP_SELF. 84 $PHP_SELF = $_SERVER['PHP_SELF']; 85 if ( empty( $PHP_SELF ) ) { 86 $_SERVER['PHP_SELF'] = preg_replace( '/(\?.*)?$/', '', $_SERVER['REQUEST_URI'] ); 87 $PHP_SELF = $_SERVER['PHP_SELF']; 88 } 89 90 wp_populate_basic_auth_from_authorization_header(); 91 } 92 93 /** 94 * Populates the Basic Auth server details from the Authorization header. 95 * 96 * Some servers running in CGI or FastCGI mode don't pass the Authorization 97 * header on to WordPress. If it's been rewritten to the `HTTP_AUTHORIZATION` header, 98 * fill in the proper $_SERVER variables instead. 99 * 100 * @since 5.6.0 101 */ 102 function wp_populate_basic_auth_from_authorization_header() { 103 // If we don't have anything to pull from, return early. 104 if ( ! isset( $_SERVER['HTTP_AUTHORIZATION'] ) && ! isset( $_SERVER['REDIRECT_HTTP_AUTHORIZATION'] ) ) { 105 return; 106 } 107 108 // If either PHP_AUTH key is already set, do nothing. 109 if ( isset( $_SERVER['PHP_AUTH_USER'] ) || isset( $_SERVER['PHP_AUTH_PW'] ) ) { 110 return; 111 } 112 113 // From our prior conditional, one of these must be set. 114 $header = isset( $_SERVER['HTTP_AUTHORIZATION'] ) ? $_SERVER['HTTP_AUTHORIZATION'] : $_SERVER['REDIRECT_HTTP_AUTHORIZATION']; 115 116 // Test to make sure the pattern matches expected. 117 if ( ! preg_match( '%^Basic [a-z\d/+]*={0,2}$%i', $header ) ) { 118 return; 119 } 120 121 // Removing `Basic ` the token would start six characters in. 122 $token = substr( $header, 6 ); 123 $userpass = base64_decode( $token ); 124 125 list( $user, $pass ) = explode( ':', $userpass ); 126 127 // Now shove them in the proper keys where we're expecting later on. 128 $_SERVER['PHP_AUTH_USER'] = $user; 129 $_SERVER['PHP_AUTH_PW'] = $pass; 130 } 131 132 /** 133 * Check for the required PHP version, and the MySQL extension or 134 * a database drop-in. 135 * 136 * Dies if requirements are not met. 137 * 138 * @since 3.0.0 139 * @access private 140 * 141 * @global string $required_php_version The required PHP version string. 142 * @global string $wp_version The WordPress version string. 143 */ 144 function wp_check_php_mysql_versions() { 145 global $required_php_version, $wp_version; 146 $php_version = phpversion(); 147 148 if ( version_compare( $required_php_version, $php_version, '>' ) ) { 149 $protocol = wp_get_server_protocol(); 150 header( sprintf( '%s 500 Internal Server Error', $protocol ), true, 500 ); 151 header( 'Content-Type: text/html; charset=utf-8' ); 152 printf( 'Your server is running PHP version %1$s but WordPress %2$s requires at least %3$s.', $php_version, $wp_version, $required_php_version ); 153 exit( 1 ); 154 } 155 156 if ( ! extension_loaded( 'mysql' ) && ! extension_loaded( 'mysqli' ) && ! extension_loaded( 'mysqlnd' ) 157 // This runs before default constants are defined, so we can't assume WP_CONTENT_DIR is set yet. 158 && ( defined( 'WP_CONTENT_DIR' ) && ! file_exists( WP_CONTENT_DIR . '/db.php' ) 159 || ! file_exists( ABSPATH . 'wp-content/db.php' ) ) 160 ) { 161 require_once ABSPATH . WPINC . '/functions.php'; 162 wp_load_translations_early(); 163 $args = array( 164 'exit' => false, 165 'code' => 'mysql_not_found', 166 ); 167 wp_die( 168 __( 'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.' ), 169 __( 'Requirements Not Met' ), 170 $args 171 ); 172 exit( 1 ); 173 } 174 } 175 176 /** 177 * Retrieves the current environment type. 178 * 179 * The type can be set via the `WP_ENVIRONMENT_TYPE` global system variable, 180 * or a constant of the same name. 181 * 182 * Possible values are 'local', 'development', 'staging', and 'production'. 183 * If not set, the type defaults to 'production'. 184 * 185 * @since 5.5.0 186 * @since 5.5.1 Added the 'local' type. 187 * @since 5.5.1 Removed the ability to alter the list of types. 188 * 189 * @return string The current environment type. 190 */ 191 function wp_get_environment_type() { 192 static $current_env = ''; 193 194 if ( ! defined( 'WP_RUN_CORE_TESTS' ) && $current_env ) { 195 return $current_env; 196 } 197 198 $wp_environments = array( 199 'local', 200 'development', 201 'staging', 202 'production', 203 ); 204 205 // Add a note about the deprecated WP_ENVIRONMENT_TYPES constant. 206 if ( defined( 'WP_ENVIRONMENT_TYPES' ) && function_exists( '_deprecated_argument' ) ) { 207 if ( function_exists( '__' ) ) { 208 /* translators: %s: WP_ENVIRONMENT_TYPES */ 209 $message = sprintf( __( 'The %s constant is no longer supported.' ), 'WP_ENVIRONMENT_TYPES' ); 210 } else { 211 $message = sprintf( 'The %s constant is no longer supported.', 'WP_ENVIRONMENT_TYPES' ); 212 } 213 214 _deprecated_argument( 215 'define()', 216 '5.5.1', 217 $message 218 ); 219 } 220 221 // Check if the environment variable has been set, if `getenv` is available on the system. 222 if ( function_exists( 'getenv' ) ) { 223 $has_env = getenv( 'WP_ENVIRONMENT_TYPE' ); 224 if ( false !== $has_env ) { 225 $current_env = $has_env; 226 } 227 } 228 229 // Fetch the environment from a constant, this overrides the global system variable. 230 if ( defined( 'WP_ENVIRONMENT_TYPE' ) ) { 231 $current_env = WP_ENVIRONMENT_TYPE; 232 } 233 234 // Make sure the environment is an allowed one, and not accidentally set to an invalid value. 235 if ( ! in_array( $current_env, $wp_environments, true ) ) { 236 $current_env = 'production'; 237 } 238 239 return $current_env; 240 } 241 242 /** 243 * Don't load all of WordPress when handling a favicon.ico request. 244 * 245 * Instead, send the headers for a zero-length favicon and bail. 246 * 247 * @since 3.0.0 248 * @deprecated 5.4.0 Deprecated in favor of do_favicon(). 249 */ 250 function wp_favicon_request() { 251 if ( '/favicon.ico' === $_SERVER['REQUEST_URI'] ) { 252 header( 'Content-Type: image/vnd.microsoft.icon' ); 253 exit; 254 } 255 } 256 257 /** 258 * Die with a maintenance message when conditions are met. 259 * 260 * The default message can be replaced by using a drop-in (maintenance.php in 261 * the wp-content directory). 262 * 263 * @since 3.0.0 264 * @access private 265 */ 266 function wp_maintenance() { 267 // Return if maintenance mode is disabled. 268 if ( ! wp_is_maintenance_mode() ) { 269 return; 270 } 271 272 if ( file_exists( WP_CONTENT_DIR . '/maintenance.php' ) ) { 273 require_once WP_CONTENT_DIR . '/maintenance.php'; 274 die(); 275 } 276 277 require_once ABSPATH . WPINC . '/functions.php'; 278 wp_load_translations_early(); 279 280 header( 'Retry-After: 600' ); 281 282 wp_die( 283 __( 'Briefly unavailable for scheduled maintenance. Check back in a minute.' ), 284 __( 'Maintenance' ), 285 503 286 ); 287 } 288 289 /** 290 * Check if maintenance mode is enabled. 291 * 292 * Checks for a file in the WordPress root directory named ".maintenance". 293 * This file will contain the variable $upgrading, set to the time the file 294 * was created. If the file was created less than 10 minutes ago, WordPress 295 * is in maintenance mode. 296 * 297 * @since 5.5.0 298 * 299 * @global int $upgrading The Unix timestamp marking when upgrading WordPress began. 300 * 301 * @return bool True if maintenance mode is enabled, false otherwise. 302 */ 303 function wp_is_maintenance_mode() { 304 global $upgrading; 305 306 if ( ! file_exists( ABSPATH . '.maintenance' ) || wp_installing() ) { 307 return false; 308 } 309 310 require ABSPATH . '.maintenance'; 311 // If the $upgrading timestamp is older than 10 minutes, consider maintenance over. 312 if ( ( time() - $upgrading ) >= 10 * MINUTE_IN_SECONDS ) { 313 return false; 314 } 315 316 /** 317 * Filters whether to enable maintenance mode. 318 * 319 * This filter runs before it can be used by plugins. It is designed for 320 * non-web runtimes. If this filter returns true, maintenance mode will be 321 * active and the request will end. If false, the request will be allowed to 322 * continue processing even if maintenance mode should be active. 323 * 324 * @since 4.6.0 325 * 326 * @param bool $enable_checks Whether to enable maintenance mode. Default true. 327 * @param int $upgrading The timestamp set in the .maintenance file. 328 */ 329 if ( ! apply_filters( 'enable_maintenance_mode', true, $upgrading ) ) { 330 return false; 331 } 332 333 return true; 334 } 335 336 /** 337 * Get the time elapsed so far during this PHP script. 338 * 339 * Uses REQUEST_TIME_FLOAT that appeared in PHP 5.4.0. 340 * 341 * @since 5.8.0 342 * 343 * @return float Seconds since the PHP script started. 344 */ 345 function timer_float() { 346 return microtime( true ) - $_SERVER['REQUEST_TIME_FLOAT']; 347 } 348 349 /** 350 * Start the WordPress micro-timer. 351 * 352 * @since 0.71 353 * @access private 354 * 355 * @global float $timestart Unix timestamp set at the beginning of the page load. 356 * @see timer_stop() 357 * 358 * @return bool Always returns true. 359 */ 360 function timer_start() { 361 global $timestart; 362 $timestart = microtime( true ); 363 return true; 364 } 365 366 /** 367 * Retrieve or display the time from the page start to when function is called. 368 * 369 * @since 0.71 370 * 371 * @global float $timestart Seconds from when timer_start() is called. 372 * @global float $timeend Seconds from when function is called. 373 * 374 * @param int|bool $display Whether to echo or return the results. Accepts 0|false for return, 375 * 1|true for echo. Default 0|false. 376 * @param int $precision The number of digits from the right of the decimal to display. 377 * Default 3. 378 * @return string The "second.microsecond" finished time calculation. The number is formatted 379 * for human consumption, both localized and rounded. 380 */ 381 function timer_stop( $display = 0, $precision = 3 ) { 382 global $timestart, $timeend; 383 $timeend = microtime( true ); 384 $timetotal = $timeend - $timestart; 385 $r = ( function_exists( 'number_format_i18n' ) ) ? number_format_i18n( $timetotal, $precision ) : number_format( $timetotal, $precision ); 386 if ( $display ) { 387 echo $r; 388 } 389 return $r; 390 } 391 392 /** 393 * Set PHP error reporting based on WordPress debug settings. 394 * 395 * Uses three constants: `WP_DEBUG`, `WP_DEBUG_DISPLAY`, and `WP_DEBUG_LOG`. 396 * All three can be defined in wp-config.php. By default, `WP_DEBUG` and 397 * `WP_DEBUG_LOG` are set to false, and `WP_DEBUG_DISPLAY` is set to true. 398 * 399 * When `WP_DEBUG` is true, all PHP notices are reported. WordPress will also 400 * display internal notices: when a deprecated WordPress function, function 401 * argument, or file is used. Deprecated code may be removed from a later 402 * version. 403 * 404 * It is strongly recommended that plugin and theme developers use `WP_DEBUG` 405 * in their development environments. 406 * 407 * `WP_DEBUG_DISPLAY` and `WP_DEBUG_LOG` perform no function unless `WP_DEBUG` 408 * is true. 409 * 410 * When `WP_DEBUG_DISPLAY` is true, WordPress will force errors to be displayed. 411 * `WP_DEBUG_DISPLAY` defaults to true. Defining it as null prevents WordPress 412 * from changing the global configuration setting. Defining `WP_DEBUG_DISPLAY` 413 * as false will force errors to be hidden. 414 * 415 * When `WP_DEBUG_LOG` is true, errors will be logged to `wp-content/debug.log`. 416 * When `WP_DEBUG_LOG` is a valid path, errors will be logged to the specified file. 417 * 418 * Errors are never displayed for XML-RPC, REST, `ms-files.php`, and Ajax requests. 419 * 420 * @since 3.0.0 421 * @since 5.1.0 `WP_DEBUG_LOG` can be a file path. 422 * @access private 423 */ 424 function wp_debug_mode() { 425 /** 426 * Filters whether to allow the debug mode check to occur. 427 * 428 * This filter runs before it can be used by plugins. It is designed for 429 * non-web runtimes. Returning false causes the `WP_DEBUG` and related 430 * constants to not be checked and the default PHP values for errors 431 * will be used unless you take care to update them yourself. 432 * 433 * To use this filter you must define a `$wp_filter` global before 434 * WordPress loads, usually in `wp-config.php`. 435 * 436 * Example: 437 * 438 * $GLOBALS['wp_filter'] = array( 439 * 'enable_wp_debug_mode_checks' => array( 440 * 10 => array( 441 * array( 442 * 'accepted_args' => 0, 443 * 'function' => function() { 444 * return false; 445 * }, 446 * ), 447 * ), 448 * ), 449 * ); 450 * 451 * @since 4.6.0 452 * 453 * @param bool $enable_debug_mode Whether to enable debug mode checks to occur. Default true. 454 */ 455 if ( ! apply_filters( 'enable_wp_debug_mode_checks', true ) ) { 456 return; 457 } 458 459 if ( WP_DEBUG ) { 460 error_reporting( E_ALL ); 461 462 if ( WP_DEBUG_DISPLAY ) { 463 ini_set( 'display_errors', 1 ); 464 } elseif ( null !== WP_DEBUG_DISPLAY ) { 465 ini_set( 'display_errors', 0 ); 466 } 467 468 if ( in_array( strtolower( (string) WP_DEBUG_LOG ), array( 'true', '1' ), true ) ) { 469 $log_path = WP_CONTENT_DIR . '/debug.log'; 470 } elseif ( is_string( WP_DEBUG_LOG ) ) { 471 $log_path = WP_DEBUG_LOG; 472 } else { 473 $log_path = false; 474 } 475 476 if ( $log_path ) { 477 ini_set( 'log_errors', 1 ); 478 ini_set( 'error_log', $log_path ); 479 } 480 } else { 481 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 ); 482 } 483 484 if ( 485 defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || defined( 'MS_FILES_REQUEST' ) || 486 ( defined( 'WP_INSTALLING' ) && WP_INSTALLING ) || 487 wp_doing_ajax() || wp_is_json_request() ) { 488 ini_set( 'display_errors', 0 ); 489 } 490 } 491 492 /** 493 * Set the location of the language directory. 494 * 495 * To set directory manually, define the `WP_LANG_DIR` constant 496 * in wp-config.php. 497 * 498 * If the language directory exists within `WP_CONTENT_DIR`, it 499 * is used. Otherwise the language directory is assumed to live 500 * in `WPINC`. 501 * 502 * @since 3.0.0 503 * @access private 504 */ 505 function wp_set_lang_dir() { 506 if ( ! defined( 'WP_LANG_DIR' ) ) { 507 if ( file_exists( WP_CONTENT_DIR . '/languages' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) || ! @is_dir( ABSPATH . WPINC . '/languages' ) ) { 508 /** 509 * Server path of the language directory. 510 * 511 * No leading slash, no trailing slash, full path, not relative to ABSPATH 512 * 513 * @since 2.1.0 514 */ 515 define( 'WP_LANG_DIR', WP_CONTENT_DIR . '/languages' ); 516 if ( ! defined( 'LANGDIR' ) ) { 517 // Old static relative path maintained for limited backward compatibility - won't work in some cases. 518 define( 'LANGDIR', 'wp-content/languages' ); 519 } 520 } else { 521 /** 522 * Server path of the language directory. 523 * 524 * No leading slash, no trailing slash, full path, not relative to `ABSPATH`. 525 * 526 * @since 2.1.0 527 */ 528 define( 'WP_LANG_DIR', ABSPATH . WPINC . '/languages' ); 529 if ( ! defined( 'LANGDIR' ) ) { 530 // Old relative path maintained for backward compatibility. 531 define( 'LANGDIR', WPINC . '/languages' ); 532 } 533 } 534 } 535 } 536 537 /** 538 * Load the database class file and instantiate the `$wpdb` global. 539 * 540 * @since 2.5.0 541 * 542 * @global wpdb $wpdb WordPress database abstraction object. 543 */ 544 function require_wp_db() { 545 global $wpdb; 546 547 require_once ABSPATH . WPINC . '/wp-db.php'; 548 if ( file_exists( WP_CONTENT_DIR . '/db.php' ) ) { 549 require_once WP_CONTENT_DIR . '/db.php'; 550 } 551 552 if ( isset( $wpdb ) ) { 553 return; 554 } 555 556 $dbuser = defined( 'DB_USER' ) ? DB_USER : ''; 557 $dbpassword = defined( 'DB_PASSWORD' ) ? DB_PASSWORD : ''; 558 $dbname = defined( 'DB_NAME' ) ? DB_NAME : ''; 559 $dbhost = defined( 'DB_HOST' ) ? DB_HOST : ''; 560 561 $wpdb = new wpdb( $dbuser, $dbpassword, $dbname, $dbhost ); 562 } 563 564 /** 565 * Set the database table prefix and the format specifiers for database 566 * table columns. 567 * 568 * Columns not listed here default to `%s`. 569 * 570 * @since 3.0.0 571 * @access private 572 * 573 * @global wpdb $wpdb WordPress database abstraction object. 574 * @global string $table_prefix The database table prefix. 575 */ 576 function wp_set_wpdb_vars() { 577 global $wpdb, $table_prefix; 578 if ( ! empty( $wpdb->error ) ) { 579 dead_db(); 580 } 581 582 $wpdb->field_types = array( 583 'post_author' => '%d', 584 'post_parent' => '%d', 585 'menu_order' => '%d', 586 'term_id' => '%d', 587 'term_group' => '%d', 588 'term_taxonomy_id' => '%d', 589 'parent' => '%d', 590 'count' => '%d', 591 'object_id' => '%d', 592 'term_order' => '%d', 593 'ID' => '%d', 594 'comment_ID' => '%d', 595 'comment_post_ID' => '%d', 596 'comment_parent' => '%d', 597 'user_id' => '%d', 598 'link_id' => '%d', 599 'link_owner' => '%d', 600 'link_rating' => '%d', 601 'option_id' => '%d', 602 'blog_id' => '%d', 603 'meta_id' => '%d', 604 'post_id' => '%d', 605 'user_status' => '%d', 606 'umeta_id' => '%d', 607 'comment_karma' => '%d', 608 'comment_count' => '%d', 609 // Multisite: 610 'active' => '%d', 611 'cat_id' => '%d', 612 'deleted' => '%d', 613 'lang_id' => '%d', 614 'mature' => '%d', 615 'public' => '%d', 616 'site_id' => '%d', 617 'spam' => '%d', 618 ); 619 620 $prefix = $wpdb->set_prefix( $table_prefix ); 621 622 if ( is_wp_error( $prefix ) ) { 623 wp_load_translations_early(); 624 wp_die( 625 sprintf( 626 /* translators: 1: $table_prefix, 2: wp-config.php */ 627 __( '<strong>Error</strong>: %1$s in %2$s can only contain numbers, letters, and underscores.' ), 628 '<code>$table_prefix</code>', 629 '<code>wp-config.php</code>' 630 ) 631 ); 632 } 633 } 634 635 /** 636 * Toggle `$_wp_using_ext_object_cache` on and off without directly 637 * touching global. 638 * 639 * @since 3.7.0 640 * 641 * @global bool $_wp_using_ext_object_cache 642 * 643 * @param bool $using Whether external object cache is being used. 644 * @return bool The current 'using' setting. 645 */ 646 function wp_using_ext_object_cache( $using = null ) { 647 global $_wp_using_ext_object_cache; 648 $current_using = $_wp_using_ext_object_cache; 649 if ( null !== $using ) { 650 $_wp_using_ext_object_cache = $using; 651 } 652 return $current_using; 653 } 654 655 /** 656 * Start the WordPress object cache. 657 * 658 * If an object-cache.php file exists in the wp-content directory, 659 * it uses that drop-in as an external object cache. 660 * 661 * @since 3.0.0 662 * @access private 663 * 664 * @global array $wp_filter Stores all of the filters. 665 */ 666 function wp_start_object_cache() { 667 global $wp_filter; 668 static $first_init = true; 669 670 // Only perform the following checks once. 671 672 /** 673 * Filters whether to enable loading of the object-cache.php drop-in. 674 * 675 * This filter runs before it can be used by plugins. It is designed for non-web 676 * runtimes. If false is returned, object-cache.php will never be loaded. 677 * 678 * @since 5.8.0 679 * 680 * @param bool $enable_object_cache Whether to enable loading object-cache.php (if present). 681 * Default true. 682 */ 683 if ( $first_init && apply_filters( 'enable_loading_object_cache_dropin', true ) ) { 684 if ( ! function_exists( 'wp_cache_init' ) ) { 685 /* 686 * This is the normal situation. First-run of this function. No 687 * caching backend has been loaded. 688 * 689 * We try to load a custom caching backend, and then, if it 690 * results in a wp_cache_init() function existing, we note 691 * that an external object cache is being used. 692 */ 693 if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) { 694 require_once WP_CONTENT_DIR . '/object-cache.php'; 695 if ( function_exists( 'wp_cache_init' ) ) { 696 wp_using_ext_object_cache( true ); 697 } 698 699 // Re-initialize any hooks added manually by object-cache.php. 700 if ( $wp_filter ) { 701 $wp_filter = WP_Hook::build_preinitialized_hooks( $wp_filter ); 702 } 703 } 704 } elseif ( ! wp_using_ext_object_cache() && file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) { 705 /* 706 * Sometimes advanced-cache.php can load object-cache.php before 707 * this function is run. This breaks the function_exists() check 708 * above and can result in wp_using_ext_object_cache() returning 709 * false when actually an external cache is in use. 710 */ 711 wp_using_ext_object_cache( true ); 712 } 713 } 714 715 if ( ! wp_using_ext_object_cache() ) { 716 require_once ABSPATH . WPINC . '/cache.php'; 717 } 718 719 require_once ABSPATH . WPINC . '/cache-compat.php'; 720 721 /* 722 * If cache supports reset, reset instead of init if already 723 * initialized. Reset signals to the cache that global IDs 724 * have changed and it may need to update keys and cleanup caches. 725 */ 726 if ( ! $first_init && function_exists( 'wp_cache_switch_to_blog' ) ) { 727 wp_cache_switch_to_blog( get_current_blog_id() ); 728 } elseif ( function_exists( 'wp_cache_init' ) ) { 729 wp_cache_init(); 730 } 731 732 if ( function_exists( 'wp_cache_add_global_groups' ) ) { 733 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'site-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'blog_meta' ) ); 734 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); 735 } 736 737 $first_init = false; 738 } 739 740 /** 741 * Redirect to the installer if WordPress is not installed. 742 * 743 * Dies with an error message when Multisite is enabled. 744 * 745 * @since 3.0.0 746 * @access private 747 */ 748 function wp_not_installed() { 749 if ( is_multisite() ) { 750 if ( ! is_blog_installed() && ! wp_installing() ) { 751 nocache_headers(); 752 753 wp_die( __( 'The site you have requested is not installed properly. Please contact the system administrator.' ) ); 754 } 755 } elseif ( ! is_blog_installed() && ! wp_installing() ) { 756 nocache_headers(); 757 758 require ABSPATH . WPINC . '/kses.php'; 759 require ABSPATH . WPINC . '/pluggable.php'; 760 761 $link = wp_guess_url() . '/wp-admin/install.php'; 762 763 wp_redirect( $link ); 764 die(); 765 } 766 } 767 768 /** 769 * Retrieve an array of must-use plugin files. 770 * 771 * The default directory is wp-content/mu-plugins. To change the default 772 * directory manually, define `WPMU_PLUGIN_DIR` and `WPMU_PLUGIN_URL` 773 * in wp-config.php. 774 * 775 * @since 3.0.0 776 * @access private 777 * 778 * @return string[] Array of absolute paths of files to include. 779 */ 780 function wp_get_mu_plugins() { 781 $mu_plugins = array(); 782 if ( ! is_dir( WPMU_PLUGIN_DIR ) ) { 783 return $mu_plugins; 784 } 785 $dh = opendir( WPMU_PLUGIN_DIR ); 786 if ( ! $dh ) { 787 return $mu_plugins; 788 } 789 while ( ( $plugin = readdir( $dh ) ) !== false ) { 790 if ( '.php' === substr( $plugin, -4 ) ) { 791 $mu_plugins[] = WPMU_PLUGIN_DIR . '/' . $plugin; 792 } 793 } 794 closedir( $dh ); 795 sort( $mu_plugins ); 796 797 return $mu_plugins; 798 } 799 800 /** 801 * Retrieve an array of active and valid plugin files. 802 * 803 * While upgrading or installing WordPress, no plugins are returned. 804 * 805 * The default directory is `wp-content/plugins`. To change the default 806 * directory manually, define `WP_PLUGIN_DIR` and `WP_PLUGIN_URL` 807 * in `wp-config.php`. 808 * 809 * @since 3.0.0 810 * @access private 811 * 812 * @return string[] Array of paths to plugin files relative to the plugins directory. 813 */ 814 function wp_get_active_and_valid_plugins() { 815 $plugins = array(); 816 $active_plugins = (array) get_option( 'active_plugins', array() ); 817 818 // Check for hacks file if the option is enabled. 819 if ( get_option( 'hack_file' ) && file_exists( ABSPATH . 'my-hacks.php' ) ) { 820 _deprecated_file( 'my-hacks.php', '1.5.0' ); 821 array_unshift( $plugins, ABSPATH . 'my-hacks.php' ); 822 } 823 824 if ( empty( $active_plugins ) || wp_installing() ) { 825 return $plugins; 826 } 827 828 $network_plugins = is_multisite() ? wp_get_active_network_plugins() : false; 829 830 foreach ( $active_plugins as $plugin ) { 831 if ( ! validate_file( $plugin ) // $plugin must validate as file. 832 && '.php' === substr( $plugin, -4 ) // $plugin must end with '.php'. 833 && file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist. 834 // Not already included as a network plugin. 835 && ( ! $network_plugins || ! in_array( WP_PLUGIN_DIR . '/' . $plugin, $network_plugins, true ) ) 836 ) { 837 $plugins[] = WP_PLUGIN_DIR . '/' . $plugin; 838 } 839 } 840 841 /* 842 * Remove plugins from the list of active plugins when we're on an endpoint 843 * that should be protected against WSODs and the plugin is paused. 844 */ 845 if ( wp_is_recovery_mode() ) { 846 $plugins = wp_skip_paused_plugins( $plugins ); 847 } 848 849 return $plugins; 850 } 851 852 /** 853 * Filters a given list of plugins, removing any paused plugins from it. 854 * 855 * @since 5.2.0 856 * 857 * @param string[] $plugins Array of absolute plugin main file paths. 858 * @return string[] Filtered array of plugins, without any paused plugins. 859 */ 860 function wp_skip_paused_plugins( array $plugins ) { 861 $paused_plugins = wp_paused_plugins()->get_all(); 862 863 if ( empty( $paused_plugins ) ) { 864 return $plugins; 865 } 866 867 foreach ( $plugins as $index => $plugin ) { 868 list( $plugin ) = explode( '/', plugin_basename( $plugin ) ); 869 870 if ( array_key_exists( $plugin, $paused_plugins ) ) { 871 unset( $plugins[ $index ] ); 872 873 // Store list of paused plugins for displaying an admin notice. 874 $GLOBALS['_paused_plugins'][ $plugin ] = $paused_plugins[ $plugin ]; 875 } 876 } 877 878 return $plugins; 879 } 880 881 /** 882 * Retrieves an array of active and valid themes. 883 * 884 * While upgrading or installing WordPress, no themes are returned. 885 * 886 * @since 5.1.0 887 * @access private 888 * 889 * @global string $pagenow The filename of the current screen. 890 * 891 * @return string[] Array of absolute paths to theme directories. 892 */ 893 function wp_get_active_and_valid_themes() { 894 global $pagenow; 895 896 $themes = array(); 897 898 if ( wp_installing() && 'wp-activate.php' !== $pagenow ) { 899 return $themes; 900 } 901 902 if ( TEMPLATEPATH !== STYLESHEETPATH ) { 903 $themes[] = STYLESHEETPATH; 904 } 905 906 $themes[] = TEMPLATEPATH; 907 908 /* 909 * Remove themes from the list of active themes when we're on an endpoint 910 * that should be protected against WSODs and the theme is paused. 911 */ 912 if ( wp_is_recovery_mode() ) { 913 $themes = wp_skip_paused_themes( $themes ); 914 915 // If no active and valid themes exist, skip loading themes. 916 if ( empty( $themes ) ) { 917 add_filter( 'wp_using_themes', '__return_false' ); 918 } 919 } 920 921 return $themes; 922 } 923 924 /** 925 * Filters a given list of themes, removing any paused themes from it. 926 * 927 * @since 5.2.0 928 * 929 * @param string[] $themes Array of absolute theme directory paths. 930 * @return string[] Filtered array of absolute paths to themes, without any paused themes. 931 */ 932 function wp_skip_paused_themes( array $themes ) { 933 $paused_themes = wp_paused_themes()->get_all(); 934 935 if ( empty( $paused_themes ) ) { 936 return $themes; 937 } 938 939 foreach ( $themes as $index => $theme ) { 940 $theme = basename( $theme ); 941 942 if ( array_key_exists( $theme, $paused_themes ) ) { 943 unset( $themes[ $index ] ); 944 945 // Store list of paused themes for displaying an admin notice. 946 $GLOBALS['_paused_themes'][ $theme ] = $paused_themes[ $theme ]; 947 } 948 } 949 950 return $themes; 951 } 952 953 /** 954 * Is WordPress in Recovery Mode. 955 * 956 * In this mode, plugins or themes that cause WSODs will be paused. 957 * 958 * @since 5.2.0 959 * 960 * @return bool 961 */ 962 function wp_is_recovery_mode() { 963 return wp_recovery_mode()->is_active(); 964 } 965 966 /** 967 * Determines whether we are currently on an endpoint that should be protected against WSODs. 968 * 969 * @since 5.2.0 970 * 971 * @global string $pagenow The filename of the current screen. 972 * 973 * @return bool True if the current endpoint should be protected. 974 */ 975 function is_protected_endpoint() { 976 // Protect login pages. 977 if ( isset( $GLOBALS['pagenow'] ) && 'wp-login.php' === $GLOBALS['pagenow'] ) { 978 return true; 979 } 980 981 // Protect the admin backend. 982 if ( is_admin() && ! wp_doing_ajax() ) { 983 return true; 984 } 985 986 // Protect Ajax actions that could help resolve a fatal error should be available. 987 if ( is_protected_ajax_action() ) { 988 return true; 989 } 990 991 /** 992 * Filters whether the current request is against a protected endpoint. 993 * 994 * This filter is only fired when an endpoint is requested which is not already protected by 995 * WordPress core. As such, it exclusively allows providing further protected endpoints in 996 * addition to the admin backend, login pages and protected Ajax actions. 997 * 998 * @since 5.2.0 999 * 1000 * @param bool $is_protected_endpoint Whether the currently requested endpoint is protected. 1001 * Default false. 1002 */ 1003 return (bool) apply_filters( 'is_protected_endpoint', false ); 1004 } 1005 1006 /** 1007 * Determines whether we are currently handling an Ajax action that should be protected against WSODs. 1008 * 1009 * @since 5.2.0 1010 * 1011 * @return bool True if the current Ajax action should be protected. 1012 */ 1013 function is_protected_ajax_action() { 1014 if ( ! wp_doing_ajax() ) { 1015 return false; 1016 } 1017 1018 if ( ! isset( $_REQUEST['action'] ) ) { 1019 return false; 1020 } 1021 1022 $actions_to_protect = array( 1023 'edit-theme-plugin-file', // Saving changes in the core code editor. 1024 'heartbeat', // Keep the heart beating. 1025 'install-plugin', // Installing a new plugin. 1026 'install-theme', // Installing a new theme. 1027 'search-plugins', // Searching in the list of plugins. 1028 'search-install-plugins', // Searching for a plugin in the plugin install screen. 1029 'update-plugin', // Update an existing plugin. 1030 'update-theme', // Update an existing theme. 1031 ); 1032 1033 /** 1034 * Filters the array of protected Ajax actions. 1035 * 1036 * This filter is only fired when doing Ajax and the Ajax request has an 'action' property. 1037 * 1038 * @since 5.2.0 1039 * 1040 * @param string[] $actions_to_protect Array of strings with Ajax actions to protect. 1041 */ 1042 $actions_to_protect = (array) apply_filters( 'wp_protected_ajax_actions', $actions_to_protect ); 1043 1044 if ( ! in_array( $_REQUEST['action'], $actions_to_protect, true ) ) { 1045 return false; 1046 } 1047 1048 return true; 1049 } 1050 1051 /** 1052 * Set internal encoding. 1053 * 1054 * In most cases the default internal encoding is latin1, which is 1055 * of no use, since we want to use the `mb_` functions for `utf-8` strings. 1056 * 1057 * @since 3.0.0 1058 * @access private 1059 */ 1060 function wp_set_internal_encoding() { 1061 if ( function_exists( 'mb_internal_encoding' ) ) { 1062 $charset = get_option( 'blog_charset' ); 1063 // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged 1064 if ( ! $charset || ! @mb_internal_encoding( $charset ) ) { 1065 mb_internal_encoding( 'UTF-8' ); 1066 } 1067 } 1068 } 1069 1070 /** 1071 * Add magic quotes to `$_GET`, `$_POST`, `$_COOKIE`, and `$_SERVER`. 1072 * 1073 * Also forces `$_REQUEST` to be `$_GET + $_POST`. If `$_SERVER`, 1074 * `$_COOKIE`, or `$_ENV` are needed, use those superglobals directly. 1075 * 1076 * @since 3.0.0 1077 * @access private 1078 */ 1079 function wp_magic_quotes() { 1080 // Escape with wpdb. 1081 $_GET = add_magic_quotes( $_GET ); 1082 $_POST = add_magic_quotes( $_POST ); 1083 $_COOKIE = add_magic_quotes( $_COOKIE ); 1084 $_SERVER = add_magic_quotes( $_SERVER ); 1085 1086 // Force REQUEST to be GET + POST. 1087 $_REQUEST = array_merge( $_GET, $_POST ); 1088 } 1089 1090 /** 1091 * Runs just before PHP shuts down execution. 1092 * 1093 * @since 1.2.0 1094 * @access private 1095 */ 1096 function shutdown_action_hook() { 1097 /** 1098 * Fires just before PHP shuts down execution. 1099 * 1100 * @since 1.2.0 1101 */ 1102 do_action( 'shutdown' ); 1103 1104 wp_cache_close(); 1105 } 1106 1107 /** 1108 * Copy an object. 1109 * 1110 * @since 2.7.0 1111 * @deprecated 3.2.0 1112 * 1113 * @param object $object The object to clone. 1114 * @return object The cloned object. 1115 */ 1116 function wp_clone( $object ) { 1117 // Use parens for clone to accommodate PHP 4. See #17880. 1118 return clone( $object ); 1119 } 1120 1121 /** 1122 * Determines whether the current request is for an administrative interface page. 1123 * 1124 * Does not check if the user is an administrator; use current_user_can() 1125 * for checking roles and capabilities. 1126 * 1127 * For more information on this and similar theme functions, check out 1128 * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ 1129 * Conditional Tags} article in the Theme Developer Handbook. 1130 * 1131 * @since 1.5.1 1132 * 1133 * @global WP_Screen $current_screen WordPress current screen object. 1134 * 1135 * @return bool True if inside WordPress administration interface, false otherwise. 1136 */ 1137 function is_admin() { 1138 if ( isset( $GLOBALS['current_screen'] ) ) { 1139 return $GLOBALS['current_screen']->in_admin(); 1140 } elseif ( defined( 'WP_ADMIN' ) ) { 1141 return WP_ADMIN; 1142 } 1143 1144 return false; 1145 } 1146 1147 /** 1148 * Whether the current request is for a site's administrative interface. 1149 * 1150 * e.g. `/wp-admin/` 1151 * 1152 * Does not check if the user is an administrator; use current_user_can() 1153 * for checking roles and capabilities. 1154 * 1155 * @since 3.1.0 1156 * 1157 * @global WP_Screen $current_screen WordPress current screen object. 1158 * 1159 * @return bool True if inside WordPress blog administration pages. 1160 */ 1161 function is_blog_admin() { 1162 if ( isset( $GLOBALS['current_screen'] ) ) { 1163 return $GLOBALS['current_screen']->in_admin( 'site' ); 1164 } elseif ( defined( 'WP_BLOG_ADMIN' ) ) { 1165 return WP_BLOG_ADMIN; 1166 } 1167 1168 return false; 1169 } 1170 1171 /** 1172 * Whether the current request is for the network administrative interface. 1173 * 1174 * e.g. `/wp-admin/network/` 1175 * 1176 * Does not check if the user is an administrator; use current_user_can() 1177 * for checking roles and capabilities. 1178 * 1179 * Does not check if the site is a Multisite network; use is_multisite() 1180 * for checking if Multisite is enabled. 1181 * 1182 * @since 3.1.0 1183 * 1184 * @global WP_Screen $current_screen WordPress current screen object. 1185 * 1186 * @return bool True if inside WordPress network administration pages. 1187 */ 1188 function is_network_admin() { 1189 if ( isset( $GLOBALS['current_screen'] ) ) { 1190 return $GLOBALS['current_screen']->in_admin( 'network' ); 1191 } elseif ( defined( 'WP_NETWORK_ADMIN' ) ) { 1192 return WP_NETWORK_ADMIN; 1193 } 1194 1195 return false; 1196 } 1197 1198 /** 1199 * Whether the current request is for a user admin screen. 1200 * 1201 * e.g. `/wp-admin/user/` 1202 * 1203 * Does not check if the user is an administrator; use current_user_can() 1204 * for checking roles and capabilities. 1205 * 1206 * @since 3.1.0 1207 * 1208 * @global WP_Screen $current_screen WordPress current screen object. 1209 * 1210 * @return bool True if inside WordPress user administration pages. 1211 */ 1212 function is_user_admin() { 1213 if ( isset( $GLOBALS['current_screen'] ) ) { 1214 return $GLOBALS['current_screen']->in_admin( 'user' ); 1215 } elseif ( defined( 'WP_USER_ADMIN' ) ) { 1216 return WP_USER_ADMIN; 1217 } 1218 1219 return false; 1220 } 1221 1222 /** 1223 * If Multisite is enabled. 1224 * 1225 * @since 3.0.0 1226 * 1227 * @return bool True if Multisite is enabled, false otherwise. 1228 */ 1229 function is_multisite() { 1230 if ( defined( 'MULTISITE' ) ) { 1231 return MULTISITE; 1232 } 1233 1234 if ( defined( 'SUBDOMAIN_INSTALL' ) || defined( 'VHOST' ) || defined( 'SUNRISE' ) ) { 1235 return true; 1236 } 1237 1238 return false; 1239 } 1240 1241 /** 1242 * Retrieve the current site ID. 1243 * 1244 * @since 3.1.0 1245 * 1246 * @global int $blog_id 1247 * 1248 * @return int Site ID. 1249 */ 1250 function get_current_blog_id() { 1251 global $blog_id; 1252 return absint( $blog_id ); 1253 } 1254 1255 /** 1256 * Retrieves the current network ID. 1257 * 1258 * @since 4.6.0 1259 * 1260 * @return int The ID of the current network. 1261 */ 1262 function get_current_network_id() { 1263 if ( ! is_multisite() ) { 1264 return 1; 1265 } 1266 1267 $current_network = get_network(); 1268 1269 if ( ! isset( $current_network->id ) ) { 1270 return get_main_network_id(); 1271 } 1272 1273 return absint( $current_network->id ); 1274 } 1275 1276 /** 1277 * Attempt an early load of translations. 1278 * 1279 * Used for errors encountered during the initial loading process, before 1280 * the locale has been properly detected and loaded. 1281 * 1282 * Designed for unusual load sequences (like setup-config.php) or for when 1283 * the script will then terminate with an error, otherwise there is a risk 1284 * that a file can be double-included. 1285 * 1286 * @since 3.4.0 1287 * @access private 1288 * 1289 * @global WP_Locale $wp_locale WordPress date and time locale object. 1290 */ 1291 function wp_load_translations_early() { 1292 global $wp_locale; 1293 1294 static $loaded = false; 1295 if ( $loaded ) { 1296 return; 1297 } 1298 $loaded = true; 1299 1300 if ( function_exists( 'did_action' ) && did_action( 'init' ) ) { 1301 return; 1302 } 1303 1304 // We need $wp_local_package. 1305 require ABSPATH . WPINC . '/version.php'; 1306 1307 // Translation and localization. 1308 require_once ABSPATH . WPINC . '/pomo/mo.php'; 1309 require_once ABSPATH . WPINC . '/l10n.php'; 1310 require_once ABSPATH . WPINC . '/class-wp-locale.php'; 1311 require_once ABSPATH . WPINC . '/class-wp-locale-switcher.php'; 1312 1313 // General libraries. 1314 require_once ABSPATH . WPINC . '/plugin.php'; 1315 1316 $locales = array(); 1317 $locations = array(); 1318 1319 while ( true ) { 1320 if ( defined( 'WPLANG' ) ) { 1321 if ( '' === WPLANG ) { 1322 break; 1323 } 1324 $locales[] = WPLANG; 1325 } 1326 1327 if ( isset( $wp_local_package ) ) { 1328 $locales[] = $wp_local_package; 1329 } 1330 1331 if ( ! $locales ) { 1332 break; 1333 } 1334 1335 if ( defined( 'WP_LANG_DIR' ) && @is_dir( WP_LANG_DIR ) ) { 1336 $locations[] = WP_LANG_DIR; 1337 } 1338 1339 if ( defined( 'WP_CONTENT_DIR' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) ) { 1340 $locations[] = WP_CONTENT_DIR . '/languages'; 1341 } 1342 1343 if ( @is_dir( ABSPATH . 'wp-content/languages' ) ) { 1344 $locations[] = ABSPATH . 'wp-content/languages'; 1345 } 1346 1347 if ( @is_dir( ABSPATH . WPINC . '/languages' ) ) { 1348 $locations[] = ABSPATH . WPINC . '/languages'; 1349 } 1350 1351 if ( ! $locations ) { 1352 break; 1353 } 1354 1355 $locations = array_unique( $locations ); 1356 1357 foreach ( $locales as $locale ) { 1358 foreach ( $locations as $location ) { 1359 if ( file_exists( $location . '/' . $locale . '.mo' ) ) { 1360 load_textdomain( 'default', $location . '/' . $locale . '.mo' ); 1361 if ( defined( 'WP_SETUP_CONFIG' ) && file_exists( $location . '/admin-' . $locale . '.mo' ) ) { 1362 load_textdomain( 'default', $location . '/admin-' . $locale . '.mo' ); 1363 } 1364 break 2; 1365 } 1366 } 1367 } 1368 1369 break; 1370 } 1371 1372 $wp_locale = new WP_Locale(); 1373 } 1374 1375 /** 1376 * Check or set whether WordPress is in "installation" mode. 1377 * 1378 * If the `WP_INSTALLING` constant is defined during the bootstrap, `wp_installing()` will default to `true`. 1379 * 1380 * @since 4.4.0 1381 * 1382 * @param bool $is_installing Optional. True to set WP into Installing mode, false to turn Installing mode off. 1383 * Omit this parameter if you only want to fetch the current status. 1384 * @return bool True if WP is installing, otherwise false. When a `$is_installing` is passed, the function will 1385 * report whether WP was in installing mode prior to the change to `$is_installing`. 1386 */ 1387 function wp_installing( $is_installing = null ) { 1388 static $installing = null; 1389 1390 // Support for the `WP_INSTALLING` constant, defined before WP is loaded. 1391 if ( is_null( $installing ) ) { 1392 $installing = defined( 'WP_INSTALLING' ) && WP_INSTALLING; 1393 } 1394 1395 if ( ! is_null( $is_installing ) ) { 1396 $old_installing = $installing; 1397 $installing = $is_installing; 1398 return (bool) $old_installing; 1399 } 1400 1401 return (bool) $installing; 1402 } 1403 1404 /** 1405 * Determines if SSL is used. 1406 * 1407 * @since 2.6.0 1408 * @since 4.6.0 Moved from functions.php to load.php. 1409 * 1410 * @return bool True if SSL, otherwise false. 1411 */ 1412 function is_ssl() { 1413 if ( isset( $_SERVER['HTTPS'] ) ) { 1414 if ( 'on' === strtolower( $_SERVER['HTTPS'] ) ) { 1415 return true; 1416 } 1417 1418 if ( '1' == $_SERVER['HTTPS'] ) { 1419 return true; 1420 } 1421 } elseif ( isset( $_SERVER['SERVER_PORT'] ) && ( '443' == $_SERVER['SERVER_PORT'] ) ) { 1422 return true; 1423 } 1424 return false; 1425 } 1426 1427 /** 1428 * Converts a shorthand byte value to an integer byte value. 1429 * 1430 * @since 2.3.0 1431 * @since 4.6.0 Moved from media.php to load.php. 1432 * 1433 * @link https://www.php.net/manual/en/function.ini-get.php 1434 * @link https://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes 1435 * 1436 * @param string $value A (PHP ini) byte value, either shorthand or ordinary. 1437 * @return int An integer byte value. 1438 */ 1439 function wp_convert_hr_to_bytes( $value ) { 1440 $value = strtolower( trim( $value ) ); 1441 $bytes = (int) $value; 1442 1443 if ( false !== strpos( $value, 'g' ) ) { 1444 $bytes *= GB_IN_BYTES; 1445 } elseif ( false !== strpos( $value, 'm' ) ) { 1446 $bytes *= MB_IN_BYTES; 1447 } elseif ( false !== strpos( $value, 'k' ) ) { 1448 $bytes *= KB_IN_BYTES; 1449 } 1450 1451 // Deal with large (float) values which run into the maximum integer size. 1452 return min( $bytes, PHP_INT_MAX ); 1453 } 1454 1455 /** 1456 * Determines whether a PHP ini value is changeable at runtime. 1457 * 1458 * @since 4.6.0 1459 * 1460 * @link https://www.php.net/manual/en/function.ini-get-all.php 1461 * 1462 * @param string $setting The name of the ini setting to check. 1463 * @return bool True if the value is changeable at runtime. False otherwise. 1464 */ 1465 function wp_is_ini_value_changeable( $setting ) { 1466 static $ini_all; 1467 1468 if ( ! isset( $ini_all ) ) { 1469 $ini_all = false; 1470 // Sometimes `ini_get_all()` is disabled via the `disable_functions` option for "security purposes". 1471 if ( function_exists( 'ini_get_all' ) ) { 1472 $ini_all = ini_get_all(); 1473 } 1474 } 1475 1476 // 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. 1477 if ( isset( $ini_all[ $setting ]['access'] ) && ( INI_ALL === ( $ini_all[ $setting ]['access'] & 7 ) || INI_USER === ( $ini_all[ $setting ]['access'] & 7 ) ) ) { 1478 return true; 1479 } 1480 1481 // If we were unable to retrieve the details, fail gracefully to assume it's changeable. 1482 if ( ! is_array( $ini_all ) ) { 1483 return true; 1484 } 1485 1486 return false; 1487 } 1488 1489 /** 1490 * Determines whether the current request is a WordPress Ajax request. 1491 * 1492 * @since 4.7.0 1493 * 1494 * @return bool True if it's a WordPress Ajax request, false otherwise. 1495 */ 1496 function wp_doing_ajax() { 1497 /** 1498 * Filters whether the current request is a WordPress Ajax request. 1499 * 1500 * @since 4.7.0 1501 * 1502 * @param bool $wp_doing_ajax Whether the current request is a WordPress Ajax request. 1503 */ 1504 return apply_filters( 'wp_doing_ajax', defined( 'DOING_AJAX' ) && DOING_AJAX ); 1505 } 1506 1507 /** 1508 * Determines whether the current request should use themes. 1509 * 1510 * @since 5.1.0 1511 * 1512 * @return bool True if themes should be used, false otherwise. 1513 */ 1514 function wp_using_themes() { 1515 /** 1516 * Filters whether the current request should use themes. 1517 * 1518 * @since 5.1.0 1519 * 1520 * @param bool $wp_using_themes Whether the current request should use themes. 1521 */ 1522 return apply_filters( 'wp_using_themes', defined( 'WP_USE_THEMES' ) && WP_USE_THEMES ); 1523 } 1524 1525 /** 1526 * Determines whether the current request is a WordPress cron request. 1527 * 1528 * @since 4.8.0 1529 * 1530 * @return bool True if it's a WordPress cron request, false otherwise. 1531 */ 1532 function wp_doing_cron() { 1533 /** 1534 * Filters whether the current request is a WordPress cron request. 1535 * 1536 * @since 4.8.0 1537 * 1538 * @param bool $wp_doing_cron Whether the current request is a WordPress cron request. 1539 */ 1540 return apply_filters( 'wp_doing_cron', defined( 'DOING_CRON' ) && DOING_CRON ); 1541 } 1542 1543 /** 1544 * Checks whether the given variable is a WordPress Error. 1545 * 1546 * Returns whether `$thing` is an instance of the `WP_Error` class. 1547 * 1548 * @since 2.1.0 1549 * 1550 * @param mixed $thing The variable to check. 1551 * @return bool Whether the variable is an instance of WP_Error. 1552 */ 1553 function is_wp_error( $thing ) { 1554 $is_wp_error = ( $thing instanceof WP_Error ); 1555 1556 if ( $is_wp_error ) { 1557 /** 1558 * Fires when `is_wp_error()` is called and its parameter is an instance of `WP_Error`. 1559 * 1560 * @since 5.6.0 1561 * 1562 * @param WP_Error $thing The error object passed to `is_wp_error()`. 1563 */ 1564 do_action( 'is_wp_error_instance', $thing ); 1565 } 1566 1567 return $is_wp_error; 1568 } 1569 1570 /** 1571 * Determines whether file modifications are allowed. 1572 * 1573 * @since 4.8.0 1574 * 1575 * @param string $context The usage context. 1576 * @return bool True if file modification is allowed, false otherwise. 1577 */ 1578 function wp_is_file_mod_allowed( $context ) { 1579 /** 1580 * Filters whether file modifications are allowed. 1581 * 1582 * @since 4.8.0 1583 * 1584 * @param bool $file_mod_allowed Whether file modifications are allowed. 1585 * @param string $context The usage context. 1586 */ 1587 return apply_filters( 'file_mod_allowed', ! defined( 'DISALLOW_FILE_MODS' ) || ! DISALLOW_FILE_MODS, $context ); 1588 } 1589 1590 /** 1591 * Start scraping edited file errors. 1592 * 1593 * @since 4.9.0 1594 */ 1595 function wp_start_scraping_edited_file_errors() { 1596 if ( ! isset( $_REQUEST['wp_scrape_key'] ) || ! isset( $_REQUEST['wp_scrape_nonce'] ) ) { 1597 return; 1598 } 1599 $key = substr( sanitize_key( wp_unslash( $_REQUEST['wp_scrape_key'] ) ), 0, 32 ); 1600 $nonce = wp_unslash( $_REQUEST['wp_scrape_nonce'] ); 1601 1602 if ( get_transient( 'scrape_key_' . $key ) !== $nonce ) { 1603 echo "###### wp_scraping_result_start:$key ######"; 1604 echo wp_json_encode( 1605 array( 1606 'code' => 'scrape_nonce_failure', 1607 'message' => __( 'Scrape key check failed. Please try again.' ), 1608 ) 1609 ); 1610 echo "###### wp_scraping_result_end:$key ######"; 1611 die(); 1612 } 1613 if ( ! defined( 'WP_SANDBOX_SCRAPING' ) ) { 1614 define( 'WP_SANDBOX_SCRAPING', true ); 1615 } 1616 register_shutdown_function( 'wp_finalize_scraping_edited_file_errors', $key ); 1617 } 1618 1619 /** 1620 * Finalize scraping for edited file errors. 1621 * 1622 * @since 4.9.0 1623 * 1624 * @param string $scrape_key Scrape key. 1625 */ 1626 function wp_finalize_scraping_edited_file_errors( $scrape_key ) { 1627 $error = error_get_last(); 1628 echo "\n###### wp_scraping_result_start:$scrape_key ######\n"; 1629 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 ) ) { 1630 $error = str_replace( ABSPATH, '', $error ); 1631 echo wp_json_encode( $error ); 1632 } else { 1633 echo wp_json_encode( true ); 1634 } 1635 echo "\n###### wp_scraping_result_end:$scrape_key ######\n"; 1636 } 1637 1638 /** 1639 * Checks whether current request is a JSON request, or is expecting a JSON response. 1640 * 1641 * @since 5.0.0 1642 * 1643 * @return bool True if `Accepts` or `Content-Type` headers contain `application/json`. 1644 * False otherwise. 1645 */ 1646 function wp_is_json_request() { 1647 1648 if ( isset( $_SERVER['HTTP_ACCEPT'] ) && wp_is_json_media_type( $_SERVER['HTTP_ACCEPT'] ) ) { 1649 return true; 1650 } 1651 1652 if ( isset( $_SERVER['CONTENT_TYPE'] ) && wp_is_json_media_type( $_SERVER['CONTENT_TYPE'] ) ) { 1653 return true; 1654 } 1655 1656 return false; 1657 1658 } 1659 1660 /** 1661 * Checks whether current request is a JSONP request, or is expecting a JSONP response. 1662 * 1663 * @since 5.2.0 1664 * 1665 * @return bool True if JSONP request, false otherwise. 1666 */ 1667 function wp_is_jsonp_request() { 1668 if ( ! isset( $_GET['_jsonp'] ) ) { 1669 return false; 1670 } 1671 1672 if ( ! function_exists( 'wp_check_jsonp_callback' ) ) { 1673 require_once ABSPATH . WPINC . '/functions.php'; 1674 } 1675 1676 $jsonp_callback = $_GET['_jsonp']; 1677 if ( ! wp_check_jsonp_callback( $jsonp_callback ) ) { 1678 return false; 1679 } 1680 1681 /** This filter is documented in wp-includes/rest-api/class-wp-rest-server.php */ 1682 $jsonp_enabled = apply_filters( 'rest_jsonp_enabled', true ); 1683 1684 return $jsonp_enabled; 1685 1686 } 1687 1688 /** 1689 * Checks whether a string is a valid JSON Media Type. 1690 * 1691 * @since 5.6.0 1692 * 1693 * @param string $media_type A Media Type string to check. 1694 * @return bool True if string is a valid JSON Media Type. 1695 */ 1696 function wp_is_json_media_type( $media_type ) { 1697 static $cache = array(); 1698 1699 if ( ! isset( $cache[ $media_type ] ) ) { 1700 $cache[ $media_type ] = (bool) preg_match( '/(^|\s|,)application\/([\w!#\$&-\^\.\+]+\+)?json(\+oembed)?($|\s|;|,)/i', $media_type ); 1701 } 1702 1703 return $cache[ $media_type ]; 1704 } 1705 1706 /** 1707 * Checks whether current request is an XML request, or is expecting an XML response. 1708 * 1709 * @since 5.2.0 1710 * 1711 * @return bool True if `Accepts` or `Content-Type` headers contain `text/xml` 1712 * or one of the related MIME types. False otherwise. 1713 */ 1714 function wp_is_xml_request() { 1715 $accepted = array( 1716 'text/xml', 1717 'application/rss+xml', 1718 'application/atom+xml', 1719 'application/rdf+xml', 1720 'text/xml+oembed', 1721 'application/xml+oembed', 1722 ); 1723 1724 if ( isset( $_SERVER['HTTP_ACCEPT'] ) ) { 1725 foreach ( $accepted as $type ) { 1726 if ( false !== strpos( $_SERVER['HTTP_ACCEPT'], $type ) ) { 1727 return true; 1728 } 1729 } 1730 } 1731 1732 if ( isset( $_SERVER['CONTENT_TYPE'] ) && in_array( $_SERVER['CONTENT_TYPE'], $accepted, true ) ) { 1733 return true; 1734 } 1735 1736 return false; 1737 } 1738 1739 /** 1740 * Checks if this site is protected by HTTP Basic Auth. 1741 * 1742 * At the moment, this merely checks for the present of Basic Auth credentials. Therefore, calling 1743 * this function with a context different from the current context may give inaccurate results. 1744 * In a future release, this evaluation may be made more robust. 1745 * 1746 * Currently, this is only used by Application Passwords to prevent a conflict since it also utilizes 1747 * Basic Auth. 1748 * 1749 * @since 5.6.1 1750 * 1751 * @global string $pagenow The filename of the current screen. 1752 * 1753 * @param string $context The context to check for protection. Accepts 'login', 'admin', and 'front'. 1754 * Defaults to the current context. 1755 * @return bool Whether the site is protected by Basic Auth. 1756 */ 1757 function wp_is_site_protected_by_basic_auth( $context = '' ) { 1758 global $pagenow; 1759 1760 if ( ! $context ) { 1761 if ( 'wp-login.php' === $pagenow ) { 1762 $context = 'login'; 1763 } elseif ( is_admin() ) { 1764 $context = 'admin'; 1765 } else { 1766 $context = 'front'; 1767 } 1768 } 1769 1770 $is_protected = ! empty( $_SERVER['PHP_AUTH_USER'] ) || ! empty( $_SERVER['PHP_AUTH_PW'] ); 1771 1772 /** 1773 * Filters whether a site is protected by HTTP Basic Auth. 1774 * 1775 * @since 5.6.1 1776 * 1777 * @param bool $is_protected Whether the site is protected by Basic Auth. 1778 * @param string $context The context to check for protection. One of 'login', 'admin', or 'front'. 1779 */ 1780 return apply_filters( 'wp_is_site_protected_by_basic_auth', $is_protected, $context ); 1781 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Oct 13 01:00:02 2024 | Cross-referenced by PHPXref 0.7.1 |