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