[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/ -> load.php (source)

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


Generated: Thu Jul 2 01:00:04 2020 Cross-referenced by PHPXref 0.7.1