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