[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

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


Generated: Wed Oct 16 08:20:01 2019 Cross-referenced by PHPXref 0.7