[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

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', '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 = PHP_VERSION;
 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 . '/class-wpdb.php';
 548  
 549      if ( file_exists( WP_CONTENT_DIR . '/db.php' ) ) {
 550          require_once WP_CONTENT_DIR . '/db.php';
 551      }
 552  
 553      if ( isset( $wpdb ) ) {
 554          return;
 555      }
 556  
 557      $dbuser     = defined( 'DB_USER' ) ? DB_USER : '';
 558      $dbpassword = defined( 'DB_PASSWORD' ) ? DB_PASSWORD : '';
 559      $dbname     = defined( 'DB_NAME' ) ? DB_NAME : '';
 560      $dbhost     = defined( 'DB_HOST' ) ? DB_HOST : '';
 561  
 562      $wpdb = new wpdb( $dbuser, $dbpassword, $dbname, $dbhost );
 563  }
 564  
 565  /**
 566   * Set the database table prefix and the format specifiers for database
 567   * table columns.
 568   *
 569   * Columns not listed here default to `%s`.
 570   *
 571   * @since 3.0.0
 572   * @access private
 573   *
 574   * @global wpdb   $wpdb         WordPress database abstraction object.
 575   * @global string $table_prefix The database table prefix.
 576   */
 577  function wp_set_wpdb_vars() {
 578      global $wpdb, $table_prefix;
 579      if ( ! empty( $wpdb->error ) ) {
 580          dead_db();
 581      }
 582  
 583      $wpdb->field_types = array(
 584          'post_author'      => '%d',
 585          'post_parent'      => '%d',
 586          'menu_order'       => '%d',
 587          'term_id'          => '%d',
 588          'term_group'       => '%d',
 589          'term_taxonomy_id' => '%d',
 590          'parent'           => '%d',
 591          'count'            => '%d',
 592          'object_id'        => '%d',
 593          'term_order'       => '%d',
 594          'ID'               => '%d',
 595          'comment_ID'       => '%d',
 596          'comment_post_ID'  => '%d',
 597          'comment_parent'   => '%d',
 598          'user_id'          => '%d',
 599          'link_id'          => '%d',
 600          'link_owner'       => '%d',
 601          'link_rating'      => '%d',
 602          'option_id'        => '%d',
 603          'blog_id'          => '%d',
 604          'meta_id'          => '%d',
 605          'post_id'          => '%d',
 606          'user_status'      => '%d',
 607          'umeta_id'         => '%d',
 608          'comment_karma'    => '%d',
 609          'comment_count'    => '%d',
 610          // Multisite:
 611          'active'           => '%d',
 612          'cat_id'           => '%d',
 613          'deleted'          => '%d',
 614          'lang_id'          => '%d',
 615          'mature'           => '%d',
 616          'public'           => '%d',
 617          'site_id'          => '%d',
 618          'spam'             => '%d',
 619      );
 620  
 621      $prefix = $wpdb->set_prefix( $table_prefix );
 622  
 623      if ( is_wp_error( $prefix ) ) {
 624          wp_load_translations_early();
 625          wp_die(
 626              sprintf(
 627                  /* translators: 1: $table_prefix, 2: wp-config.php */
 628                  __( '<strong>Error:</strong> %1$s in %2$s can only contain numbers, letters, and underscores.' ),
 629                  '<code>$table_prefix</code>',
 630                  '<code>wp-config.php</code>'
 631              )
 632          );
 633      }
 634  }
 635  
 636  /**
 637   * Toggle `$_wp_using_ext_object_cache` on and off without directly
 638   * touching global.
 639   *
 640   * @since 3.7.0
 641   *
 642   * @global bool $_wp_using_ext_object_cache
 643   *
 644   * @param bool $using Whether external object cache is being used.
 645   * @return bool The current 'using' setting.
 646   */
 647  function wp_using_ext_object_cache( $using = null ) {
 648      global $_wp_using_ext_object_cache;
 649      $current_using = $_wp_using_ext_object_cache;
 650      if ( null !== $using ) {
 651          $_wp_using_ext_object_cache = $using;
 652      }
 653      return $current_using;
 654  }
 655  
 656  /**
 657   * Start the WordPress object cache.
 658   *
 659   * If an object-cache.php file exists in the wp-content directory,
 660   * it uses that drop-in as an external object cache.
 661   *
 662   * @since 3.0.0
 663   * @access private
 664   *
 665   * @global array $wp_filter Stores all of the filters.
 666   */
 667  function wp_start_object_cache() {
 668      global $wp_filter;
 669      static $first_init = true;
 670  
 671      // Only perform the following checks once.
 672  
 673      /**
 674       * Filters whether to enable loading of the object-cache.php drop-in.
 675       *
 676       * This filter runs before it can be used by plugins. It is designed for non-web
 677       * runtimes. If false is returned, object-cache.php will never be loaded.
 678       *
 679       * @since 5.8.0
 680       *
 681       * @param bool $enable_object_cache Whether to enable loading object-cache.php (if present).
 682       *                                  Default true.
 683       */
 684      if ( $first_init && apply_filters( 'enable_loading_object_cache_dropin', true ) ) {
 685          if ( ! function_exists( 'wp_cache_init' ) ) {
 686              /*
 687               * This is the normal situation. First-run of this function. No
 688               * caching backend has been loaded.
 689               *
 690               * We try to load a custom caching backend, and then, if it
 691               * results in a wp_cache_init() function existing, we note
 692               * that an external object cache is being used.
 693               */
 694              if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
 695                  require_once WP_CONTENT_DIR . '/object-cache.php';
 696                  if ( function_exists( 'wp_cache_init' ) ) {
 697                      wp_using_ext_object_cache( true );
 698                  }
 699  
 700                  // Re-initialize any hooks added manually by object-cache.php.
 701                  if ( $wp_filter ) {
 702                      $wp_filter = WP_Hook::build_preinitialized_hooks( $wp_filter );
 703                  }
 704              }
 705          } elseif ( ! wp_using_ext_object_cache() && file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
 706              /*
 707               * Sometimes advanced-cache.php can load object-cache.php before
 708               * this function is run. This breaks the function_exists() check
 709               * above and can result in wp_using_ext_object_cache() returning
 710               * false when actually an external cache is in use.
 711               */
 712              wp_using_ext_object_cache( true );
 713          }
 714      }
 715  
 716      if ( ! wp_using_ext_object_cache() ) {
 717          require_once  ABSPATH . WPINC . '/cache.php';
 718      }
 719  
 720      require_once  ABSPATH . WPINC . '/cache-compat.php';
 721  
 722      /*
 723       * If cache supports reset, reset instead of init if already
 724       * initialized. Reset signals to the cache that global IDs
 725       * have changed and it may need to update keys and cleanup caches.
 726       */
 727      if ( ! $first_init && function_exists( 'wp_cache_switch_to_blog' ) ) {
 728          wp_cache_switch_to_blog( get_current_blog_id() );
 729      } elseif ( function_exists( 'wp_cache_init' ) ) {
 730          wp_cache_init();
 731      }
 732  
 733      if ( function_exists( 'wp_cache_add_global_groups' ) ) {
 734          wp_cache_add_global_groups(
 735              array(
 736                  'blog-details',
 737                  'blog-id-cache',
 738                  'blog-lookup',
 739                  'blog_meta',
 740                  'global-posts',
 741                  'networks',
 742                  'sites',
 743                  'site-details',
 744                  'site-options',
 745                  'site-transient',
 746                  'rss',
 747                  'users',
 748                  'useremail',
 749                  'userlogins',
 750                  'usermeta',
 751                  'user_meta',
 752                  'userslugs',
 753              )
 754          );
 755  
 756          wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
 757      }
 758  
 759      $first_init = false;
 760  }
 761  
 762  /**
 763   * Redirect to the installer if WordPress is not installed.
 764   *
 765   * Dies with an error message when Multisite is enabled.
 766   *
 767   * @since 3.0.0
 768   * @access private
 769   */
 770  function wp_not_installed() {
 771      if ( is_multisite() ) {
 772          if ( ! is_blog_installed() && ! wp_installing() ) {
 773              nocache_headers();
 774  
 775              wp_die( __( 'The site you have requested is not installed properly. Please contact the system administrator.' ) );
 776          }
 777      } elseif ( ! is_blog_installed() && ! wp_installing() ) {
 778          nocache_headers();
 779  
 780          require  ABSPATH . WPINC . '/kses.php';
 781          require  ABSPATH . WPINC . '/pluggable.php';
 782  
 783          $link = wp_guess_url() . '/wp-admin/install.php';
 784  
 785          wp_redirect( $link );
 786          die();
 787      }
 788  }
 789  
 790  /**
 791   * Retrieve an array of must-use plugin files.
 792   *
 793   * The default directory is wp-content/mu-plugins. To change the default
 794   * directory manually, define `WPMU_PLUGIN_DIR` and `WPMU_PLUGIN_URL`
 795   * in wp-config.php.
 796   *
 797   * @since 3.0.0
 798   * @access private
 799   *
 800   * @return string[] Array of absolute paths of files to include.
 801   */
 802  function wp_get_mu_plugins() {
 803      $mu_plugins = array();
 804      if ( ! is_dir( WPMU_PLUGIN_DIR ) ) {
 805          return $mu_plugins;
 806      }
 807      $dh = opendir( WPMU_PLUGIN_DIR );
 808      if ( ! $dh ) {
 809          return $mu_plugins;
 810      }
 811      while ( ( $plugin = readdir( $dh ) ) !== false ) {
 812          if ( '.php' === substr( $plugin, -4 ) ) {
 813              $mu_plugins[] = WPMU_PLUGIN_DIR . '/' . $plugin;
 814          }
 815      }
 816      closedir( $dh );
 817      sort( $mu_plugins );
 818  
 819      return $mu_plugins;
 820  }
 821  
 822  /**
 823   * Retrieve an array of active and valid plugin files.
 824   *
 825   * While upgrading or installing WordPress, no plugins are returned.
 826   *
 827   * The default directory is `wp-content/plugins`. To change the default
 828   * directory manually, define `WP_PLUGIN_DIR` and `WP_PLUGIN_URL`
 829   * in `wp-config.php`.
 830   *
 831   * @since 3.0.0
 832   * @access private
 833   *
 834   * @return string[] Array of paths to plugin files relative to the plugins directory.
 835   */
 836  function wp_get_active_and_valid_plugins() {
 837      $plugins        = array();
 838      $active_plugins = (array) get_option( 'active_plugins', array() );
 839  
 840      // Check for hacks file if the option is enabled.
 841      if ( get_option( 'hack_file' ) && file_exists( ABSPATH . 'my-hacks.php' ) ) {
 842          _deprecated_file( 'my-hacks.php', '1.5.0' );
 843          array_unshift( $plugins, ABSPATH . 'my-hacks.php' );
 844      }
 845  
 846      if ( empty( $active_plugins ) || wp_installing() ) {
 847          return $plugins;
 848      }
 849  
 850      $network_plugins = is_multisite() ? wp_get_active_network_plugins() : false;
 851  
 852      foreach ( $active_plugins as $plugin ) {
 853          if ( ! validate_file( $plugin )                     // $plugin must validate as file.
 854              && '.php' === substr( $plugin, -4 )             // $plugin must end with '.php'.
 855              && file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist.
 856              // Not already included as a network plugin.
 857              && ( ! $network_plugins || ! in_array( WP_PLUGIN_DIR . '/' . $plugin, $network_plugins, true ) )
 858              ) {
 859              $plugins[] = WP_PLUGIN_DIR . '/' . $plugin;
 860          }
 861      }
 862  
 863      /*
 864       * Remove plugins from the list of active plugins when we're on an endpoint
 865       * that should be protected against WSODs and the plugin is paused.
 866       */
 867      if ( wp_is_recovery_mode() ) {
 868          $plugins = wp_skip_paused_plugins( $plugins );
 869      }
 870  
 871      return $plugins;
 872  }
 873  
 874  /**
 875   * Filters a given list of plugins, removing any paused plugins from it.
 876   *
 877   * @since 5.2.0
 878   *
 879   * @param string[] $plugins Array of absolute plugin main file paths.
 880   * @return string[] Filtered array of plugins, without any paused plugins.
 881   */
 882  function wp_skip_paused_plugins( array $plugins ) {
 883      $paused_plugins = wp_paused_plugins()->get_all();
 884  
 885      if ( empty( $paused_plugins ) ) {
 886          return $plugins;
 887      }
 888  
 889      foreach ( $plugins as $index => $plugin ) {
 890          list( $plugin ) = explode( '/', plugin_basename( $plugin ) );
 891  
 892          if ( array_key_exists( $plugin, $paused_plugins ) ) {
 893              unset( $plugins[ $index ] );
 894  
 895              // Store list of paused plugins for displaying an admin notice.
 896              $GLOBALS['_paused_plugins'][ $plugin ] = $paused_plugins[ $plugin ];
 897          }
 898      }
 899  
 900      return $plugins;
 901  }
 902  
 903  /**
 904   * Retrieves an array of active and valid themes.
 905   *
 906   * While upgrading or installing WordPress, no themes are returned.
 907   *
 908   * @since 5.1.0
 909   * @access private
 910   *
 911   * @global string $pagenow The filename of the current screen.
 912   *
 913   * @return string[] Array of absolute paths to theme directories.
 914   */
 915  function wp_get_active_and_valid_themes() {
 916      global $pagenow;
 917  
 918      $themes = array();
 919  
 920      if ( wp_installing() && 'wp-activate.php' !== $pagenow ) {
 921          return $themes;
 922      }
 923  
 924      if ( TEMPLATEPATH !== STYLESHEETPATH ) {
 925          $themes[] = STYLESHEETPATH;
 926      }
 927  
 928      $themes[] = TEMPLATEPATH;
 929  
 930      /*
 931       * Remove themes from the list of active themes when we're on an endpoint
 932       * that should be protected against WSODs and the theme is paused.
 933       */
 934      if ( wp_is_recovery_mode() ) {
 935          $themes = wp_skip_paused_themes( $themes );
 936  
 937          // If no active and valid themes exist, skip loading themes.
 938          if ( empty( $themes ) ) {
 939              add_filter( 'wp_using_themes', '__return_false' );
 940          }
 941      }
 942  
 943      return $themes;
 944  }
 945  
 946  /**
 947   * Filters a given list of themes, removing any paused themes from it.
 948   *
 949   * @since 5.2.0
 950   *
 951   * @param string[] $themes Array of absolute theme directory paths.
 952   * @return string[] Filtered array of absolute paths to themes, without any paused themes.
 953   */
 954  function wp_skip_paused_themes( array $themes ) {
 955      $paused_themes = wp_paused_themes()->get_all();
 956  
 957      if ( empty( $paused_themes ) ) {
 958          return $themes;
 959      }
 960  
 961      foreach ( $themes as $index => $theme ) {
 962          $theme = basename( $theme );
 963  
 964          if ( array_key_exists( $theme, $paused_themes ) ) {
 965              unset( $themes[ $index ] );
 966  
 967              // Store list of paused themes for displaying an admin notice.
 968              $GLOBALS['_paused_themes'][ $theme ] = $paused_themes[ $theme ];
 969          }
 970      }
 971  
 972      return $themes;
 973  }
 974  
 975  /**
 976   * Is WordPress in Recovery Mode.
 977   *
 978   * In this mode, plugins or themes that cause WSODs will be paused.
 979   *
 980   * @since 5.2.0
 981   *
 982   * @return bool
 983   */
 984  function wp_is_recovery_mode() {
 985      return wp_recovery_mode()->is_active();
 986  }
 987  
 988  /**
 989   * Determines whether we are currently on an endpoint that should be protected against WSODs.
 990   *
 991   * @since 5.2.0
 992   *
 993   * @global string $pagenow The filename of the current screen.
 994   *
 995   * @return bool True if the current endpoint should be protected.
 996   */
 997  function is_protected_endpoint() {
 998      // Protect login pages.
 999      if ( isset( $GLOBALS['pagenow'] ) && 'wp-login.php' === $GLOBALS['pagenow'] ) {
1000          return true;
1001      }
1002  
1003      // Protect the admin backend.
1004      if ( is_admin() && ! wp_doing_ajax() ) {
1005          return true;
1006      }
1007  
1008      // Protect Ajax actions that could help resolve a fatal error should be available.
1009      if ( is_protected_ajax_action() ) {
1010          return true;
1011      }
1012  
1013      /**
1014       * Filters whether the current request is against a protected endpoint.
1015       *
1016       * This filter is only fired when an endpoint is requested which is not already protected by
1017       * WordPress core. As such, it exclusively allows providing further protected endpoints in
1018       * addition to the admin backend, login pages and protected Ajax actions.
1019       *
1020       * @since 5.2.0
1021       *
1022       * @param bool $is_protected_endpoint Whether the currently requested endpoint is protected.
1023       *                                    Default false.
1024       */
1025      return (bool) apply_filters( 'is_protected_endpoint', false );
1026  }
1027  
1028  /**
1029   * Determines whether we are currently handling an Ajax action that should be protected against WSODs.
1030   *
1031   * @since 5.2.0
1032   *
1033   * @return bool True if the current Ajax action should be protected.
1034   */
1035  function is_protected_ajax_action() {
1036      if ( ! wp_doing_ajax() ) {
1037          return false;
1038      }
1039  
1040      if ( ! isset( $_REQUEST['action'] ) ) {
1041          return false;
1042      }
1043  
1044      $actions_to_protect = array(
1045          'edit-theme-plugin-file', // Saving changes in the core code editor.
1046          'heartbeat',              // Keep the heart beating.
1047          'install-plugin',         // Installing a new plugin.
1048          'install-theme',          // Installing a new theme.
1049          'search-plugins',         // Searching in the list of plugins.
1050          'search-install-plugins', // Searching for a plugin in the plugin install screen.
1051          'update-plugin',          // Update an existing plugin.
1052          'update-theme',           // Update an existing theme.
1053      );
1054  
1055      /**
1056       * Filters the array of protected Ajax actions.
1057       *
1058       * This filter is only fired when doing Ajax and the Ajax request has an 'action' property.
1059       *
1060       * @since 5.2.0
1061       *
1062       * @param string[] $actions_to_protect Array of strings with Ajax actions to protect.
1063       */
1064      $actions_to_protect = (array) apply_filters( 'wp_protected_ajax_actions', $actions_to_protect );
1065  
1066      if ( ! in_array( $_REQUEST['action'], $actions_to_protect, true ) ) {
1067          return false;
1068      }
1069  
1070      return true;
1071  }
1072  
1073  /**
1074   * Set internal encoding.
1075   *
1076   * In most cases the default internal encoding is latin1, which is
1077   * of no use, since we want to use the `mb_` functions for `utf-8` strings.
1078   *
1079   * @since 3.0.0
1080   * @access private
1081   */
1082  function wp_set_internal_encoding() {
1083      if ( function_exists( 'mb_internal_encoding' ) ) {
1084          $charset = get_option( 'blog_charset' );
1085          // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
1086          if ( ! $charset || ! @mb_internal_encoding( $charset ) ) {
1087              mb_internal_encoding( 'UTF-8' );
1088          }
1089      }
1090  }
1091  
1092  /**
1093   * Add magic quotes to `$_GET`, `$_POST`, `$_COOKIE`, and `$_SERVER`.
1094   *
1095   * Also forces `$_REQUEST` to be `$_GET + $_POST`. If `$_SERVER`,
1096   * `$_COOKIE`, or `$_ENV` are needed, use those superglobals directly.
1097   *
1098   * @since 3.0.0
1099   * @access private
1100   */
1101  function wp_magic_quotes() {
1102      // Escape with wpdb.
1103      $_GET    = add_magic_quotes( $_GET );
1104      $_POST   = add_magic_quotes( $_POST );
1105      $_COOKIE = add_magic_quotes( $_COOKIE );
1106      $_SERVER = add_magic_quotes( $_SERVER );
1107  
1108      // Force REQUEST to be GET + POST.
1109      $_REQUEST = array_merge( $_GET, $_POST );
1110  }
1111  
1112  /**
1113   * Runs just before PHP shuts down execution.
1114   *
1115   * @since 1.2.0
1116   * @access private
1117   */
1118  function shutdown_action_hook() {
1119      /**
1120       * Fires just before PHP shuts down execution.
1121       *
1122       * @since 1.2.0
1123       */
1124      do_action( 'shutdown' );
1125  
1126      wp_cache_close();
1127  }
1128  
1129  /**
1130   * Copy an object.
1131   *
1132   * @since 2.7.0
1133   * @deprecated 3.2.0
1134   *
1135   * @param object $object The object to clone.
1136   * @return object The cloned object.
1137   */
1138  function wp_clone( $object ) {
1139      // Use parens for clone to accommodate PHP 4. See #17880.
1140      return clone( $object );
1141  }
1142  
1143  /**
1144   * Determines whether the current request is for the login screen.
1145   *
1146   * @since 6.1.0
1147   *
1148   * @see wp_login_url()
1149   *
1150   * @return bool True if inside WordPress login screen, false otherwise.
1151   */
1152  function is_login_screen() {
1153      return false !== stripos( wp_login_url(), $_SERVER['SCRIPT_NAME'] );
1154  }
1155  
1156  /**
1157   * Determines whether the current request is for an administrative interface page.
1158   *
1159   * Does not check if the user is an administrator; use current_user_can()
1160   * for checking roles and capabilities.
1161   *
1162   * For more information on this and similar theme functions, check out
1163   * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
1164   * Conditional Tags} article in the Theme Developer Handbook.
1165   *
1166   * @since 1.5.1
1167   *
1168   * @global WP_Screen $current_screen WordPress current screen object.
1169   *
1170   * @return bool True if inside WordPress administration interface, false otherwise.
1171   */
1172  function is_admin() {
1173      if ( isset( $GLOBALS['current_screen'] ) ) {
1174          return $GLOBALS['current_screen']->in_admin();
1175      } elseif ( defined( 'WP_ADMIN' ) ) {
1176          return WP_ADMIN;
1177      }
1178  
1179      return false;
1180  }
1181  
1182  /**
1183   * Whether the current request is for a site's administrative interface.
1184   *
1185   * e.g. `/wp-admin/`
1186   *
1187   * Does not check if the user is an administrator; use current_user_can()
1188   * for checking roles and capabilities.
1189   *
1190   * @since 3.1.0
1191   *
1192   * @global WP_Screen $current_screen WordPress current screen object.
1193   *
1194   * @return bool True if inside WordPress blog administration pages.
1195   */
1196  function is_blog_admin() {
1197      if ( isset( $GLOBALS['current_screen'] ) ) {
1198          return $GLOBALS['current_screen']->in_admin( 'site' );
1199      } elseif ( defined( 'WP_BLOG_ADMIN' ) ) {
1200          return WP_BLOG_ADMIN;
1201      }
1202  
1203      return false;
1204  }
1205  
1206  /**
1207   * Whether the current request is for the network administrative interface.
1208   *
1209   * e.g. `/wp-admin/network/`
1210   *
1211   * Does not check if the user is an administrator; use current_user_can()
1212   * for checking roles and capabilities.
1213   *
1214   * Does not check if the site is a Multisite network; use is_multisite()
1215   * for checking if Multisite is enabled.
1216   *
1217   * @since 3.1.0
1218   *
1219   * @global WP_Screen $current_screen WordPress current screen object.
1220   *
1221   * @return bool True if inside WordPress network administration pages.
1222   */
1223  function is_network_admin() {
1224      if ( isset( $GLOBALS['current_screen'] ) ) {
1225          return $GLOBALS['current_screen']->in_admin( 'network' );
1226      } elseif ( defined( 'WP_NETWORK_ADMIN' ) ) {
1227          return WP_NETWORK_ADMIN;
1228      }
1229  
1230      return false;
1231  }
1232  
1233  /**
1234   * Whether the current request is for a user admin screen.
1235   *
1236   * e.g. `/wp-admin/user/`
1237   *
1238   * Does not check if the user is an administrator; use current_user_can()
1239   * for checking roles and capabilities.
1240   *
1241   * @since 3.1.0
1242   *
1243   * @global WP_Screen $current_screen WordPress current screen object.
1244   *
1245   * @return bool True if inside WordPress user administration pages.
1246   */
1247  function is_user_admin() {
1248      if ( isset( $GLOBALS['current_screen'] ) ) {
1249          return $GLOBALS['current_screen']->in_admin( 'user' );
1250      } elseif ( defined( 'WP_USER_ADMIN' ) ) {
1251          return WP_USER_ADMIN;
1252      }
1253  
1254      return false;
1255  }
1256  
1257  /**
1258   * If Multisite is enabled.
1259   *
1260   * @since 3.0.0
1261   *
1262   * @return bool True if Multisite is enabled, false otherwise.
1263   */
1264  function is_multisite() {
1265      if ( defined( 'MULTISITE' ) ) {
1266          return MULTISITE;
1267      }
1268  
1269      if ( defined( 'SUBDOMAIN_INSTALL' ) || defined( 'VHOST' ) || defined( 'SUNRISE' ) ) {
1270          return true;
1271      }
1272  
1273      return false;
1274  }
1275  
1276  /**
1277   * Retrieve the current site ID.
1278   *
1279   * @since 3.1.0
1280   *
1281   * @global int $blog_id
1282   *
1283   * @return int Site ID.
1284   */
1285  function get_current_blog_id() {
1286      global $blog_id;
1287      return absint( $blog_id );
1288  }
1289  
1290  /**
1291   * Retrieves the current network ID.
1292   *
1293   * @since 4.6.0
1294   *
1295   * @return int The ID of the current network.
1296   */
1297  function get_current_network_id() {
1298      if ( ! is_multisite() ) {
1299          return 1;
1300      }
1301  
1302      $current_network = get_network();
1303  
1304      if ( ! isset( $current_network->id ) ) {
1305          return get_main_network_id();
1306      }
1307  
1308      return absint( $current_network->id );
1309  }
1310  
1311  /**
1312   * Attempt an early load of translations.
1313   *
1314   * Used for errors encountered during the initial loading process, before
1315   * the locale has been properly detected and loaded.
1316   *
1317   * Designed for unusual load sequences (like setup-config.php) or for when
1318   * the script will then terminate with an error, otherwise there is a risk
1319   * that a file can be double-included.
1320   *
1321   * @since 3.4.0
1322   * @access private
1323   *
1324   * @global WP_Locale $wp_locale WordPress date and time locale object.
1325   */
1326  function wp_load_translations_early() {
1327      global $wp_locale;
1328  
1329      static $loaded = false;
1330      if ( $loaded ) {
1331          return;
1332      }
1333      $loaded = true;
1334  
1335      if ( function_exists( 'did_action' ) && did_action( 'init' ) ) {
1336          return;
1337      }
1338  
1339      // We need $wp_local_package.
1340      require  ABSPATH . WPINC . '/version.php';
1341  
1342      // Translation and localization.
1343      require_once  ABSPATH . WPINC . '/pomo/mo.php';
1344      require_once  ABSPATH . WPINC . '/l10n.php';
1345      require_once  ABSPATH . WPINC . '/class-wp-locale.php';
1346      require_once  ABSPATH . WPINC . '/class-wp-locale-switcher.php';
1347  
1348      // General libraries.
1349      require_once  ABSPATH . WPINC . '/plugin.php';
1350  
1351      $locales   = array();
1352      $locations = array();
1353  
1354      while ( true ) {
1355          if ( defined( 'WPLANG' ) ) {
1356              if ( '' === WPLANG ) {
1357                  break;
1358              }
1359              $locales[] = WPLANG;
1360          }
1361  
1362          if ( isset( $wp_local_package ) ) {
1363              $locales[] = $wp_local_package;
1364          }
1365  
1366          if ( ! $locales ) {
1367              break;
1368          }
1369  
1370          if ( defined( 'WP_LANG_DIR' ) && @is_dir( WP_LANG_DIR ) ) {
1371              $locations[] = WP_LANG_DIR;
1372          }
1373  
1374          if ( defined( 'WP_CONTENT_DIR' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) ) {
1375              $locations[] = WP_CONTENT_DIR . '/languages';
1376          }
1377  
1378          if ( @is_dir( ABSPATH . 'wp-content/languages' ) ) {
1379              $locations[] = ABSPATH . 'wp-content/languages';
1380          }
1381  
1382          if ( @is_dir( ABSPATH . WPINC . '/languages' ) ) {
1383              $locations[] = ABSPATH . WPINC . '/languages';
1384          }
1385  
1386          if ( ! $locations ) {
1387              break;
1388          }
1389  
1390          $locations = array_unique( $locations );
1391  
1392          foreach ( $locales as $locale ) {
1393              foreach ( $locations as $location ) {
1394                  if ( file_exists( $location . '/' . $locale . '.mo' ) ) {
1395                      load_textdomain( 'default', $location . '/' . $locale . '.mo' );
1396                      if ( defined( 'WP_SETUP_CONFIG' ) && file_exists( $location . '/admin-' . $locale . '.mo' ) ) {
1397                          load_textdomain( 'default', $location . '/admin-' . $locale . '.mo' );
1398                      }
1399                      break 2;
1400                  }
1401              }
1402          }
1403  
1404          break;
1405      }
1406  
1407      $wp_locale = new WP_Locale();
1408  }
1409  
1410  /**
1411   * Check or set whether WordPress is in "installation" mode.
1412   *
1413   * If the `WP_INSTALLING` constant is defined during the bootstrap, `wp_installing()` will default to `true`.
1414   *
1415   * @since 4.4.0
1416   *
1417   * @param bool $is_installing Optional. True to set WP into Installing mode, false to turn Installing mode off.
1418   *                            Omit this parameter if you only want to fetch the current status.
1419   * @return bool True if WP is installing, otherwise false. When a `$is_installing` is passed, the function will
1420   *              report whether WP was in installing mode prior to the change to `$is_installing`.
1421   */
1422  function wp_installing( $is_installing = null ) {
1423      static $installing = null;
1424  
1425      // Support for the `WP_INSTALLING` constant, defined before WP is loaded.
1426      if ( is_null( $installing ) ) {
1427          $installing = defined( 'WP_INSTALLING' ) && WP_INSTALLING;
1428      }
1429  
1430      if ( ! is_null( $is_installing ) ) {
1431          $old_installing = $installing;
1432          $installing     = $is_installing;
1433          return (bool) $old_installing;
1434      }
1435  
1436      return (bool) $installing;
1437  }
1438  
1439  /**
1440   * Determines if SSL is used.
1441   *
1442   * @since 2.6.0
1443   * @since 4.6.0 Moved from functions.php to load.php.
1444   *
1445   * @return bool True if SSL, otherwise false.
1446   */
1447  function is_ssl() {
1448      if ( isset( $_SERVER['HTTPS'] ) ) {
1449          if ( 'on' === strtolower( $_SERVER['HTTPS'] ) ) {
1450              return true;
1451          }
1452  
1453          if ( '1' == $_SERVER['HTTPS'] ) {
1454              return true;
1455          }
1456      } elseif ( isset( $_SERVER['SERVER_PORT'] ) && ( '443' == $_SERVER['SERVER_PORT'] ) ) {
1457          return true;
1458      }
1459      return false;
1460  }
1461  
1462  /**
1463   * Converts a shorthand byte value to an integer byte value.
1464   *
1465   * @since 2.3.0
1466   * @since 4.6.0 Moved from media.php to load.php.
1467   *
1468   * @link https://www.php.net/manual/en/function.ini-get.php
1469   * @link https://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes
1470   *
1471   * @param string $value A (PHP ini) byte value, either shorthand or ordinary.
1472   * @return int An integer byte value.
1473   */
1474  function wp_convert_hr_to_bytes( $value ) {
1475      $value = strtolower( trim( $value ) );
1476      $bytes = (int) $value;
1477  
1478      if ( false !== strpos( $value, 'g' ) ) {
1479          $bytes *= GB_IN_BYTES;
1480      } elseif ( false !== strpos( $value, 'm' ) ) {
1481          $bytes *= MB_IN_BYTES;
1482      } elseif ( false !== strpos( $value, 'k' ) ) {
1483          $bytes *= KB_IN_BYTES;
1484      }
1485  
1486      // Deal with large (float) values which run into the maximum integer size.
1487      return min( $bytes, PHP_INT_MAX );
1488  }
1489  
1490  /**
1491   * Determines whether a PHP ini value is changeable at runtime.
1492   *
1493   * @since 4.6.0
1494   *
1495   * @link https://www.php.net/manual/en/function.ini-get-all.php
1496   *
1497   * @param string $setting The name of the ini setting to check.
1498   * @return bool True if the value is changeable at runtime. False otherwise.
1499   */
1500  function wp_is_ini_value_changeable( $setting ) {
1501      static $ini_all;
1502  
1503      if ( ! isset( $ini_all ) ) {
1504          $ini_all = false;
1505          // Sometimes `ini_get_all()` is disabled via the `disable_functions` option for "security purposes".
1506          if ( function_exists( 'ini_get_all' ) ) {
1507              $ini_all = ini_get_all();
1508          }
1509      }
1510  
1511      // 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.
1512      if ( isset( $ini_all[ $setting ]['access'] ) && ( INI_ALL === ( $ini_all[ $setting ]['access'] & 7 ) || INI_USER === ( $ini_all[ $setting ]['access'] & 7 ) ) ) {
1513          return true;
1514      }
1515  
1516      // If we were unable to retrieve the details, fail gracefully to assume it's changeable.
1517      if ( ! is_array( $ini_all ) ) {
1518          return true;
1519      }
1520  
1521      return false;
1522  }
1523  
1524  /**
1525   * Determines whether the current request is a WordPress Ajax request.
1526   *
1527   * @since 4.7.0
1528   *
1529   * @return bool True if it's a WordPress Ajax request, false otherwise.
1530   */
1531  function wp_doing_ajax() {
1532      /**
1533       * Filters whether the current request is a WordPress Ajax request.
1534       *
1535       * @since 4.7.0
1536       *
1537       * @param bool $wp_doing_ajax Whether the current request is a WordPress Ajax request.
1538       */
1539      return apply_filters( 'wp_doing_ajax', defined( 'DOING_AJAX' ) && DOING_AJAX );
1540  }
1541  
1542  /**
1543   * Determines whether the current request should use themes.
1544   *
1545   * @since 5.1.0
1546   *
1547   * @return bool True if themes should be used, false otherwise.
1548   */
1549  function wp_using_themes() {
1550      /**
1551       * Filters whether the current request should use themes.
1552       *
1553       * @since 5.1.0
1554       *
1555       * @param bool $wp_using_themes Whether the current request should use themes.
1556       */
1557      return apply_filters( 'wp_using_themes', defined( 'WP_USE_THEMES' ) && WP_USE_THEMES );
1558  }
1559  
1560  /**
1561   * Determines whether the current request is a WordPress cron request.
1562   *
1563   * @since 4.8.0
1564   *
1565   * @return bool True if it's a WordPress cron request, false otherwise.
1566   */
1567  function wp_doing_cron() {
1568      /**
1569       * Filters whether the current request is a WordPress cron request.
1570       *
1571       * @since 4.8.0
1572       *
1573       * @param bool $wp_doing_cron Whether the current request is a WordPress cron request.
1574       */
1575      return apply_filters( 'wp_doing_cron', defined( 'DOING_CRON' ) && DOING_CRON );
1576  }
1577  
1578  /**
1579   * Checks whether the given variable is a WordPress Error.
1580   *
1581   * Returns whether `$thing` is an instance of the `WP_Error` class.
1582   *
1583   * @since 2.1.0
1584   *
1585   * @param mixed $thing The variable to check.
1586   * @return bool Whether the variable is an instance of WP_Error.
1587   */
1588  function is_wp_error( $thing ) {
1589      $is_wp_error = ( $thing instanceof WP_Error );
1590  
1591      if ( $is_wp_error ) {
1592          /**
1593           * Fires when `is_wp_error()` is called and its parameter is an instance of `WP_Error`.
1594           *
1595           * @since 5.6.0
1596           *
1597           * @param WP_Error $thing The error object passed to `is_wp_error()`.
1598           */
1599          do_action( 'is_wp_error_instance', $thing );
1600      }
1601  
1602      return $is_wp_error;
1603  }
1604  
1605  /**
1606   * Determines whether file modifications are allowed.
1607   *
1608   * @since 4.8.0
1609   *
1610   * @param string $context The usage context.
1611   * @return bool True if file modification is allowed, false otherwise.
1612   */
1613  function wp_is_file_mod_allowed( $context ) {
1614      /**
1615       * Filters whether file modifications are allowed.
1616       *
1617       * @since 4.8.0
1618       *
1619       * @param bool   $file_mod_allowed Whether file modifications are allowed.
1620       * @param string $context          The usage context.
1621       */
1622      return apply_filters( 'file_mod_allowed', ! defined( 'DISALLOW_FILE_MODS' ) || ! DISALLOW_FILE_MODS, $context );
1623  }
1624  
1625  /**
1626   * Start scraping edited file errors.
1627   *
1628   * @since 4.9.0
1629   */
1630  function wp_start_scraping_edited_file_errors() {
1631      if ( ! isset( $_REQUEST['wp_scrape_key'] ) || ! isset( $_REQUEST['wp_scrape_nonce'] ) ) {
1632          return;
1633      }
1634      $key   = substr( sanitize_key( wp_unslash( $_REQUEST['wp_scrape_key'] ) ), 0, 32 );
1635      $nonce = wp_unslash( $_REQUEST['wp_scrape_nonce'] );
1636  
1637      if ( get_transient( 'scrape_key_' . $key ) !== $nonce ) {
1638          echo "###### wp_scraping_result_start:$key ######";
1639          echo wp_json_encode(
1640              array(
1641                  'code'    => 'scrape_nonce_failure',
1642                  'message' => __( 'Scrape key check failed. Please try again.' ),
1643              )
1644          );
1645          echo "###### wp_scraping_result_end:$key ######";
1646          die();
1647      }
1648      if ( ! defined( 'WP_SANDBOX_SCRAPING' ) ) {
1649          define( 'WP_SANDBOX_SCRAPING', true );
1650      }
1651      register_shutdown_function( 'wp_finalize_scraping_edited_file_errors', $key );
1652  }
1653  
1654  /**
1655   * Finalize scraping for edited file errors.
1656   *
1657   * @since 4.9.0
1658   *
1659   * @param string $scrape_key Scrape key.
1660   */
1661  function wp_finalize_scraping_edited_file_errors( $scrape_key ) {
1662      $error = error_get_last();
1663      echo "\n###### wp_scraping_result_start:$scrape_key ######\n";
1664      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 ) ) {
1665          $error = str_replace( ABSPATH, '', $error );
1666          echo wp_json_encode( $error );
1667      } else {
1668          echo wp_json_encode( true );
1669      }
1670      echo "\n###### wp_scraping_result_end:$scrape_key ######\n";
1671  }
1672  
1673  /**
1674   * Checks whether current request is a JSON request, or is expecting a JSON response.
1675   *
1676   * @since 5.0.0
1677   *
1678   * @return bool True if `Accepts` or `Content-Type` headers contain `application/json`.
1679   *              False otherwise.
1680   */
1681  function wp_is_json_request() {
1682  
1683      if ( isset( $_SERVER['HTTP_ACCEPT'] ) && wp_is_json_media_type( $_SERVER['HTTP_ACCEPT'] ) ) {
1684          return true;
1685      }
1686  
1687      if ( isset( $_SERVER['CONTENT_TYPE'] ) && wp_is_json_media_type( $_SERVER['CONTENT_TYPE'] ) ) {
1688          return true;
1689      }
1690  
1691      return false;
1692  
1693  }
1694  
1695  /**
1696   * Checks whether current request is a JSONP request, or is expecting a JSONP response.
1697   *
1698   * @since 5.2.0
1699   *
1700   * @return bool True if JSONP request, false otherwise.
1701   */
1702  function wp_is_jsonp_request() {
1703      if ( ! isset( $_GET['_jsonp'] ) ) {
1704          return false;
1705      }
1706  
1707      if ( ! function_exists( 'wp_check_jsonp_callback' ) ) {
1708          require_once  ABSPATH . WPINC . '/functions.php';
1709      }
1710  
1711      $jsonp_callback = $_GET['_jsonp'];
1712      if ( ! wp_check_jsonp_callback( $jsonp_callback ) ) {
1713          return false;
1714      }
1715  
1716      /** This filter is documented in wp-includes/rest-api/class-wp-rest-server.php */
1717      $jsonp_enabled = apply_filters( 'rest_jsonp_enabled', true );
1718  
1719      return $jsonp_enabled;
1720  
1721  }
1722  
1723  /**
1724   * Checks whether a string is a valid JSON Media Type.
1725   *
1726   * @since 5.6.0
1727   *
1728   * @param string $media_type A Media Type string to check.
1729   * @return bool True if string is a valid JSON Media Type.
1730   */
1731  function wp_is_json_media_type( $media_type ) {
1732      static $cache = array();
1733  
1734      if ( ! isset( $cache[ $media_type ] ) ) {
1735          $cache[ $media_type ] = (bool) preg_match( '/(^|\s|,)application\/([\w!#\$&-\^\.\+]+\+)?json(\+oembed)?($|\s|;|,)/i', $media_type );
1736      }
1737  
1738      return $cache[ $media_type ];
1739  }
1740  
1741  /**
1742   * Checks whether current request is an XML request, or is expecting an XML response.
1743   *
1744   * @since 5.2.0
1745   *
1746   * @return bool True if `Accepts` or `Content-Type` headers contain `text/xml`
1747   *              or one of the related MIME types. False otherwise.
1748   */
1749  function wp_is_xml_request() {
1750      $accepted = array(
1751          'text/xml',
1752          'application/rss+xml',
1753          'application/atom+xml',
1754          'application/rdf+xml',
1755          'text/xml+oembed',
1756          'application/xml+oembed',
1757      );
1758  
1759      if ( isset( $_SERVER['HTTP_ACCEPT'] ) ) {
1760          foreach ( $accepted as $type ) {
1761              if ( false !== strpos( $_SERVER['HTTP_ACCEPT'], $type ) ) {
1762                  return true;
1763              }
1764          }
1765      }
1766  
1767      if ( isset( $_SERVER['CONTENT_TYPE'] ) && in_array( $_SERVER['CONTENT_TYPE'], $accepted, true ) ) {
1768          return true;
1769      }
1770  
1771      return false;
1772  }
1773  
1774  /**
1775   * Checks if this site is protected by HTTP Basic Auth.
1776   *
1777   * At the moment, this merely checks for the present of Basic Auth credentials. Therefore, calling
1778   * this function with a context different from the current context may give inaccurate results.
1779   * In a future release, this evaluation may be made more robust.
1780   *
1781   * Currently, this is only used by Application Passwords to prevent a conflict since it also utilizes
1782   * Basic Auth.
1783   *
1784   * @since 5.6.1
1785   *
1786   * @global string $pagenow The filename of the current screen.
1787   *
1788   * @param string $context The context to check for protection. Accepts 'login', 'admin', and 'front'.
1789   *                        Defaults to the current context.
1790   * @return bool Whether the site is protected by Basic Auth.
1791   */
1792  function wp_is_site_protected_by_basic_auth( $context = '' ) {
1793      global $pagenow;
1794  
1795      if ( ! $context ) {
1796          if ( 'wp-login.php' === $pagenow ) {
1797              $context = 'login';
1798          } elseif ( is_admin() ) {
1799              $context = 'admin';
1800          } else {
1801              $context = 'front';
1802          }
1803      }
1804  
1805      $is_protected = ! empty( $_SERVER['PHP_AUTH_USER'] ) || ! empty( $_SERVER['PHP_AUTH_PW'] );
1806  
1807      /**
1808       * Filters whether a site is protected by HTTP Basic Auth.
1809       *
1810       * @since 5.6.1
1811       *
1812       * @param bool $is_protected Whether the site is protected by Basic Auth.
1813       * @param string $context    The context to check for protection. One of 'login', 'admin', or 'front'.
1814       */
1815      return apply_filters( 'wp_is_site_protected_by_basic_auth', $is_protected, $context );
1816  }


Generated : Fri Aug 19 08:20:02 2022 Cross-referenced by PHPXref