wp-settings.php 16 KB

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