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