3 * Used to setup and fix common variables and include
4 * the WordPress procedural and class library.
6 * You should not have to change this file and allows
7 * for some configuration in wp-config.php.
12 if ( !defined('WP_MEMORY_LIMIT') )
13 define('WP_MEMORY_LIMIT', '32M');
15 if ( function_exists('memory_get_usage') && ( (int) @ini_get('memory_limit') < abs(intval(WP_MEMORY_LIMIT)) ) )
16 @ini_set('memory_limit', WP_MEMORY_LIMIT);
18 set_magic_quotes_runtime(0);
19 @ini_set('magic_quotes_sybase', 0);
22 * Turn register globals off.
26 * @return null Will return null if register_globals PHP directive was disabled
28 function wp_unregister_GLOBALS() {
29 if ( !ini_get('register_globals') )
32 if ( isset($_REQUEST['GLOBALS']) )
33 die('GLOBALS overwrite attempt detected');
35 // Variables that shouldn't be unset
36 $noUnset = array('GLOBALS', '_GET', '_POST', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES', 'table_prefix');
38 $input = array_merge($_GET, $_POST, $_COOKIE, $_SERVER, $_ENV, $_FILES, isset($_SESSION) && is_array($_SESSION) ? $_SESSION : array());
39 foreach ( $input as $k => $v )
40 if ( !in_array($k, $noUnset) && isset($GLOBALS[$k]) ) {
46 wp_unregister_GLOBALS();
48 unset( $wp_filter, $cache_lastcommentmodified, $cache_lastpostdate );
50 // Force REQUEST to be GET + POST. If SERVER, COOKIE, or ENV are needed, use those superglobals directly.
51 $_REQUEST = array_merge($_GET, $_POST);
54 * The $blog_id global, which you can change in the config allows you to create a simple
55 * multiple blog installation using just one WordPress and changing $blog_id around.
57 * @global int $blog_id
60 if ( ! isset($blog_id) )
63 // Fix for IIS, which doesn't set REQUEST_URI
64 if ( empty( $_SERVER['REQUEST_URI'] ) ) {
67 if (isset($_SERVER['HTTP_X_ORIGINAL_URL'])) {
68 $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
71 else if (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
72 $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
76 // Use ORIG_PATH_INFO if there is no PATH_INFO
77 if ( !isset($_SERVER['PATH_INFO']) && isset($_SERVER['ORIG_PATH_INFO']) )
78 $_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'];
80 // Some IIS + PHP configurations puts the script-name in the path-info (No need to append it twice)
81 if ( isset($_SERVER['PATH_INFO']) ) {
82 if ( $_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME'] )
83 $_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'];
85 $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO'];
88 // Append the query string if it exists and isn't null
89 if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) {
90 $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
95 // Fix for PHP as CGI hosts that set SCRIPT_FILENAME to something ending in php.cgi for all requests
96 if ( isset($_SERVER['SCRIPT_FILENAME']) && ( strpos($_SERVER['SCRIPT_FILENAME'], 'php.cgi') == strlen($_SERVER['SCRIPT_FILENAME']) - 7 ) )
97 $_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED'];
99 // Fix for Dreamhost and other PHP as CGI hosts
100 if (strpos($_SERVER['SCRIPT_NAME'], 'php.cgi') !== false)
101 unset($_SERVER['PATH_INFO']);
103 // Fix empty PHP_SELF
104 $PHP_SELF = $_SERVER['PHP_SELF'];
105 if ( empty($PHP_SELF) )
106 $_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace("/(\?.*)?$/",'',$_SERVER["REQUEST_URI"]);
108 if ( version_compare( '4.3', phpversion(), '>' ) ) {
109 die( sprintf( /*WP_I18N_OLD_PHP*/'Your server is running PHP version %s but WordPress requires at least 4.3.'/*/WP_I18N_OLD_PHP*/, phpversion() ) );
112 if ( !defined('WP_CONTENT_DIR') )
113 define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' ); // no trailing slash, full paths only - WP_CONTENT_URL is defined further down
115 if ( file_exists(ABSPATH . '.maintenance') && !defined('WP_INSTALLING') ) {
116 include(ABSPATH . '.maintenance');
117 // If the $upgrading timestamp is older than 10 minutes, don't die.
118 if ( ( time() - $upgrading ) < 600 ) {
119 if ( file_exists( WP_CONTENT_DIR . '/maintenance.php' ) ) {
120 require_once( WP_CONTENT_DIR . '/maintenance.php' );
124 $protocol = $_SERVER["SERVER_PROTOCOL"];
125 if ( 'HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol )
126 $protocol = 'HTTP/1.0';
127 header( "$protocol 503 Service Unavailable", true, 503 );
128 header( 'Content-Type: text/html; charset=utf-8' );
130 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
131 <html xmlns="http://www.w3.org/1999/xhtml">
133 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
134 <title>Maintenance</title>
138 <h1>Briefly unavailable for scheduled maintenance. Check back in a minute.</h1>
146 if ( !extension_loaded('mysql') && !file_exists(WP_CONTENT_DIR . '/db.php') )
147 die( /*WP_I18N_OLD_MYSQL*/'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.'/*/WP_I18N_OLD_MYSQL*/ );
150 * PHP 4 standard microtime start capture.
154 * @global int $timestart Seconds and Microseconds added together from when function is called.
155 * @return bool Always returns true.
157 function timer_start() {
159 $mtime = explode(' ', microtime() );
160 $mtime = $mtime[1] + $mtime[0];
166 * Return and/or display the time from the page start to when function is called.
168 * You can get the results and print them by doing:
170 * $nTimePageTookToExecute = timer_stop();
171 * echo $nTimePageTookToExecute;
174 * Or instead, you can do:
178 * which will do what the above does. If you need the result, you can assign it to a variable, but
179 * most cases, you only need to echo it.
182 * @global int $timestart Seconds and Microseconds added together from when timer_start() is called
183 * @global int $timeend Seconds and Microseconds added together from when function is called
185 * @param int $display Use '0' or null to not echo anything and 1 to echo the total time
186 * @param int $precision The amount of digits from the right of the decimal to display. Default is 3.
187 * @return float The "second.microsecond" finished time calculation
189 function timer_stop($display = 0, $precision = 3) { //if called like timer_stop(1), will echo $timetotal
190 global $timestart, $timeend;
191 $mtime = microtime();
192 $mtime = explode(' ',$mtime);
193 $mtime = $mtime[1] + $mtime[0];
195 $timetotal = $timeend-$timestart;
196 $r = ( function_exists('number_format_i18n') ) ? number_format_i18n($timetotal, $precision) : number_format($timetotal, $precision);
203 // Add define('WP_DEBUG',true); to wp-config.php to enable display of notices during development.
204 if (defined('WP_DEBUG') and WP_DEBUG == true) {
205 error_reporting(E_ALL);
207 if ( defined('E_RECOVERABLE_ERROR') )
208 error_reporting(E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR);
210 error_reporting(E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING);
213 // For an advanced caching plugin to use, static because you would only want one
214 if ( defined('WP_CACHE') )
215 @include WP_CONTENT_DIR . '/advanced-cache.php';
218 * Stores the location of the WordPress directory of functions, classes, and core content.
222 define('WPINC', 'wp-includes');
224 if ( !defined('WP_LANG_DIR') ) {
226 * Stores the location of the language directory. First looks for language folder in WP_CONTENT_DIR
227 * and uses that folder if it exists. Or it uses the "languages" folder in WPINC.
231 if ( file_exists(WP_CONTENT_DIR . '/languages') && @is_dir(WP_CONTENT_DIR . '/languages') ) {
232 define('WP_LANG_DIR', WP_CONTENT_DIR . '/languages'); // no leading slash, no trailing slash, full path, not relative to ABSPATH
233 if (!defined('LANGDIR')) {
234 // Old static relative path maintained for limited backwards compatibility - won't work in some cases
235 define('LANGDIR', 'wp-content/languages');
238 define('WP_LANG_DIR', ABSPATH . WPINC . '/languages'); // no leading slash, no trailing slash, full path, not relative to ABSPATH
239 if (!defined('LANGDIR')) {
240 // Old relative path maintained for backwards compatibility
241 define('LANGDIR', WPINC . '/languages');
246 require (ABSPATH . WPINC . '/compat.php');
247 require (ABSPATH . WPINC . '/functions.php');
248 require (ABSPATH . WPINC . '/classes.php');
252 if ( !empty($wpdb->error) )
256 * Format specifiers for DB columns. Columns not listed here default to %s.
258 * @see wpdb:$field_types
259 * @see wpdb:prepare()
263 $wpdb->field_types = array( 'post_author' => '%d', 'post_parent' => '%d', 'menu_order' => '%d', 'term_id' => '%d', 'term_group' => '%d', 'term_taxonomy_id' => '%d',
264 'parent' => '%d', 'count' => '%d','object_id' => '%d', 'term_order' => '%d', 'ID' => '%d', 'commment_ID' => '%d', 'comment_post_ID' => '%d', 'comment_parent' => '%d',
265 'user_id' => '%d', 'link_id' => '%d', 'link_owner' => '%d', 'link_rating' => '%d', 'option_id' => '%d', 'blog_id' => '%d', 'meta_id' => '%d', 'post_id' => '%d',
266 'user_status' => '%d', 'umeta_id' => '%d', 'comment_karma' => '%d', 'comment_count' => '%d');
268 $prefix = $wpdb->set_prefix($table_prefix);
270 if ( is_wp_error($prefix) )
271 wp_die(/*WP_I18N_BAD_PREFIX*/'<strong>ERROR</strong>: <code>$table_prefix</code> in <code>wp-config.php</code> can only contain numbers, letters, and underscores.'/*/WP_I18N_BAD_PREFIX*/);
276 * Returns a cloned copy of an object.
280 * @param object $object The object to clone
281 * @return object The cloned object
283 function wp_clone( $object ) {
285 if ( !isset( $can_clone ) ) {
286 $can_clone = version_compare( phpversion(), '5.0', '>=' );
288 return $can_clone ? clone( $object ) : $object;
291 if ( file_exists(WP_CONTENT_DIR . '/object-cache.php') ) {
292 require_once (WP_CONTENT_DIR . '/object-cache.php');
293 $_wp_using_ext_object_cache = true;
295 require_once (ABSPATH . WPINC . '/cache.php');
296 $_wp_using_ext_object_cache = false;
300 if ( function_exists('wp_cache_add_global_groups') ) {
301 wp_cache_add_global_groups(array ('users', 'userlogins', 'usermeta'));
302 wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' ));
305 require (ABSPATH . WPINC . '/plugin.php');
306 require (ABSPATH . WPINC . '/default-filters.php');
307 include_once(ABSPATH . WPINC . '/pomo/mo.php');
308 require_once (ABSPATH . WPINC . '/l10n.php');
310 if ( !is_blog_installed() && (strpos($_SERVER['PHP_SELF'], 'install.php') === false && !defined('WP_INSTALLING')) ) {
311 if ( defined('WP_SITEURL') )
312 $link = WP_SITEURL . '/wp-admin/install.php';
313 elseif (strpos($_SERVER['PHP_SELF'], 'wp-admin') !== false)
314 $link = preg_replace('|/wp-admin/?.*?$|', '/', $_SERVER['PHP_SELF']) . 'wp-admin/install.php';
316 $link = preg_replace('|/[^/]+?$|', '/', $_SERVER['PHP_SELF']) . 'wp-admin/install.php';
317 require_once(ABSPATH . WPINC . '/kses.php');
318 require_once(ABSPATH . WPINC . '/pluggable.php');
320 die(); // have to die here ~ Mark
323 require (ABSPATH . WPINC . '/formatting.php');
324 require (ABSPATH . WPINC . '/capabilities.php');
325 require (ABSPATH . WPINC . '/query.php');
326 require (ABSPATH . WPINC . '/theme.php');
327 require (ABSPATH . WPINC . '/user.php');
328 require (ABSPATH . WPINC . '/general-template.php');
329 require (ABSPATH . WPINC . '/link-template.php');
330 require (ABSPATH . WPINC . '/author-template.php');
331 require (ABSPATH . WPINC . '/post.php');
332 require (ABSPATH . WPINC . '/post-template.php');
333 require (ABSPATH . WPINC . '/category.php');
334 require (ABSPATH . WPINC . '/category-template.php');
335 require (ABSPATH . WPINC . '/comment.php');
336 require (ABSPATH . WPINC . '/comment-template.php');
337 require (ABSPATH . WPINC . '/rewrite.php');
338 require (ABSPATH . WPINC . '/feed.php');
339 require (ABSPATH . WPINC . '/bookmark.php');
340 require (ABSPATH . WPINC . '/bookmark-template.php');
341 require (ABSPATH . WPINC . '/kses.php');
342 require (ABSPATH . WPINC . '/cron.php');
343 require (ABSPATH . WPINC . '/version.php');
344 require (ABSPATH . WPINC . '/deprecated.php');
345 require (ABSPATH . WPINC . '/script-loader.php');
346 require (ABSPATH . WPINC . '/taxonomy.php');
347 require (ABSPATH . WPINC . '/update.php');
348 require (ABSPATH . WPINC . '/canonical.php');
349 require (ABSPATH . WPINC . '/shortcodes.php');
350 require (ABSPATH . WPINC . '/media.php');
351 require (ABSPATH . WPINC . '/http.php');
352 require (ABSPATH . WPINC . '/widgets.php');
354 if ( !defined('WP_CONTENT_URL') )
355 define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content'); // full url - WP_CONTENT_DIR is defined further up
358 * Allows for the plugins directory to be moved from the default location.
362 if ( !defined('WP_PLUGIN_DIR') )
363 define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' ); // full path, no trailing slash
366 * Allows for the plugins directory to be moved from the default location.
370 if ( !defined('WP_PLUGIN_URL') )
371 define( 'WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins' ); // full url, no trailing slash
374 * Allows for the plugins directory to be moved from the default location.
378 if ( !defined('PLUGINDIR') )
379 define( 'PLUGINDIR', 'wp-content/plugins' ); // Relative to ABSPATH. For back compat.
382 * Allows for the mu-plugins directory to be moved from the default location.
386 if ( !defined('WPMU_PLUGIN_DIR') )
387 define( 'WPMU_PLUGIN_DIR', WP_CONTENT_DIR . '/mu-plugins' ); // full path, no trailing slash
390 * Allows for the mu-plugins directory to be moved from the default location.
394 if ( !defined('WPMU_PLUGIN_URL') )
395 define( 'WPMU_PLUGIN_URL', WP_CONTENT_URL . '/mu-plugins' ); // full url, no trailing slash
398 * Allows for the mu-plugins directory to be moved from the default location.
402 if ( !defined( 'MUPLUGINDIR' ) )
403 define( 'MUPLUGINDIR', 'wp-content/mu-plugins' ); // Relative to ABSPATH. For back compat.
405 if ( is_dir( WPMU_PLUGIN_DIR ) ) {
406 if ( $dh = opendir( WPMU_PLUGIN_DIR ) ) {
407 while ( ( $plugin = readdir( $dh ) ) !== false ) {
408 if ( substr( $plugin, -4 ) == '.php' ) {
409 include_once( WPMU_PLUGIN_DIR . '/' . $plugin );
414 do_action('muplugins_loaded');
417 * Used to guarantee unique hash cookies
420 define('COOKIEHASH', md5(get_option('siteurl')));
423 * Should be exactly the same as the default value of SECRET_KEY in wp-config-sample.php
426 $wp_default_secret_key = 'put your unique phrase here';
429 * It is possible to define this in wp-config.php
432 if ( !defined('USER_COOKIE') )
433 define('USER_COOKIE', 'wordpressuser_' . COOKIEHASH);
436 * It is possible to define this in wp-config.php
439 if ( !defined('PASS_COOKIE') )
440 define('PASS_COOKIE', 'wordpresspass_' . COOKIEHASH);
443 * It is possible to define this in wp-config.php
446 if ( !defined('AUTH_COOKIE') )
447 define('AUTH_COOKIE', 'wordpress_' . COOKIEHASH);
450 * It is possible to define this in wp-config.php
453 if ( !defined('SECURE_AUTH_COOKIE') )
454 define('SECURE_AUTH_COOKIE', 'wordpress_sec_' . COOKIEHASH);
457 * It is possible to define this in wp-config.php
460 if ( !defined('LOGGED_IN_COOKIE') )
461 define('LOGGED_IN_COOKIE', 'wordpress_logged_in_' . COOKIEHASH);
464 * It is possible to define this in wp-config.php
467 if ( !defined('TEST_COOKIE') )
468 define('TEST_COOKIE', 'wordpress_test_cookie');
471 * It is possible to define this in wp-config.php
474 if ( !defined('COOKIEPATH') )
475 define('COOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('home') . '/' ) );
478 * It is possible to define this in wp-config.php
481 if ( !defined('SITECOOKIEPATH') )
482 define('SITECOOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('siteurl') . '/' ) );
485 * It is possible to define this in wp-config.php
488 if ( !defined('ADMIN_COOKIE_PATH') )
489 define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH . 'wp-admin' );
492 * It is possible to define this in wp-config.php
495 if ( !defined('PLUGINS_COOKIE_PATH') )
496 define( 'PLUGINS_COOKIE_PATH', preg_replace('|https?://[^/]+|i', '', WP_PLUGIN_URL) );
499 * It is possible to define this in wp-config.php
502 if ( !defined('COOKIE_DOMAIN') )
503 define('COOKIE_DOMAIN', false);
506 * It is possible to define this in wp-config.php
509 if ( !defined('FORCE_SSL_ADMIN') )
510 define('FORCE_SSL_ADMIN', false);
511 force_ssl_admin(FORCE_SSL_ADMIN);
514 * It is possible to define this in wp-config.php
517 if ( !defined('FORCE_SSL_LOGIN') )
518 define('FORCE_SSL_LOGIN', false);
519 force_ssl_login(FORCE_SSL_LOGIN);
522 * It is possible to define this in wp-config.php
525 if ( !defined( 'AUTOSAVE_INTERVAL' ) )
526 define( 'AUTOSAVE_INTERVAL', 60 );
529 require (ABSPATH . WPINC . '/vars.php');
531 // Check for hacks file if the option is enabled
532 if ( get_option('hack_file') ) {
533 if ( file_exists(ABSPATH . 'my-hacks.php') )
534 require(ABSPATH . 'my-hacks.php');
537 $current_plugins = get_option('active_plugins');
538 if ( is_array($current_plugins) && !defined('WP_INSTALLING') ) {
539 foreach ( $current_plugins as $plugin ) {
540 // check the $plugin filename
541 // Validate plugin filename
542 if ( validate_file($plugin) // $plugin must validate as file
543 || '.php' != substr($plugin, -4) // $plugin must end with '.php'
544 || !file_exists(WP_PLUGIN_DIR . '/' . $plugin) // $plugin must exist
548 include_once(WP_PLUGIN_DIR . '/' . $plugin);
552 unset($current_plugins);
554 require (ABSPATH . WPINC . '/pluggable.php');
557 * In most cases the default internal encoding is latin1, which is of no use,
558 * since we want to use the mb_ functions for utf-8 strings
560 if (function_exists('mb_internal_encoding')) {
561 if (!@mb_internal_encoding(get_option('blog_charset')))
562 mb_internal_encoding('UTF-8');
566 if ( defined('WP_CACHE') && function_exists('wp_cache_postload') )
569 do_action('plugins_loaded');
571 $default_constants = array( 'WP_POST_REVISIONS' => true );
572 foreach ( $default_constants as $c => $v )
573 @define( $c, $v ); // will fail if the constant is already defined
574 unset($default_constants, $c, $v);
576 // If already slashed, strip.
577 if ( get_magic_quotes_gpc() ) {
578 $_GET = stripslashes_deep($_GET );
579 $_POST = stripslashes_deep($_POST );
580 $_COOKIE = stripslashes_deep($_COOKIE);
584 $_GET = add_magic_quotes($_GET );
585 $_POST = add_magic_quotes($_POST );
586 $_COOKIE = add_magic_quotes($_COOKIE);
587 $_SERVER = add_magic_quotes($_SERVER);
589 do_action('sanitize_comment_cookies');
592 * WordPress Query object
593 * @global object $wp_the_query
596 $wp_the_query =& new WP_Query();
599 * Holds the reference to @see $wp_the_query
600 * Use this global for WordPress queries
601 * @global object $wp_query
604 $wp_query =& $wp_the_query;
607 * Holds the WordPress Rewrite object for creating pretty URLs
608 * @global object $wp_rewrite
611 $wp_rewrite =& new WP_Rewrite();
621 * WordPress Widget Factory Object
622 * @global object $wp_widget_factory
625 $wp_widget_factory =& new WP_Widget_Factory();
627 do_action('setup_theme');
630 * Web Path to the current active template directory
633 define('TEMPLATEPATH', get_template_directory());
636 * Web Path to the current active template stylesheet directory
639 define('STYLESHEETPATH', get_stylesheet_directory());
641 // Load the default text localization domain.
642 load_default_textdomain();
645 * The locale of the blog
648 $locale = get_locale();
649 $locale_file = WP_LANG_DIR . "/$locale.php";
650 if ( is_readable($locale_file) )
651 require_once($locale_file);
653 // Pull in locale data after loading text domain.
654 require_once(ABSPATH . WPINC . '/locale.php');
657 * WordPress Locale object for loading locale domain date and various strings.
658 * @global object $wp_locale
661 $wp_locale =& new WP_Locale();
663 // Load functions for active theme.
664 if ( TEMPLATEPATH !== STYLESHEETPATH && file_exists(STYLESHEETPATH . '/functions.php') )
665 include(STYLESHEETPATH . '/functions.php');
666 if ( file_exists(TEMPLATEPATH . '/functions.php') )
667 include(TEMPLATEPATH . '/functions.php');
670 * Runs just before PHP shuts down execution.
675 function shutdown_action_hook() {
676 do_action('shutdown');
679 register_shutdown_function('shutdown_action_hook');
681 $wp->init(); // Sets up current user.
683 // Everything is loaded and initialized.