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


Generated: Wed Jul 24 01:00:02 2019 Cross-referenced by PHPXref 0.7.1