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