WordPress PHP Cross Reference Blogging Systems

Source: /wp-includes/load.php - 1038 lines - 30326 bytes - Summary - Text - Print

Description: These functions are needed to load WordPress.

   1  <?php
   2  /**
   3   * These functions are needed to load WordPress.
   4   *
   5   * @internal This file must be parsable by PHP4.
   6   *
   7   * @package WordPress
   8   */
   9  
  10  /**
  11   * Return the HTTP protocol sent by the server.
  12   *
  13   * @since 4.4.0
  14   *
  15   * @return string The HTTP protocol. Default: HTTP/1.0.
  16   */
  17  function wp_get_server_protocol() {
  18      $protocol = $_SERVER['SERVER_PROTOCOL'];
  19      if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0' ) ) ) {
  20          $protocol = 'HTTP/1.0';
  21      }
  22      return $protocol;
  23  }
  24  
  25  /**
  26   * Turn register globals off.
  27   *
  28   * @since 2.1.0
  29   * @access private
  30   */
  31  function wp_unregister_GLOBALS() {
  32      if ( !ini_get( 'register_globals' ) )
  33          return;
  34  
  35      if ( isset( $_REQUEST['GLOBALS'] ) )
  36          die( 'GLOBALS overwrite attempt detected' );
  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   * Fix `$_SERVER` variables for various setups.
  50   *
  51   * @since 3.0.0
  52   * @access private
  53   *
  54   * @global string $PHP_SELF The filename of the currently executing script,
  55   *                          relative to the document root.
  56   */
  57  function wp_fix_server_vars() {
  58      global $PHP_SELF;
  59  
  60      $default_server_values = array(
  61          'SERVER_SOFTWARE' => '',
  62          'REQUEST_URI' => '',
  63      );
  64  
  65      $_SERVER = array_merge( $default_server_values, $_SERVER );
  66  
  67      // Fix for IIS when running with PHP ISAPI
  68      if ( empty( $_SERVER['REQUEST_URI'] ) || ( PHP_SAPI != 'cgi-fcgi' && preg_match( '/^Microsoft-IIS\//', $_SERVER['SERVER_SOFTWARE'] ) ) ) {
  69  
  70          // IIS Mod-Rewrite
  71          if ( isset( $_SERVER['HTTP_X_ORIGINAL_URL'] ) ) {
  72              $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
  73          }
  74          // IIS Isapi_Rewrite
  75          elseif ( isset( $_SERVER['HTTP_X_REWRITE_URL'] ) ) {
  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              // Some IIS + PHP configurations puts the script-name in the path-info (No need to append it twice)
  83              if ( isset( $_SERVER['PATH_INFO'] ) ) {
  84                  if ( $_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME'] )
  85                      $_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'];
  86                  else
  87                      $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO'];
  88              }
  89  
  90              // Append the query string if it exists and isn't null
  91              if ( ! empty( $_SERVER['QUERY_STRING'] ) ) {
  92                  $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
  93              }
  94          }
  95      }
  96  
  97      // Fix for PHP as CGI hosts that set SCRIPT_FILENAME to something ending in php.cgi for all requests
  98      if ( isset( $_SERVER['SCRIPT_FILENAME'] ) && ( strpos( $_SERVER['SCRIPT_FILENAME'], 'php.cgi' ) == strlen( $_SERVER['SCRIPT_FILENAME'] ) - 7 ) )
  99          $_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED'];
 100  
 101      // Fix for Dreamhost and other PHP as CGI hosts
 102      if ( strpos( $_SERVER['SCRIPT_NAME'], 'php.cgi' ) !== false )
 103          unset( $_SERVER['PATH_INFO'] );
 104  
 105      // Fix empty PHP_SELF
 106      $PHP_SELF = $_SERVER['PHP_SELF'];
 107      if ( empty( $PHP_SELF ) )
 108          $_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace( '/(\?.*)?$/', '', $_SERVER["REQUEST_URI"] );
 109  }
 110  
 111  /**
 112   * Check for the required PHP version, and the MySQL extension or
 113   * a database drop-in.
 114   *
 115   * Dies if requirements are not met.
 116   *
 117   * @since 3.0.0
 118   * @access private
 119   *
 120   * @global string $required_php_version The required PHP version string.
 121   * @global string $wp_version           The WordPress version string.
 122   */
 123  function wp_check_php_mysql_versions() {
 124      global $required_php_version, $wp_version;
 125      $php_version = phpversion();
 126  
 127      if ( version_compare( $required_php_version, $php_version, '>' ) ) {
 128          wp_load_translations_early();
 129  
 130          $protocol = wp_get_server_protocol();
 131          header( sprintf( '%s 500 Internal Server Error', $protocol ), true, 500 );
 132          header( 'Content-Type: text/html; charset=utf-8' );
 133          die( sprintf( __( 'Your server is running PHP version %1$s but WordPress %2$s requires at least %3$s.' ), $php_version, $wp_version, $required_php_version ) );
 134      }
 135  
 136      if ( ! extension_loaded( 'mysql' ) && ! extension_loaded( 'mysqli' ) && ! extension_loaded( 'mysqlnd' ) && ! file_exists( WP_CONTENT_DIR . '/db.php' ) ) {
 137          wp_load_translations_early();
 138  
 139          $protocol = wp_get_server_protocol();
 140          header( sprintf( '%s 500 Internal Server Error', $protocol ), true, 500 );
 141          header( 'Content-Type: text/html; charset=utf-8' );
 142          die( __( 'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.' ) );
 143      }
 144  }
 145  
 146  /**
 147   * Don't load all of WordPress when handling a favicon.ico request.
 148   *
 149   * Instead, send the headers for a zero-length favicon and bail.
 150   *
 151   * @since 3.0.0
 152   */
 153  function wp_favicon_request() {
 154      if ( '/favicon.ico' == $_SERVER['REQUEST_URI'] ) {
 155          header('Content-Type: image/vnd.microsoft.icon');
 156          exit;
 157      }
 158  }
 159  
 160  /**
 161   * Die with a maintenance message when conditions are met.
 162   *
 163   * Checks for a file in the WordPress root directory named ".maintenance".
 164   * This file will contain the variable $upgrading, set to the time the file
 165   * was created. If the file was created less than 10 minutes ago, WordPress
 166   * enters maintenance mode and displays a message.
 167   *
 168   * The default message can be replaced by using a drop-in (maintenance.php in
 169   * the wp-content directory).
 170   *
 171   * @since 3.0.0
 172   * @access private
 173   *
 174   * @global int $upgrading the unix timestamp marking when upgrading WordPress began.
 175   */
 176  function wp_maintenance() {
 177      if ( ! file_exists( ABSPATH . '.maintenance' ) || wp_installing() )
 178          return;
 179  
 180      global $upgrading;
 181  
 182      include( ABSPATH . '.maintenance' );
 183      // If the $upgrading timestamp is older than 10 minutes, don't die.
 184      if ( ( time() - $upgrading ) >= 600 )
 185          return;
 186  
 187      /**
 188       * Filters whether to enable maintenance mode.
 189       *
 190       * This filter runs before it can be used by plugins. It is designed for
 191       * non-web runtimes. If this filter returns true, maintenance mode will be
 192       * active and the request will end. If false, the request will be allowed to
 193       * continue processing even if maintenance mode should be active.
 194       *
 195       * @since 4.6.0
 196       *
 197       * @param bool $enable_checks Whether to enable maintenance mode. Default true.
 198       * @param int  $upgrading     The timestamp set in the .maintenance file.
 199       */
 200      if ( ! apply_filters( 'enable_maintenance_mode', true, $upgrading ) ) {
 201          return;
 202      }
 203  
 204      if ( file_exists( WP_CONTENT_DIR . '/maintenance.php' ) ) {
 205          require_once( WP_CONTENT_DIR . '/maintenance.php' );
 206          die();
 207      }
 208  
 209      wp_load_translations_early();
 210  
 211      $protocol = wp_get_server_protocol();
 212      header( "$protocol 503 Service Unavailable", true, 503 );
 213      header( 'Content-Type: text/html; charset=utf-8' );
 214      header( 'Retry-After: 600' );
 215  ?>
 216      <!DOCTYPE html>
 217      <html xmlns="http://www.w3.org/1999/xhtml"<?php if ( is_rtl() ) echo ' dir="rtl"'; ?>>
 218      <head>
 219      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 220          <title><?php _e( 'Maintenance' ); ?></title>
 221  
 222      </head>
 223      <body>
 224          <h1><?php _e( 'Briefly unavailable for scheduled maintenance. Check back in a minute.' ); ?></h1>
 225      </body>
 226      </html>
 227  <?php
 228      die();
 229  }
 230  
 231  /**
 232   * Start the WordPress micro-timer.
 233   *
 234   * @since 0.71
 235   * @access private
 236   *
 237   * @global float $timestart Unix timestamp set at the beginning of the page load.
 238   * @see timer_stop()
 239   *
 240   * @return bool Always returns true.
 241   */
 242  function timer_start() {
 243      global $timestart;
 244      $timestart = microtime( true );
 245      return true;
 246  }
 247  
 248  /**
 249   * Retrieve or display the time from the page start to when function is called.
 250   *
 251   * @since 0.71
 252   *
 253   * @global float   $timestart Seconds from when timer_start() is called.
 254   * @global float   $timeend   Seconds from when function is called.
 255   *
 256   * @param int|bool $display   Whether to echo or return the results. Accepts 0|false for return,
 257   *                            1|true for echo. Default 0|false.
 258   * @param int      $precision The number of digits from the right of the decimal to display.
 259   *                            Default 3.
 260   * @return string The "second.microsecond" finished time calculation. The number is formatted
 261   *                for human consumption, both localized and rounded.
 262   */
 263  function timer_stop( $display = 0, $precision = 3 ) {
 264      global $timestart, $timeend;
 265      $timeend = microtime( true );
 266      $timetotal = $timeend - $timestart;
 267      $r = ( function_exists( 'number_format_i18n' ) ) ? number_format_i18n( $timetotal, $precision ) : number_format( $timetotal, $precision );
 268      if ( $display )
 269          echo $r;
 270      return $r;
 271  }
 272  
 273  /**
 274   * Set PHP error reporting based on WordPress debug settings.
 275   *
 276   * Uses three constants: `WP_DEBUG`, `WP_DEBUG_DISPLAY`, and `WP_DEBUG_LOG`.
 277   * All three can be defined in wp-config.php. By default, `WP_DEBUG` and
 278   * `WP_DEBUG_LOG` are set to false, and `WP_DEBUG_DISPLAY` is set to true.
 279   *
 280   * When `WP_DEBUG` is true, all PHP notices are reported. WordPress will also
 281   * display internal notices: when a deprecated WordPress function, function
 282   * argument, or file is used. Deprecated code may be removed from a later
 283   * version.
 284   *
 285   * It is strongly recommended that plugin and theme developers use `WP_DEBUG`
 286   * in their development environments.
 287   *
 288   * `WP_DEBUG_DISPLAY` and `WP_DEBUG_LOG` perform no function unless `WP_DEBUG`
 289   * is true.
 290   *
 291   * When `WP_DEBUG_DISPLAY` is true, WordPress will force errors to be displayed.
 292   * `WP_DEBUG_DISPLAY` defaults to true. Defining it as null prevents WordPress
 293   * from changing the global configuration setting. Defining `WP_DEBUG_DISPLAY`
 294   * as false will force errors to be hidden.
 295   *
 296   * When `WP_DEBUG_LOG` is true, errors will be logged to debug.log in the content
 297   * directory.
 298   *
 299   * Errors are never displayed for XML-RPC, REST, and Ajax requests.
 300   *
 301   * @since 3.0.0
 302   * @access private
 303   */
 304  function wp_debug_mode() {
 305      /**
 306       * Filters whether to allow the debug mode check to occur.
 307       *
 308       * This filter runs before it can be used by plugins. It is designed for
 309       * non-web run-times. Returning false causes the `WP_DEBUG` and related
 310       * constants to not be checked and the default php values for errors
 311       * will be used unless you take care to update them yourself.
 312       *
 313       * @since 4.6.0
 314       *
 315       * @param bool $enable_debug_mode Whether to enable debug mode checks to occur. Default true.
 316       */
 317      if ( ! apply_filters( 'enable_wp_debug_mode_checks', true ) ){
 318          return;
 319      }
 320  
 321      if ( WP_DEBUG ) {
 322          error_reporting( E_ALL );
 323  
 324          if ( WP_DEBUG_DISPLAY )
 325              ini_set( 'display_errors', 1 );
 326          elseif ( null !== WP_DEBUG_DISPLAY )
 327              ini_set( 'display_errors', 0 );
 328  
 329          if ( WP_DEBUG_LOG ) {
 330              ini_set( 'log_errors', 1 );
 331              ini_set( 'error_log', WP_CONTENT_DIR . '/debug.log' );
 332          }
 333      } else {
 334          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 );
 335      }
 336  
 337      if ( defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
 338          @ini_set( 'display_errors', 0 );
 339      }
 340  }
 341  
 342  /**
 343   * Set the location of the language directory.
 344   *
 345   * To set directory manually, define the `WP_LANG_DIR` constant
 346   * in wp-config.php.
 347   *
 348   * If the language directory exists within `WP_CONTENT_DIR`, it
 349   * is used. Otherwise the language directory is assumed to live
 350   * in `WPINC`.
 351   *
 352   * @since 3.0.0
 353   * @access private
 354   */
 355  function wp_set_lang_dir() {
 356      if ( !defined( 'WP_LANG_DIR' ) ) {
 357          if ( file_exists( WP_CONTENT_DIR . '/languages' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) || !@is_dir(ABSPATH . WPINC . '/languages') ) {
 358              /**
 359               * Server path of the language directory.
 360               *
 361               * No leading slash, no trailing slash, full path, not relative to ABSPATH
 362               *
 363               * @since 2.1.0
 364               */
 365              define( 'WP_LANG_DIR', WP_CONTENT_DIR . '/languages' );
 366              if ( !defined( 'LANGDIR' ) ) {
 367                  // Old static relative path maintained for limited backward compatibility - won't work in some cases.
 368                  define( 'LANGDIR', 'wp-content/languages' );
 369              }
 370          } else {
 371              /**
 372               * Server path of the language directory.
 373               *
 374               * No leading slash, no trailing slash, full path, not relative to `ABSPATH`.
 375               *
 376               * @since 2.1.0
 377               */
 378              define( 'WP_LANG_DIR', ABSPATH . WPINC . '/languages' );
 379              if ( !defined( 'LANGDIR' ) ) {
 380                  // Old relative path maintained for backward compatibility.
 381                  define( 'LANGDIR', WPINC . '/languages' );
 382              }
 383          }
 384      }
 385  }
 386  
 387  /**
 388   * Load the database class file and instantiate the `$wpdb` global.
 389   *
 390   * @since 2.5.0
 391   *
 392   * @global wpdb $wpdb The WordPress database class.
 393   */
 394  function require_wp_db() {
 395      global $wpdb;
 396  
 397      require_once ( ABSPATH . WPINC . '/wp-db.php' );
 398      if ( file_exists( WP_CONTENT_DIR . '/db.php' ) )
 399          require_once( WP_CONTENT_DIR . '/db.php' );
 400  
 401      if ( isset( $wpdb ) )
 402          return;
 403  
 404      $wpdb = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST );
 405  }
 406  
 407  /**
 408   * Set the database table prefix and the format specifiers for database
 409   * table columns.
 410   *
 411   * Columns not listed here default to `%s`.
 412   *
 413   * @since 3.0.0
 414   * @access private
 415   *
 416   * @global wpdb   $wpdb         The WordPress database class.
 417   * @global string $table_prefix The database table prefix.
 418   */
 419  function wp_set_wpdb_vars() {
 420      global $wpdb, $table_prefix;
 421      if ( !empty( $wpdb->error ) )
 422          dead_db();
 423  
 424      $wpdb->field_types = array( 'post_author' => '%d', 'post_parent' => '%d', 'menu_order' => '%d', 'term_id' => '%d', 'term_group' => '%d', 'term_taxonomy_id' => '%d',
 425          'parent' => '%d', 'count' => '%d','object_id' => '%d', 'term_order' => '%d', 'ID' => '%d', 'comment_ID' => '%d', 'comment_post_ID' => '%d', 'comment_parent' => '%d',
 426          'user_id' => '%d', 'link_id' => '%d', 'link_owner' => '%d', 'link_rating' => '%d', 'option_id' => '%d', 'blog_id' => '%d', 'meta_id' => '%d', 'post_id' => '%d',
 427          'user_status' => '%d', 'umeta_id' => '%d', 'comment_karma' => '%d', 'comment_count' => '%d',
 428          // multisite:
 429          'active' => '%d', 'cat_id' => '%d', 'deleted' => '%d', 'lang_id' => '%d', 'mature' => '%d', 'public' => '%d', 'site_id' => '%d', 'spam' => '%d',
 430      );
 431  
 432      $prefix = $wpdb->set_prefix( $table_prefix );
 433  
 434      if ( is_wp_error( $prefix ) ) {
 435          wp_load_translations_early();
 436          wp_die(
 437              /* translators: 1: $table_prefix 2: wp-config.php */
 438              sprintf( __( '<strong>ERROR</strong>: %1$s in %2$s can only contain numbers, letters, and underscores.' ),
 439                  '<code>$table_prefix</code>',
 440                  '<code>wp-config.php</code>'
 441              )
 442          );
 443      }
 444  }
 445  
 446  /**
 447   * Toggle `$_wp_using_ext_object_cache` on and off without directly
 448   * touching global.
 449   *
 450   * @since 3.7.0
 451   *
 452   * @global bool $_wp_using_ext_object_cache
 453   *
 454   * @param bool $using Whether external object cache is being used.
 455   * @return bool The current 'using' setting.
 456   */
 457  function wp_using_ext_object_cache( $using = null ) {
 458      global $_wp_using_ext_object_cache;
 459      $current_using = $_wp_using_ext_object_cache;
 460      if ( null !== $using )
 461          $_wp_using_ext_object_cache = $using;
 462      return $current_using;
 463  }
 464  
 465  /**
 466   * Start the WordPress object cache.
 467   *
 468   * If an object-cache.php file exists in the wp-content directory,
 469   * it uses that drop-in as an external object cache.
 470   *
 471   * @since 3.0.0
 472   * @access private
 473   *
 474   * @global int $blog_id Blog ID.
 475   */
 476  function wp_start_object_cache() {
 477      global $blog_id;
 478  
 479      $first_init = false;
 480       if ( ! function_exists( 'wp_cache_init' ) ) {
 481          if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
 482              require_once ( WP_CONTENT_DIR . '/object-cache.php' );
 483              if ( function_exists( 'wp_cache_init' ) )
 484                  wp_using_ext_object_cache( true );
 485          }
 486  
 487          $first_init = true;
 488      } elseif ( ! wp_using_ext_object_cache() && file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
 489          /*
 490           * Sometimes advanced-cache.php can load object-cache.php before
 491           * it is loaded here. This breaks the function_exists check above
 492           * and can result in `$_wp_using_ext_object_cache` being set
 493           * incorrectly. Double check if an external cache exists.
 494           */
 495          wp_using_ext_object_cache( true );
 496      }
 497  
 498      if ( ! wp_using_ext_object_cache() )
 499          require_once  ( ABSPATH . WPINC . '/cache.php' );
 500  
 501      /*
 502       * If cache supports reset, reset instead of init if already
 503       * initialized. Reset signals to the cache that global IDs
 504       * have changed and it may need to update keys and cleanup caches.
 505       */
 506      if ( ! $first_init && function_exists( 'wp_cache_switch_to_blog' ) )
 507          wp_cache_switch_to_blog( $blog_id );
 508      elseif ( function_exists( 'wp_cache_init' ) )
 509          wp_cache_init();
 510  
 511      if ( function_exists( 'wp_cache_add_global_groups' ) ) {
 512          wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'site-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites' ) );
 513          wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
 514      }
 515  }
 516  
 517  /**
 518   * Redirect to the installer if WordPress is not installed.
 519   *
 520   * Dies with an error message when Multisite is enabled.
 521   *
 522   * @since 3.0.0
 523   * @access private
 524   */
 525  function wp_not_installed() {
 526      if ( is_multisite() ) {
 527          if ( ! is_blog_installed() && ! wp_installing() ) {
 528              nocache_headers();
 529  
 530              wp_die( __( 'The site you have requested is not installed properly. Please contact the system administrator.' ) );
 531          }
 532      } elseif ( ! is_blog_installed() && ! wp_installing() ) {
 533          nocache_headers();
 534  
 535          require ( ABSPATH . WPINC . '/kses.php' );
 536          require ( ABSPATH . WPINC . '/pluggable.php' );
 537          require ( ABSPATH . WPINC . '/formatting.php' );
 538  
 539          $link = wp_guess_url() . '/wp-admin/install.php';
 540  
 541          wp_redirect( $link );
 542          die();
 543      }
 544  }
 545  
 546  /**
 547   * Retrieve an array of must-use plugin files.
 548   *
 549   * The default directory is wp-content/mu-plugins. To change the default
 550   * directory manually, define `WPMU_PLUGIN_DIR` and `WPMU_PLUGIN_URL`
 551   * in wp-config.php.
 552   *
 553   * @since 3.0.0
 554   * @access private
 555   *
 556   * @return array Files to include.
 557   */
 558  function wp_get_mu_plugins() {
 559      $mu_plugins = array();
 560      if ( !is_dir( WPMU_PLUGIN_DIR ) )
 561          return $mu_plugins;
 562      if ( ! $dh = opendir( WPMU_PLUGIN_DIR ) )
 563          return $mu_plugins;
 564      while ( ( $plugin = readdir( $dh ) ) !== false ) {
 565          if ( substr( $plugin, -4 ) == '.php' )
 566              $mu_plugins[] = WPMU_PLUGIN_DIR . '/' . $plugin;
 567      }
 568      closedir( $dh );
 569      sort( $mu_plugins );
 570  
 571      return $mu_plugins;
 572  }
 573  
 574  /**
 575   * Retrieve an array of active and valid plugin files.
 576   *
 577   * While upgrading or installing WordPress, no plugins are returned.
 578   *
 579   * The default directory is wp-content/plugins. To change the default
 580   * directory manually, define `WP_PLUGIN_DIR` and `WP_PLUGIN_URL`
 581   * in wp-config.php.
 582   *
 583   * @since 3.0.0
 584   * @access private
 585   *
 586   * @return array Files.
 587   */
 588  function wp_get_active_and_valid_plugins() {
 589      $plugins = array();
 590      $active_plugins = (array) get_option( 'active_plugins', array() );
 591  
 592      // Check for hacks file if the option is enabled
 593      if ( get_option( 'hack_file' ) && file_exists( ABSPATH . 'my-hacks.php' ) ) {
 594          _deprecated_file( 'my-hacks.php', '1.5.0' );
 595          array_unshift( $plugins, ABSPATH . 'my-hacks.php' );
 596      }
 597  
 598      if ( empty( $active_plugins ) || wp_installing() )
 599          return $plugins;
 600  
 601      $network_plugins = is_multisite() ? wp_get_active_network_plugins() : false;
 602  
 603      foreach ( $active_plugins as $plugin ) {
 604          if ( ! validate_file( $plugin ) // $plugin must validate as file
 605              && '.php' == substr( $plugin, -4 ) // $plugin must end with '.php'
 606              && file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist
 607              // not already included as a network plugin
 608              && ( ! $network_plugins || ! in_array( WP_PLUGIN_DIR . '/' . $plugin, $network_plugins ) )
 609              )
 610          $plugins[] = WP_PLUGIN_DIR . '/' . $plugin;
 611      }
 612      return $plugins;
 613  }
 614  
 615  /**
 616   * Set internal encoding.
 617   *
 618   * In most cases the default internal encoding is latin1, which is
 619   * of no use, since we want to use the `mb_` functions for `utf-8` strings.
 620   *
 621   * @since 3.0.0
 622   * @access private
 623   */
 624  function wp_set_internal_encoding() {
 625      if ( function_exists( 'mb_internal_encoding' ) ) {
 626          $charset = get_option( 'blog_charset' );
 627          if ( ! $charset || ! @mb_internal_encoding( $charset ) )
 628              mb_internal_encoding( 'UTF-8' );
 629      }
 630  }
 631  
 632  /**
 633   * Add magic quotes to `$_GET`, `$_POST`, `$_COOKIE`, and `$_SERVER`.
 634   *
 635   * Also forces `$_REQUEST` to be `$_GET + $_POST`. If `$_SERVER`,
 636   * `$_COOKIE`, or `$_ENV` are needed, use those superglobals directly.
 637   *
 638   * @since 3.0.0
 639   * @access private
 640   */
 641  function wp_magic_quotes() {
 642      // If already slashed, strip.
 643      if ( get_magic_quotes_gpc() ) {
 644          $_GET    = stripslashes_deep( $_GET    );
 645          $_POST   = stripslashes_deep( $_POST   );
 646          $_COOKIE = stripslashes_deep( $_COOKIE );
 647      }
 648  
 649      // Escape with wpdb.
 650      $_GET    = add_magic_quotes( $_GET    );
 651      $_POST   = add_magic_quotes( $_POST   );
 652      $_COOKIE = add_magic_quotes( $_COOKIE );
 653      $_SERVER = add_magic_quotes( $_SERVER );
 654  
 655      // Force REQUEST to be GET + POST.
 656      $_REQUEST = array_merge( $_GET, $_POST );
 657  }
 658  
 659  /**
 660   * Runs just before PHP shuts down execution.
 661   *
 662   * @since 1.2.0
 663   * @access private
 664   */
 665  function shutdown_action_hook() {
 666      /**
 667       * Fires just before PHP shuts down execution.
 668       *
 669       * @since 1.2.0
 670       */
 671      do_action( 'shutdown' );
 672  
 673      wp_cache_close();
 674  }
 675  
 676  /**
 677   * Copy an object.
 678   *
 679   * @since 2.7.0
 680   * @deprecated 3.2.0
 681   *
 682   * @param object $object The object to clone.
 683   * @return object The cloned object.
 684   */
 685  function wp_clone( $object ) {
 686      // Use parens for clone to accommodate PHP 4. See #17880
 687      return clone( $object );
 688  }
 689  
 690  /**
 691   * Whether the current request is for an administrative interface page.
 692   *
 693   * Does not check if the user is an administrator; current_user_can()
 694   * for checking roles and capabilities.
 695   *
 696   * @since 1.5.1
 697   *
 698   * @global WP_Screen $current_screen
 699   *
 700   * @return bool True if inside WordPress administration interface, false otherwise.
 701   */
 702  function is_admin() {
 703      if ( isset( $GLOBALS['current_screen'] ) )
 704          return $GLOBALS['current_screen']->in_admin();
 705      elseif ( defined( 'WP_ADMIN' ) )
 706          return WP_ADMIN;
 707  
 708      return false;
 709  }
 710  
 711  /**
 712   * Whether the current request is for a site's admininstrative interface.
 713   *
 714   * e.g. `/wp-admin/`
 715   *
 716   * Does not check if the user is an administrator; current_user_can()
 717   * for checking roles and capabilities.
 718   *
 719   * @since 3.1.0
 720   *
 721   * @global WP_Screen $current_screen
 722   *
 723   * @return bool True if inside WordPress blog administration pages.
 724   */
 725  function is_blog_admin() {
 726      if ( isset( $GLOBALS['current_screen'] ) )
 727          return $GLOBALS['current_screen']->in_admin( 'site' );
 728      elseif ( defined( 'WP_BLOG_ADMIN' ) )
 729          return WP_BLOG_ADMIN;
 730  
 731      return false;
 732  }
 733  
 734  /**
 735   * Whether the current request is for the network administrative interface.
 736   *
 737   * e.g. `/wp-admin/network/`
 738   *
 739   * Does not check if the user is an administrator; current_user_can()
 740   * for checking roles and capabilities.
 741   *
 742   * @since 3.1.0
 743   *
 744   * @global WP_Screen $current_screen
 745   *
 746   * @return bool True if inside WordPress network administration pages.
 747   */
 748  function is_network_admin() {
 749      if ( isset( $GLOBALS['current_screen'] ) )
 750          return $GLOBALS['current_screen']->in_admin( 'network' );
 751      elseif ( defined( 'WP_NETWORK_ADMIN' ) )
 752          return WP_NETWORK_ADMIN;
 753  
 754      return false;
 755  }
 756  
 757  /**
 758   * Whether the current request is for a user admin screen.
 759   *
 760   * e.g. `/wp-admin/user/`
 761   *
 762   * Does not inform on whether the user is an admin! Use capability
 763   * checks to tell if the user should be accessing a section or not
 764   * current_user_can().
 765   *
 766   * @since 3.1.0
 767   *
 768   * @global WP_Screen $current_screen
 769   *
 770   * @return bool True if inside WordPress user administration pages.
 771   */
 772  function is_user_admin() {
 773      if ( isset( $GLOBALS['current_screen'] ) )
 774          return $GLOBALS['current_screen']->in_admin( 'user' );
 775      elseif ( defined( 'WP_USER_ADMIN' ) )
 776          return WP_USER_ADMIN;
 777  
 778      return false;
 779  }
 780  
 781  /**
 782   * If Multisite is enabled.
 783   *
 784   * @since 3.0.0
 785   *
 786   * @return bool True if Multisite is enabled, false otherwise.
 787   */
 788  function is_multisite() {
 789      if ( defined( 'MULTISITE' ) )
 790          return MULTISITE;
 791  
 792      if ( defined( 'SUBDOMAIN_INSTALL' ) || defined( 'VHOST' ) || defined( 'SUNRISE' ) )
 793          return true;
 794  
 795      return false;
 796  }
 797  
 798  /**
 799   * Retrieve the current site ID.
 800   *
 801   * @since 3.1.0
 802   *
 803   * @global int $blog_id
 804   *
 805   * @return int Site ID.
 806   */
 807  function get_current_blog_id() {
 808      global $blog_id;
 809      return absint($blog_id);
 810  }
 811  
 812  /**
 813   * Retrieves the current network ID.
 814   *
 815   * @since 4.6.0
 816   *
 817   * @global WP_Network $current_site The current network.
 818   *
 819   * @return int The ID of the current network.
 820   */
 821  function get_current_network_id() {
 822      if ( ! is_multisite() ) {
 823          return 1;
 824      }
 825  
 826      $current_site = get_current_site();
 827  
 828      if ( ! isset( $current_site->id ) ) {
 829          return get_main_network_id();
 830      }
 831  
 832      return absint( $current_site->id );
 833  }
 834  
 835  /**
 836   * Attempt an early load of translations.
 837   *
 838   * Used for errors encountered during the initial loading process, before
 839   * the locale has been properly detected and loaded.
 840   *
 841   * Designed for unusual load sequences (like setup-config.php) or for when
 842   * the script will then terminate with an error, otherwise there is a risk
 843   * that a file can be double-included.
 844   *
 845   * @since 3.4.0
 846   * @access private
 847   *
 848   * @global string    $text_direction
 849   * @global WP_Locale $wp_locale      The WordPress date and time locale object.
 850   *
 851   * @staticvar bool $loaded
 852   */
 853  function wp_load_translations_early() {
 854      global $text_direction, $wp_locale;
 855  
 856      static $loaded = false;
 857      if ( $loaded )
 858          return;
 859      $loaded = true;
 860  
 861      if ( function_exists( 'did_action' ) && did_action( 'init' ) )
 862          return;
 863  
 864      // We need $wp_local_package
 865      require  ABSPATH . WPINC . '/version.php';
 866  
 867      // Translation and localization
 868      require_once  ABSPATH . WPINC . '/pomo/mo.php';
 869      require_once  ABSPATH . WPINC . '/l10n.php';
 870      require_once  ABSPATH . WPINC . '/locale.php';
 871  
 872      // General libraries
 873      require_once  ABSPATH . WPINC . '/plugin.php';
 874  
 875      $locales = $locations = array();
 876  
 877      while ( true ) {
 878          if ( defined( 'WPLANG' ) ) {
 879              if ( '' == WPLANG )
 880                  break;
 881              $locales[] = WPLANG;
 882          }
 883  
 884          if ( isset( $wp_local_package ) )
 885              $locales[] = $wp_local_package;
 886  
 887          if ( ! $locales )
 888              break;
 889  
 890          if ( defined( 'WP_LANG_DIR' ) && @is_dir( WP_LANG_DIR ) )
 891              $locations[] = WP_LANG_DIR;
 892  
 893          if ( defined( 'WP_CONTENT_DIR' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) )
 894              $locations[] = WP_CONTENT_DIR . '/languages';
 895  
 896          if ( @is_dir( ABSPATH . 'wp-content/languages' ) )
 897              $locations[] = ABSPATH . 'wp-content/languages';
 898  
 899          if ( @is_dir( ABSPATH . WPINC . '/languages' ) )
 900              $locations[] = ABSPATH . WPINC . '/languages';
 901  
 902          if ( ! $locations )
 903              break;
 904  
 905          $locations = array_unique( $locations );
 906  
 907          foreach ( $locales as $locale ) {
 908              foreach ( $locations as $location ) {
 909                  if ( file_exists( $location . '/' . $locale . '.mo' ) ) {
 910                      load_textdomain( 'default', $location . '/' . $locale . '.mo' );
 911                      if ( defined( 'WP_SETUP_CONFIG' ) && file_exists( $location . '/admin-' . $locale . '.mo' ) )
 912                          load_textdomain( 'default', $location . '/admin-' . $locale . '.mo' );
 913                      break 2;
 914                  }
 915              }
 916          }
 917  
 918          break;
 919      }
 920  
 921      $wp_locale = new WP_Locale();
 922  }
 923  
 924  /**
 925   * Check or set whether WordPress is in "installation" mode.
 926   *
 927   * If the `WP_INSTALLING` constant is defined during the bootstrap, `wp_installing()` will default to `true`.
 928   *
 929   * @since 4.4.0
 930   *
 931   * @staticvar bool $installing
 932   *
 933   * @param bool $is_installing Optional. True to set WP into Installing mode, false to turn Installing mode off.
 934   *                            Omit this parameter if you only want to fetch the current status.
 935   * @return bool True if WP is installing, otherwise false. When a `$is_installing` is passed, the function will
 936   *              report whether WP was in installing mode prior to the change to `$is_installing`.
 937   */
 938  function wp_installing( $is_installing = null ) {
 939      static $installing = null;
 940  
 941      // Support for the `WP_INSTALLING` constant, defined before WP is loaded.
 942      if ( is_null( $installing ) ) {
 943          $installing = defined( 'WP_INSTALLING' ) && WP_INSTALLING;
 944      }
 945  
 946      if ( ! is_null( $is_installing ) ) {
 947          $old_installing = $installing;
 948          $installing = $is_installing;
 949          return (bool) $old_installing;
 950      }
 951  
 952      return (bool) $installing;
 953  }
 954  
 955  /**
 956   * Determines if SSL is used.
 957   *
 958   * @since 2.6.0
 959   * @since 4.6.0 Moved from functions.php to load.php.
 960   *
 961   * @return bool True if SSL, otherwise false.
 962   */
 963  function is_ssl() {
 964      if ( isset( $_SERVER['HTTPS'] ) ) {
 965          if ( 'on' == strtolower( $_SERVER['HTTPS'] ) ) {
 966              return true;
 967          }
 968  
 969          if ( '1' == $_SERVER['HTTPS'] ) {
 970              return true;
 971          }
 972      } elseif ( isset($_SERVER['SERVER_PORT'] ) && ( '443' == $_SERVER['SERVER_PORT'] ) ) {
 973          return true;
 974      }
 975      return false;
 976  }
 977  
 978  /**
 979   * Converts a shorthand byte value to an integer byte value.
 980   *
 981   * @since 2.3.0
 982   * @since 4.6.0 Moved from media.php to load.php.
 983   *
 984   * @link http://php.net/manual/en/function.ini-get.php
 985   * @link http://php.net/manual/en/faq.using.php#faq.using.shorthandbytes
 986   *
 987   * @param string $value A (PHP ini) byte value, either shorthand or ordinary.
 988   * @return int An integer byte value.
 989   */
 990  function wp_convert_hr_to_bytes( $value ) {
 991      $value = strtolower( trim( $value ) );
 992      $bytes = (int) $value;
 993  
 994      if ( false !== strpos( $value, 'g' ) ) {
 995          $bytes *= GB_IN_BYTES;
 996      } elseif ( false !== strpos( $value, 'm' ) ) {
 997          $bytes *= MB_IN_BYTES;
 998      } elseif ( false !== strpos( $value, 'k' ) ) {
 999          $bytes *= KB_IN_BYTES;
1000      }
1001  
1002      // Deal with large (float) values which run into the maximum integer size.
1003      return min( $bytes, PHP_INT_MAX );
1004  }
1005  
1006  /**
1007   * Determines whether a PHP ini value is changeable at runtime.
1008   *
1009   * @since 4.6.0
1010   *
1011   * @link http://php.net/manual/en/function.ini-get-all.php
1012   *
1013   * @param string $setting The name of the ini setting to check.
1014   * @return bool True if the value is changeable at runtime. False otherwise.
1015   */
1016  function wp_is_ini_value_changeable( $setting ) {
1017      static $ini_all;
1018  
1019      if ( ! isset( $ini_all ) ) {
1020          $ini_all = false;
1021          // Sometimes `ini_get_all()` is disabled via the `disable_functions` option for "security purposes".
1022          if ( function_exists( 'ini_get_all' ) ) {
1023              $ini_all = ini_get_all();
1024          }
1025       }
1026  
1027      // 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.
1028      if ( isset( $ini_all[ $setting ]['access'] ) && ( INI_ALL === ( $ini_all[ $setting ]['access'] & 7 ) || INI_USER === ( $ini_all[ $setting ]['access'] & 7 ) ) ) {
1029          return true;
1030      }
1031  
1032      // If we were unable to retrieve the details, fail gracefully to assume it's changeable.
1033      if ( ! is_array( $ini_all ) ) {
1034          return true;
1035      }
1036  
1037      return false;
1038  }

title

Description

title

Description

title

Description

title

title

Body