[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/ -> wp-settings.php (source)

   1  <?php
   2  /**
   3   * Used to set up and fix common variables and include
   4   * the WordPress procedural and class library.
   5   *
   6   * Allows for some configuration in wp-config.php (see default-constants.php)
   7   *
   8   * @package WordPress
   9   */
  10  
  11  /**
  12   * Stores the location of the WordPress directory of functions, classes, and core content.
  13   *
  14   * @since 1.0.0
  15   */
  16  define( 'WPINC', 'wp-includes' );
  17  
  18  // Include files required for initialization.
  19  require( ABSPATH . WPINC . '/load.php' );
  20  require( ABSPATH . WPINC . '/default-constants.php' );
  21  require_once( ABSPATH . WPINC . '/plugin.php' );
  22  
  23  /*
  24   * These can't be directly globalized in version.php. When updating,
  25   * we're including version.php from another installation and don't want
  26   * these values to be overridden if already set.
  27   */
  28  global $wp_version, $wp_db_version, $tinymce_version, $required_php_version, $required_mysql_version, $wp_local_package;
  29  require ( ABSPATH . WPINC . '/version.php' );
  30  
  31  /**
  32   * If not already configured, `$blog_id` will default to 1 in a single site
  33   * configuration. In multisite, it will be overridden by default in ms-settings.php.
  34   *
  35   * @global int $blog_id
  36   * @since 2.0.0
  37   */
  38  global $blog_id;
  39  
  40  // Set initial default constants including WP_MEMORY_LIMIT, WP_MAX_MEMORY_LIMIT, WP_DEBUG, SCRIPT_DEBUG, WP_CONTENT_DIR and WP_CACHE.
  41  wp_initial_constants();
  42  
  43  // Check for the required PHP version and for the MySQL extension or a database drop-in.
  44  wp_check_php_mysql_versions();
  45  
  46  // Disable magic quotes at runtime. Magic quotes are added using wpdb later in wp-settings.php.
  47  @ini_set( 'magic_quotes_runtime', 0 );
  48  @ini_set( 'magic_quotes_sybase', 0 );
  49  
  50  // WordPress calculates offsets from UTC.
  51  date_default_timezone_set( 'UTC' );
  52  
  53  // Turn register_globals off.
  54  wp_unregister_GLOBALS();
  55  
  56  // Standardize $_SERVER variables across setups.
  57  wp_fix_server_vars();
  58  
  59  // Check if we have received a request due to missing favicon.ico
  60  wp_favicon_request();
  61  
  62  // Check if we're in maintenance mode.
  63  wp_maintenance();
  64  
  65  // Start loading timer.
  66  timer_start();
  67  
  68  // Check if we're in WP_DEBUG mode.
  69  wp_debug_mode();
  70  
  71  /**
  72   * Filters whether to enable loading of the advanced-cache.php drop-in.
  73   *
  74   * This filter runs before it can be used by plugins. It is designed for non-web
  75   * run-times. If false is returned, advanced-cache.php will never be loaded.
  76   *
  77   * @since 4.6.0
  78   *
  79   * @param bool $enable_advanced_cache Whether to enable loading advanced-cache.php (if present).
  80   *                                    Default true.
  81   */
  82  if ( WP_CACHE && apply_filters( 'enable_loading_advanced_cache_dropin', true ) ) {
  83      // For an advanced caching plugin to use. Uses a static drop-in because you would only want one.
  84      WP_DEBUG ? include( WP_CONTENT_DIR . '/advanced-cache.php' ) : @include( WP_CONTENT_DIR . '/advanced-cache.php' );
  85  
  86      // Re-initialize any hooks added manually by advanced-cache.php
  87      if ( $wp_filter ) {
  88          $wp_filter = WP_Hook::build_preinitialized_hooks( $wp_filter );
  89      }
  90  }
  91  
  92  // Define WP_LANG_DIR if not set.
  93  wp_set_lang_dir();
  94  
  95  // Load early WordPress files.
  96  require( ABSPATH . WPINC . '/compat.php' );
  97  require( ABSPATH . WPINC . '/class-wp-list-util.php' );
  98  require( ABSPATH . WPINC . '/formatting.php' );
  99  require( ABSPATH . WPINC . '/meta.php' );
 100  require( ABSPATH . WPINC . '/functions.php' );
 101  require( ABSPATH . WPINC . '/class-wp-meta-query.php' );
 102  require( ABSPATH . WPINC . '/class-wp-matchesmapregex.php' );
 103  require( ABSPATH . WPINC . '/class-wp.php' );
 104  require( ABSPATH . WPINC . '/class-wp-error.php' );
 105  require( ABSPATH . WPINC . '/pomo/mo.php' );
 106  
 107  // Include the wpdb class and, if present, a db.php database drop-in.
 108  global $wpdb;
 109  require_wp_db();
 110  
 111  // Set the database table prefix and the format specifiers for database table columns.
 112  $GLOBALS['table_prefix'] = $table_prefix;
 113  wp_set_wpdb_vars();
 114  
 115  // Start the WordPress object cache, or an external object cache if the drop-in is present.
 116  wp_start_object_cache();
 117  
 118  // Attach the default filters.
 119  require( ABSPATH . WPINC . '/default-filters.php' );
 120  
 121  // Initialize multisite if enabled.
 122  if ( is_multisite() ) {
 123      require( ABSPATH . WPINC . '/class-wp-site-query.php' );
 124      require( ABSPATH . WPINC . '/class-wp-network-query.php' );
 125      require( ABSPATH . WPINC . '/ms-blogs.php' );
 126      require( ABSPATH . WPINC . '/ms-settings.php' );
 127  } elseif ( ! defined( 'MULTISITE' ) ) {
 128      define( 'MULTISITE', false );
 129  }
 130  
 131  register_shutdown_function( 'shutdown_action_hook' );
 132  
 133  // Stop most of WordPress from being loaded if we just want the basics.
 134  if ( SHORTINIT ) {
 135      return false;
 136  }
 137  
 138  // Load the L10n library.
 139  require_once( ABSPATH . WPINC . '/l10n.php' );
 140  require_once( ABSPATH . WPINC . '/class-wp-locale.php' );
 141  require_once( ABSPATH . WPINC . '/class-wp-locale-switcher.php' );
 142  
 143  // Run the installer if WordPress is not installed.
 144  wp_not_installed();
 145  
 146  // Load most of WordPress.
 147  require( ABSPATH . WPINC . '/class-wp-walker.php' );
 148  require( ABSPATH . WPINC . '/class-wp-ajax-response.php' );
 149  require( ABSPATH . WPINC . '/capabilities.php' );
 150  require( ABSPATH . WPINC . '/class-wp-roles.php' );
 151  require( ABSPATH . WPINC . '/class-wp-role.php' );
 152  require( ABSPATH . WPINC . '/class-wp-user.php' );
 153  require( ABSPATH . WPINC . '/class-wp-query.php' );
 154  require( ABSPATH . WPINC . '/query.php' );
 155  require( ABSPATH . WPINC . '/date.php' );
 156  require( ABSPATH . WPINC . '/theme.php' );
 157  require( ABSPATH . WPINC . '/class-wp-theme.php' );
 158  require( ABSPATH . WPINC . '/template.php' );
 159  require( ABSPATH . WPINC . '/user.php' );
 160  require( ABSPATH . WPINC . '/class-wp-user-query.php' );
 161  require ( ABSPATH . WPINC . '/class-wp-session-tokens.php' );
 162  require ( ABSPATH . WPINC . '/class-wp-user-meta-session-tokens.php' );
 163  require( ABSPATH . WPINC . '/class-wp-metadata-lazyloader.php' );
 164  require( ABSPATH . WPINC . '/general-template.php' );
 165  require( ABSPATH . WPINC . '/link-template.php' );
 166  require( ABSPATH . WPINC . '/author-template.php' );
 167  require( ABSPATH . WPINC . '/post.php' );
 168  require( ABSPATH . WPINC . '/class-walker-page.php' );
 169  require( ABSPATH . WPINC . '/class-walker-page-dropdown.php' );
 170  require( ABSPATH . WPINC . '/class-wp-post-type.php' );
 171  require( ABSPATH . WPINC . '/class-wp-post.php' );
 172  require( ABSPATH . WPINC . '/post-template.php' );
 173  require( ABSPATH . WPINC . '/revision.php' );
 174  require( ABSPATH . WPINC . '/post-formats.php' );
 175  require( ABSPATH . WPINC . '/post-thumbnail-template.php' );
 176  require( ABSPATH . WPINC . '/category.php' );
 177  require( ABSPATH . WPINC . '/class-walker-category.php' );
 178  require( ABSPATH . WPINC . '/class-walker-category-dropdown.php' );
 179  require( ABSPATH . WPINC . '/category-template.php' );
 180  require( ABSPATH . WPINC . '/comment.php' );
 181  require( ABSPATH . WPINC . '/class-wp-comment.php' );
 182  require( ABSPATH . WPINC . '/class-wp-comment-query.php' );
 183  require( ABSPATH . WPINC . '/class-walker-comment.php' );
 184  require( ABSPATH . WPINC . '/comment-template.php' );
 185  require( ABSPATH . WPINC . '/rewrite.php' );
 186  require( ABSPATH . WPINC . '/class-wp-rewrite.php' );
 187  require( ABSPATH . WPINC . '/feed.php' );
 188  require( ABSPATH . WPINC . '/bookmark.php' );
 189  require( ABSPATH . WPINC . '/bookmark-template.php' );
 190  require ( ABSPATH . WPINC . '/kses.php' );
 191  require( ABSPATH . WPINC . '/cron.php' );
 192  require( ABSPATH . WPINC . '/deprecated.php' );
 193  require( ABSPATH . WPINC . '/script-loader.php' );
 194  require( ABSPATH . WPINC . '/taxonomy.php' );
 195  require( ABSPATH . WPINC . '/class-wp-taxonomy.php' );
 196  require( ABSPATH . WPINC . '/class-wp-term.php' );
 197  require( ABSPATH . WPINC . '/class-wp-term-query.php' );
 198  require( ABSPATH . WPINC . '/class-wp-tax-query.php' );
 199  require( ABSPATH . WPINC . '/update.php' );
 200  require( ABSPATH . WPINC . '/canonical.php' );
 201  require( ABSPATH . WPINC . '/shortcodes.php' );
 202  require( ABSPATH . WPINC . '/embed.php' );
 203  require( ABSPATH . WPINC . '/class-wp-embed.php' );
 204  require( ABSPATH . WPINC . '/class-oembed.php' );
 205  require( ABSPATH . WPINC . '/class-wp-oembed-controller.php' );
 206  require( ABSPATH . WPINC . '/media.php' );
 207  require( ABSPATH . WPINC . '/http.php' );
 208  require( ABSPATH . WPINC . '/class-http.php' );
 209  require( ABSPATH . WPINC . '/class-wp-http-streams.php' );
 210  require( ABSPATH . WPINC . '/class-wp-http-curl.php' );
 211  require( ABSPATH . WPINC . '/class-wp-http-proxy.php' );
 212  require( ABSPATH . WPINC . '/class-wp-http-cookie.php' );
 213  require( ABSPATH . WPINC . '/class-wp-http-encoding.php' );
 214  require( ABSPATH . WPINC . '/class-wp-http-response.php' );
 215  require( ABSPATH . WPINC . '/class-wp-http-requests-response.php' );
 216  require( ABSPATH . WPINC . '/class-wp-http-requests-hooks.php' );
 217  require( ABSPATH . WPINC . '/widgets.php' );
 218  require( ABSPATH . WPINC . '/class-wp-widget.php' );
 219  require( ABSPATH . WPINC . '/class-wp-widget-factory.php' );
 220  require( ABSPATH . WPINC . '/nav-menu.php' );
 221  require( ABSPATH . WPINC . '/nav-menu-template.php' );
 222  require( ABSPATH . WPINC . '/admin-bar.php' );
 223  require( ABSPATH . WPINC . '/rest-api.php' );
 224  require( ABSPATH . WPINC . '/rest-api/class-wp-rest-server.php' );
 225  require( ABSPATH . WPINC . '/rest-api/class-wp-rest-response.php' );
 226  require( ABSPATH . WPINC . '/rest-api/class-wp-rest-request.php' );
 227  require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-controller.php' );
 228  require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-posts-controller.php' );
 229  require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-attachments-controller.php' );
 230  require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-post-types-controller.php' );
 231  require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-post-statuses-controller.php' );
 232  require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-revisions-controller.php' );
 233  require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-autosaves-controller.php' );
 234  require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-taxonomies-controller.php' );
 235  require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-terms-controller.php' );
 236  require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-users-controller.php' );
 237  require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-comments-controller.php' );
 238  require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-search-controller.php' );
 239  require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-blocks-controller.php' );
 240  require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-block-renderer-controller.php' );
 241  require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-settings-controller.php' );
 242  require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-themes-controller.php' );
 243  require( ABSPATH . WPINC . '/rest-api/fields/class-wp-rest-meta-fields.php' );
 244  require( ABSPATH . WPINC . '/rest-api/fields/class-wp-rest-comment-meta-fields.php' );
 245  require( ABSPATH . WPINC . '/rest-api/fields/class-wp-rest-post-meta-fields.php' );
 246  require( ABSPATH . WPINC . '/rest-api/fields/class-wp-rest-term-meta-fields.php' );
 247  require( ABSPATH . WPINC . '/rest-api/fields/class-wp-rest-user-meta-fields.php' );
 248  require( ABSPATH . WPINC . '/rest-api/search/class-wp-rest-search-handler.php' );
 249  require( ABSPATH . WPINC . '/rest-api/search/class-wp-rest-post-search-handler.php' );
 250  require( ABSPATH . WPINC . '/class-wp-block-type.php' );
 251  require( ABSPATH . WPINC . '/class-wp-block-type-registry.php' );
 252  require( ABSPATH . WPINC . '/class-wp-block-parser.php' );
 253  require( ABSPATH . WPINC . '/blocks.php' );
 254  require( ABSPATH . WPINC . '/blocks/archives.php' );
 255  require( ABSPATH . WPINC . '/blocks/block.php' );
 256  require( ABSPATH . WPINC . '/blocks/categories.php' );
 257  require( ABSPATH . WPINC . '/blocks/latest-comments.php' );
 258  require( ABSPATH . WPINC . '/blocks/latest-posts.php' );
 259  require( ABSPATH . WPINC . '/blocks/shortcode.php' );
 260  
 261  $GLOBALS['wp_embed'] = new WP_Embed();
 262  
 263  // Load multisite-specific files.
 264  if ( is_multisite() ) {
 265      require( ABSPATH . WPINC . '/ms-functions.php' );
 266      require( ABSPATH . WPINC . '/ms-default-filters.php' );
 267      require( ABSPATH . WPINC . '/ms-deprecated.php' );
 268  }
 269  
 270  // Define constants that rely on the API to obtain the default value.
 271  // Define must-use plugin directory constants, which may be overridden in the sunrise.php drop-in.
 272  wp_plugin_directory_constants();
 273  
 274  $GLOBALS['wp_plugin_paths'] = array();
 275  
 276  // Load must-use plugins.
 277  foreach ( wp_get_mu_plugins() as $mu_plugin ) {
 278      include_once( $mu_plugin );
 279  
 280      /**
 281       * Fires once a single must-use plugin has loaded.
 282       *
 283       * @since 5.1.0
 284       *
 285       * @param string $mu_plugin Full path to the plugin's main file.
 286       */
 287      do_action( 'mu_plugin_loaded', $mu_plugin );
 288  }
 289  unset( $mu_plugin );
 290  
 291  // Load network activated plugins.
 292  if ( is_multisite() ) {
 293      foreach ( wp_get_active_network_plugins() as $network_plugin ) {
 294          wp_register_plugin_realpath( $network_plugin );
 295          include_once( $network_plugin );
 296  
 297          /**
 298           * Fires once a single network-activated plugin has loaded.
 299           *
 300           * @since 5.1.0
 301           *
 302           * @param string $network_plugin Full path to the plugin's main file.
 303           */
 304          do_action( 'network_plugin_loaded', $network_plugin );
 305      }
 306      unset( $network_plugin );
 307  }
 308  
 309  /**
 310   * Fires once all must-use and network-activated plugins have loaded.
 311   *
 312   * @since 2.8.0
 313   */
 314  do_action( 'muplugins_loaded' );
 315  
 316  if ( is_multisite() ) {
 317      ms_cookie_constants();
 318  }
 319  
 320  // Define constants after multisite is loaded.
 321  wp_cookie_constants();
 322  
 323  // Define and enforce our SSL constants
 324  wp_ssl_constants();
 325  
 326  // Create common globals.
 327  require( ABSPATH . WPINC . '/vars.php' );
 328  
 329  // Make taxonomies and posts available to plugins and themes.
 330  // @plugin authors: warning: these get registered again on the init hook.
 331  create_initial_taxonomies();
 332  create_initial_post_types();
 333  
 334  wp_start_scraping_edited_file_errors();
 335  
 336  // Register the default theme directory root
 337  register_theme_directory( get_theme_root() );
 338  
 339  // Load active plugins.
 340  foreach ( wp_get_active_and_valid_plugins() as $plugin ) {
 341      wp_register_plugin_realpath( $plugin );
 342      include_once( $plugin );
 343  
 344      /**
 345       * Fires once a single activated plugin has loaded.
 346       *
 347       * @since 5.1.0
 348       *
 349       * @param string $plugin Full path to the plugin's main file.
 350       */
 351      do_action( 'plugin_loaded', $plugin );
 352  }
 353  unset( $plugin );
 354  
 355  // Load pluggable functions.
 356  require ( ABSPATH . WPINC . '/pluggable.php' );
 357  require( ABSPATH . WPINC . '/pluggable-deprecated.php' );
 358  
 359  // Set internal encoding.
 360  wp_set_internal_encoding();
 361  
 362  // Run wp_cache_postload() if object cache is enabled and the function exists.
 363  if ( WP_CACHE && function_exists( 'wp_cache_postload' ) ) {
 364      wp_cache_postload();
 365  }
 366  
 367  /**
 368   * Fires once activated plugins have loaded.
 369   *
 370   * Pluggable functions are also available at this point in the loading order.
 371   *
 372   * @since 1.5.0
 373   */
 374  do_action( 'plugins_loaded' );
 375  
 376  // Define constants which affect functionality if not already defined.
 377  wp_functionality_constants();
 378  
 379  // Add magic quotes and set up $_REQUEST ( $_GET + $_POST )
 380  wp_magic_quotes();
 381  
 382  /**
 383   * Fires when comment cookies are sanitized.
 384   *
 385   * @since 2.0.11
 386   */
 387  do_action( 'sanitize_comment_cookies' );
 388  
 389  /**
 390   * WordPress Query object
 391   *
 392   * @global WP_Query $wp_the_query
 393   * @since 2.0.0
 394   */
 395  $GLOBALS['wp_the_query'] = new WP_Query();
 396  
 397  /**
 398   * Holds the reference to @see $wp_the_query
 399   * Use this global for WordPress queries
 400   *
 401   * @global WP_Query $wp_query
 402   * @since 1.5.0
 403   */
 404  $GLOBALS['wp_query'] = $GLOBALS['wp_the_query'];
 405  
 406  /**
 407   * Holds the WordPress Rewrite object for creating pretty URLs
 408   *
 409   * @global WP_Rewrite $wp_rewrite
 410   * @since 1.5.0
 411   */
 412  $GLOBALS['wp_rewrite'] = new WP_Rewrite();
 413  
 414  /**
 415   * WordPress Object
 416   *
 417   * @global WP $wp
 418   * @since 2.0.0
 419   */
 420  $GLOBALS['wp'] = new WP();
 421  
 422  /**
 423   * WordPress Widget Factory Object
 424   *
 425   * @global WP_Widget_Factory $wp_widget_factory
 426   * @since 2.8.0
 427   */
 428  $GLOBALS['wp_widget_factory'] = new WP_Widget_Factory();
 429  
 430  /**
 431   * WordPress User Roles
 432   *
 433   * @global WP_Roles $wp_roles
 434   * @since 2.0.0
 435   */
 436  $GLOBALS['wp_roles'] = new WP_Roles();
 437  
 438  /**
 439   * Fires before the theme is loaded.
 440   *
 441   * @since 2.6.0
 442   */
 443  do_action( 'setup_theme' );
 444  
 445  // Define the template related constants.
 446  wp_templating_constants();
 447  
 448  // Load the default text localization domain.
 449  load_default_textdomain();
 450  
 451  $locale      = get_locale();
 452  $locale_file = WP_LANG_DIR . "/$locale.php";
 453  if ( ( 0 === validate_file( $locale ) ) && is_readable( $locale_file ) ) {
 454      require( $locale_file );
 455  }
 456  unset( $locale_file );
 457  
 458  /**
 459   * WordPress Locale object for loading locale domain date and various strings.
 460   *
 461   * @global WP_Locale $wp_locale
 462   * @since 2.1.0
 463   */
 464  $GLOBALS['wp_locale'] = new WP_Locale();
 465  
 466  /**
 467   *  WordPress Locale Switcher object for switching locales.
 468   *
 469   * @since 4.7.0
 470   *
 471   * @global WP_Locale_Switcher $wp_locale_switcher WordPress locale switcher object.
 472   */
 473  $GLOBALS['wp_locale_switcher'] = new WP_Locale_Switcher();
 474  $GLOBALS['wp_locale_switcher']->init();
 475  
 476  // Load the functions for the active theme, for both parent and child theme if applicable.
 477  foreach ( wp_get_active_and_valid_themes() as $theme ) {
 478      if ( file_exists( $theme . '/functions.php' ) ) {
 479          include $theme . '/functions.php';
 480      }
 481  }
 482  unset( $theme );
 483  
 484  /**
 485   * Fires after the theme is loaded.
 486   *
 487   * @since 3.0.0
 488   */
 489  do_action( 'after_setup_theme' );
 490  
 491  // Set up current user.
 492  $GLOBALS['wp']->init();
 493  
 494  /**
 495   * Fires after WordPress has finished loading but before any headers are sent.
 496   *
 497   * Most of WP is loaded at this stage, and the user is authenticated. WP continues
 498   * to load on the {@see 'init'} hook that follows (e.g. widgets), and many plugins instantiate
 499   * themselves on it for all sorts of reasons (e.g. they need a user, a taxonomy, etc.).
 500   *
 501   * If you wish to plug an action once WP is loaded, use the {@see 'wp_loaded'} hook below.
 502   *
 503   * @since 1.5.0
 504   */
 505  do_action( 'init' );
 506  
 507  // Check site status
 508  if ( is_multisite() ) {
 509      if ( true !== ( $file = ms_site_check() ) ) {
 510          require( $file );
 511          die();
 512      }
 513      unset( $file );
 514  }
 515  
 516  /**
 517   * This hook is fired once WP, all plugins, and the theme are fully loaded and instantiated.
 518   *
 519   * Ajax requests should use wp-admin/admin-ajax.php. admin-ajax.php can handle requests for
 520   * users not logged in.
 521   *
 522   * @link https://codex.wordpress.org/AJAX_in_Plugins
 523   *
 524   * @since 3.0.0
 525   */
 526  do_action( 'wp_loaded' );


Generated: Tue Feb 19 01:00:05 2019 Cross-referenced by PHPXref 0.7.1