You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

471 lines
16 KiB

  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. require( ABSPATH . WPINC . '/class-phpass.php' );
  86. // Include the wpdb class and, if present, a db.php database drop-in.
  87. global $wpdb;
  88. require_wp_db();
  89. // Set the database table prefix and the format specifiers for database table columns.
  90. $GLOBALS['table_prefix'] = $table_prefix;
  91. wp_set_wpdb_vars();
  92. // Start the WordPress object cache, or an external object cache if the drop-in is present.
  93. wp_start_object_cache();
  94. // Attach the default filters.
  95. require( ABSPATH . WPINC . '/default-filters.php' );
  96. // Initialize multisite if enabled.
  97. if ( is_multisite() ) {
  98. require( ABSPATH . WPINC . '/class-wp-site-query.php' );
  99. require( ABSPATH . WPINC . '/class-wp-network-query.php' );
  100. require( ABSPATH . WPINC . '/ms-blogs.php' );
  101. require( ABSPATH . WPINC . '/ms-settings.php' );
  102. } elseif ( ! defined( 'MULTISITE' ) ) {
  103. define( 'MULTISITE', false );
  104. }
  105. register_shutdown_function( 'shutdown_action_hook' );
  106. // Stop most of WordPress from being loaded if we just want the basics.
  107. if ( SHORTINIT )
  108. return false;
  109. // Load the L10n library.
  110. require_once( ABSPATH . WPINC . '/l10n.php' );
  111. require_once( ABSPATH . WPINC . '/class-wp-locale.php' );
  112. require_once( ABSPATH . WPINC . '/class-wp-locale-switcher.php' );
  113. // Run the installer if WordPress is not installed.
  114. wp_not_installed();
  115. // Load most of WordPress.
  116. require( ABSPATH . WPINC . '/class-wp-walker.php' );
  117. require( ABSPATH . WPINC . '/class-wp-ajax-response.php' );
  118. require( ABSPATH . WPINC . '/formatting.php' );
  119. require( ABSPATH . WPINC . '/capabilities.php' );
  120. require( ABSPATH . WPINC . '/class-wp-roles.php' );
  121. require( ABSPATH . WPINC . '/class-wp-role.php' );
  122. require( ABSPATH . WPINC . '/class-wp-user.php' );
  123. require( ABSPATH . WPINC . '/class-wp-query.php' );
  124. require( ABSPATH . WPINC . '/query.php' );
  125. require( ABSPATH . WPINC . '/date.php' );
  126. require( ABSPATH . WPINC . '/theme.php' );
  127. require( ABSPATH . WPINC . '/class-wp-theme.php' );
  128. require( ABSPATH . WPINC . '/template.php' );
  129. require( ABSPATH . WPINC . '/user.php' );
  130. require( ABSPATH . WPINC . '/class-wp-user-query.php' );
  131. require( ABSPATH . WPINC . '/class-wp-session-tokens.php' );
  132. require( ABSPATH . WPINC . '/class-wp-user-meta-session-tokens.php' );
  133. require( ABSPATH . WPINC . '/meta.php' );
  134. require( ABSPATH . WPINC . '/class-wp-meta-query.php' );
  135. require( ABSPATH . WPINC . '/class-wp-metadata-lazyloader.php' );
  136. require( ABSPATH . WPINC . '/general-template.php' );
  137. require( ABSPATH . WPINC . '/link-template.php' );
  138. require( ABSPATH . WPINC . '/author-template.php' );
  139. require( ABSPATH . WPINC . '/post.php' );
  140. require( ABSPATH . WPINC . '/class-walker-page.php' );
  141. require( ABSPATH . WPINC . '/class-walker-page-dropdown.php' );
  142. require( ABSPATH . WPINC . '/class-wp-post-type.php' );
  143. require( ABSPATH . WPINC . '/class-wp-post.php' );
  144. require( ABSPATH . WPINC . '/post-template.php' );
  145. require( ABSPATH . WPINC . '/revision.php' );
  146. require( ABSPATH . WPINC . '/post-formats.php' );
  147. require( ABSPATH . WPINC . '/post-thumbnail-template.php' );
  148. require( ABSPATH . WPINC . '/category.php' );
  149. require( ABSPATH . WPINC . '/class-walker-category.php' );
  150. require( ABSPATH . WPINC . '/class-walker-category-dropdown.php' );
  151. require( ABSPATH . WPINC . '/category-template.php' );
  152. require( ABSPATH . WPINC . '/comment.php' );
  153. require( ABSPATH . WPINC . '/class-wp-comment.php' );
  154. require( ABSPATH . WPINC . '/class-wp-comment-query.php' );
  155. require( ABSPATH . WPINC . '/class-walker-comment.php' );
  156. require( ABSPATH . WPINC . '/comment-template.php' );
  157. require( ABSPATH . WPINC . '/rewrite.php' );
  158. require( ABSPATH . WPINC . '/class-wp-rewrite.php' );
  159. require( ABSPATH . WPINC . '/feed.php' );
  160. require( ABSPATH . WPINC . '/bookmark.php' );
  161. require( ABSPATH . WPINC . '/bookmark-template.php' );
  162. require( ABSPATH . WPINC . '/kses.php' );
  163. require( ABSPATH . WPINC . '/cron.php' );
  164. require( ABSPATH . WPINC . '/deprecated.php' );
  165. require( ABSPATH . WPINC . '/script-loader.php' );
  166. require( ABSPATH . WPINC . '/taxonomy.php' );
  167. require( ABSPATH . WPINC . '/class-wp-taxonomy.php' );
  168. require( ABSPATH . WPINC . '/class-wp-term.php' );
  169. require( ABSPATH . WPINC . '/class-wp-term-query.php' );
  170. require( ABSPATH . WPINC . '/class-wp-tax-query.php' );
  171. require( ABSPATH . WPINC . '/update.php' );
  172. require( ABSPATH . WPINC . '/canonical.php' );
  173. require( ABSPATH . WPINC . '/shortcodes.php' );
  174. require( ABSPATH . WPINC . '/embed.php' );
  175. require( ABSPATH . WPINC . '/class-wp-embed.php' );
  176. require( ABSPATH . WPINC . '/class-oembed.php' );
  177. require( ABSPATH . WPINC . '/class-wp-oembed-controller.php' );
  178. require( ABSPATH . WPINC . '/media.php' );
  179. require( ABSPATH . WPINC . '/http.php' );
  180. require( ABSPATH . WPINC . '/class-http.php' );
  181. require( ABSPATH . WPINC . '/class-wp-http-streams.php' );
  182. require( ABSPATH . WPINC . '/class-wp-http-curl.php' );
  183. require( ABSPATH . WPINC . '/class-wp-http-proxy.php' );
  184. require( ABSPATH . WPINC . '/class-wp-http-cookie.php' );
  185. require( ABSPATH . WPINC . '/class-wp-http-encoding.php' );
  186. require( ABSPATH . WPINC . '/class-wp-http-response.php' );
  187. require( ABSPATH . WPINC . '/class-wp-http-requests-response.php' );
  188. require( ABSPATH . WPINC . '/class-wp-http-requests-hooks.php' );
  189. require( ABSPATH . WPINC . '/widgets.php' );
  190. require( ABSPATH . WPINC . '/class-wp-widget.php' );
  191. require( ABSPATH . WPINC . '/class-wp-widget-factory.php' );
  192. require( ABSPATH . WPINC . '/nav-menu.php' );
  193. require( ABSPATH . WPINC . '/nav-menu-template.php' );
  194. require( ABSPATH . WPINC . '/admin-bar.php' );
  195. require( ABSPATH . WPINC . '/rest-api.php' );
  196. require( ABSPATH . WPINC . '/rest-api/class-wp-rest-server.php' );
  197. require( ABSPATH . WPINC . '/rest-api/class-wp-rest-response.php' );
  198. require( ABSPATH . WPINC . '/rest-api/class-wp-rest-request.php' );
  199. require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-controller.php' );
  200. require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-posts-controller.php' );
  201. require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-attachments-controller.php' );
  202. require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-post-types-controller.php' );
  203. require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-post-statuses-controller.php' );
  204. require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-revisions-controller.php' );
  205. require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-taxonomies-controller.php' );
  206. require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-terms-controller.php' );
  207. require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-users-controller.php' );
  208. require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-comments-controller.php' );
  209. require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-settings-controller.php' );
  210. require( ABSPATH . WPINC . '/rest-api/fields/class-wp-rest-meta-fields.php' );
  211. require( ABSPATH . WPINC . '/rest-api/fields/class-wp-rest-comment-meta-fields.php' );
  212. require( ABSPATH . WPINC . '/rest-api/fields/class-wp-rest-post-meta-fields.php' );
  213. require( ABSPATH . WPINC . '/rest-api/fields/class-wp-rest-term-meta-fields.php' );
  214. require( ABSPATH . WPINC . '/rest-api/fields/class-wp-rest-user-meta-fields.php' );
  215. $GLOBALS['wp_embed'] = new WP_Embed();
  216. // Load multisite-specific files.
  217. if ( is_multisite() ) {
  218. require( ABSPATH . WPINC . '/ms-functions.php' );
  219. require( ABSPATH . WPINC . '/ms-default-filters.php' );
  220. require( ABSPATH . WPINC . '/ms-deprecated.php' );
  221. }
  222. // Define constants that rely on the API to obtain the default value.
  223. // Define must-use plugin directory constants, which may be overridden in the sunrise.php drop-in.
  224. wp_plugin_directory_constants();
  225. $GLOBALS['wp_plugin_paths'] = array();
  226. // Load must-use plugins.
  227. foreach ( wp_get_mu_plugins() as $mu_plugin ) {
  228. include_once( $mu_plugin );
  229. }
  230. unset( $mu_plugin );
  231. // Load network activated plugins.
  232. if ( is_multisite() ) {
  233. foreach ( wp_get_active_network_plugins() as $network_plugin ) {
  234. wp_register_plugin_realpath( $network_plugin );
  235. include_once( $network_plugin );
  236. }
  237. unset( $network_plugin );
  238. }
  239. /**
  240. * Fires once all must-use and network-activated plugins have loaded.
  241. *
  242. * @since 2.8.0
  243. */
  244. do_action( 'muplugins_loaded' );
  245. if ( is_multisite() )
  246. ms_cookie_constants( );
  247. // Define constants after multisite is loaded.
  248. wp_cookie_constants();
  249. // Define and enforce our SSL constants
  250. wp_ssl_constants();
  251. // Create common globals.
  252. require( ABSPATH . WPINC . '/vars.php' );
  253. // Make taxonomies and posts available to plugins and themes.
  254. // @plugin authors: warning: these get registered again on the init hook.
  255. create_initial_taxonomies();
  256. create_initial_post_types();
  257. // Register the default theme directory root
  258. register_theme_directory( get_theme_root() );
  259. // Load active plugins.
  260. foreach ( wp_get_active_and_valid_plugins() as $plugin ) {
  261. wp_register_plugin_realpath( $plugin );
  262. include_once( $plugin );
  263. }
  264. unset( $plugin );
  265. // Load pluggable functions.
  266. require( ABSPATH . WPINC . '/pluggable.php' );
  267. require( ABSPATH . WPINC . '/pluggable-deprecated.php' );
  268. // Set internal encoding.
  269. wp_set_internal_encoding();
  270. // Run wp_cache_postload() if object cache is enabled and the function exists.
  271. if ( WP_CACHE && function_exists( 'wp_cache_postload' ) )
  272. wp_cache_postload();
  273. /**
  274. * Fires once activated plugins have loaded.
  275. *
  276. * Pluggable functions are also available at this point in the loading order.
  277. *
  278. * @since 1.5.0
  279. */
  280. do_action( 'plugins_loaded' );
  281. // Define constants which affect functionality if not already defined.
  282. wp_functionality_constants();
  283. // Add magic quotes and set up $_REQUEST ( $_GET + $_POST )
  284. wp_magic_quotes();
  285. /**
  286. * Fires when comment cookies are sanitized.
  287. *
  288. * @since 2.0.11
  289. */
  290. do_action( 'sanitize_comment_cookies' );
  291. /**
  292. * WordPress Query object
  293. * @global WP_Query $wp_the_query
  294. * @since 2.0.0
  295. */
  296. $GLOBALS['wp_the_query'] = new WP_Query();
  297. /**
  298. * Holds the reference to @see $wp_the_query
  299. * Use this global for WordPress queries
  300. * @global WP_Query $wp_query
  301. * @since 1.5.0
  302. */
  303. $GLOBALS['wp_query'] = $GLOBALS['wp_the_query'];
  304. /**
  305. * Holds the WordPress Rewrite object for creating pretty URLs
  306. * @global WP_Rewrite $wp_rewrite
  307. * @since 1.5.0
  308. */
  309. $GLOBALS['wp_rewrite'] = new WP_Rewrite();
  310. /**
  311. * WordPress Object
  312. * @global WP $wp
  313. * @since 2.0.0
  314. */
  315. $GLOBALS['wp'] = new WP();
  316. /**
  317. * WordPress Widget Factory Object
  318. * @global WP_Widget_Factory $wp_widget_factory
  319. * @since 2.8.0
  320. */
  321. $GLOBALS['wp_widget_factory'] = new WP_Widget_Factory();
  322. /**
  323. * WordPress User Roles
  324. * @global WP_Roles $wp_roles
  325. * @since 2.0.0
  326. */
  327. $GLOBALS['wp_roles'] = new WP_Roles();
  328. /**
  329. * Fires before the theme is loaded.
  330. *
  331. * @since 2.6.0
  332. */
  333. do_action( 'setup_theme' );
  334. // Define the template related constants.
  335. wp_templating_constants( );
  336. // Load the default text localization domain.
  337. load_default_textdomain();
  338. $locale = get_locale();
  339. $locale_file = WP_LANG_DIR . "/$locale.php";
  340. if ( ( 0 === validate_file( $locale ) ) && is_readable( $locale_file ) )
  341. require( $locale_file );
  342. unset( $locale_file );
  343. /**
  344. * WordPress Locale object for loading locale domain date and various strings.
  345. * @global WP_Locale $wp_locale
  346. * @since 2.1.0
  347. */
  348. $GLOBALS['wp_locale'] = new WP_Locale();
  349. /**
  350. * WordPress Locale Switcher object for switching locales.
  351. *
  352. * @since 4.7.0
  353. *
  354. * @global WP_Locale_Switcher $wp_locale_switcher WordPress locale switcher object.
  355. */
  356. $GLOBALS['wp_locale_switcher'] = new WP_Locale_Switcher();
  357. $GLOBALS['wp_locale_switcher']->init();
  358. // Load the functions for the active theme, for both parent and child theme if applicable.
  359. if ( ! wp_installing() || 'wp-activate.php' === $pagenow ) {
  360. if ( TEMPLATEPATH !== STYLESHEETPATH && file_exists( STYLESHEETPATH . '/functions.php' ) )
  361. include( STYLESHEETPATH . '/functions.php' );
  362. if ( file_exists( TEMPLATEPATH . '/functions.php' ) )
  363. include( TEMPLATEPATH . '/functions.php' );
  364. }
  365. /**
  366. * Fires after the theme is loaded.
  367. *
  368. * @since 3.0.0
  369. */
  370. do_action( 'after_setup_theme' );
  371. // Set up current user.
  372. $GLOBALS['wp']->init();
  373. /**
  374. * Fires after WordPress has finished loading but before any headers are sent.
  375. *
  376. * Most of WP is loaded at this stage, and the user is authenticated. WP continues
  377. * to load on the {@see 'init'} hook that follows (e.g. widgets), and many plugins instantiate
  378. * themselves on it for all sorts of reasons (e.g. they need a user, a taxonomy, etc.).
  379. *
  380. * If you wish to plug an action once WP is loaded, use the {@see 'wp_loaded'} hook below.
  381. *
  382. * @since 1.5.0
  383. */
  384. do_action( 'init' );
  385. // Check site status
  386. if ( is_multisite() ) {
  387. if ( true !== ( $file = ms_site_check() ) ) {
  388. require( $file );
  389. die();
  390. }
  391. unset($file);
  392. }
  393. /**
  394. * This hook is fired once WP, all plugins, and the theme are fully loaded and instantiated.
  395. *
  396. * Ajax requests should use wp-admin/admin-ajax.php. admin-ajax.php can handle requests for
  397. * users not logged in.
  398. *
  399. * @link https://codex.wordpress.org/AJAX_in_Plugins
  400. *
  401. * @since 3.0.0
  402. */
  403. do_action( 'wp_loaded' );