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);
20 * wp_unregister_GLOBALS() - Turn register globals off
24 * @return null Will return null if register_globals PHP directive was disabled
26 function wp_unregister_GLOBALS() {
27 if ( !ini_get('register_globals') )
30 if ( isset($_REQUEST['GLOBALS']) )
31 die('GLOBALS overwrite attempt detected');
33 // Variables that shouldn't be unset
34 $noUnset = array('GLOBALS', '_GET', '_POST', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES', 'table_prefix');
36 $input = array_merge($_GET, $_POST, $_COOKIE, $_SERVER, $_ENV, $_FILES, isset($_SESSION) && is_array($_SESSION) ? $_SESSION : array());
37 foreach ( $input as $k => $v )
38 if ( !in_array($k, $noUnset) && isset($GLOBALS[$k]) ) {
44 wp_unregister_GLOBALS();
46 unset( $wp_filter, $cache_lastcommentmodified, $cache_lastpostdate );
49 * The $blog_id global, which you can change in the config allows you to create a simple
50 * multiple blog installation using just one WordPress and changing $blog_id around.
52 * @global int $blog_id
55 if ( ! isset($blog_id) )
58 // Fix for IIS, which doesn't set REQUEST_URI
59 if ( empty( $_SERVER['REQUEST_URI'] ) ) {
62 if (isset($_SERVER['HTTP_X_ORIGINAL_URL'])) {
63 $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
66 else if (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
67 $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
71 // Use ORIG_PATH_INFO if there is no PATH_INFO
72 if ( !isset($_SERVER['PATH_INFO']) && isset($_SERVER['ORIG_PATH_INFO']) )
73 $_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'];
75 // Some IIS + PHP configurations puts the script-name in the path-info (No need to append it twice)
76 if ( isset($_SERVER['PATH_INFO']) ) {
77 if ( $_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME'] )
78 $_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'];
80 $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO'];
83 // Append the query string if it exists and isn't null
84 if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) {
85 $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
90 // Fix for PHP as CGI hosts that set SCRIPT_FILENAME to something ending in php.cgi for all requests
91 if ( isset($_SERVER['SCRIPT_FILENAME']) && ( strpos($_SERVER['SCRIPT_FILENAME'], 'php.cgi') == strlen($_SERVER['SCRIPT_FILENAME']) - 7 ) )
92 $_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED'];
94 // Fix for Dreamhost and other PHP as CGI hosts
95 if (strpos($_SERVER['SCRIPT_NAME'], 'php.cgi') !== false)
96 unset($_SERVER['PATH_INFO']);
99 $PHP_SELF = $_SERVER['PHP_SELF'];
100 if ( empty($PHP_SELF) )
101 $_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace("/(\?.*)?$/",'',$_SERVER["REQUEST_URI"]);
103 if ( version_compare( '4.3', phpversion(), '>' ) ) {
104 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() ) );
107 if ( !defined('WP_CONTENT_DIR') )
108 define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' ); // no trailing slash, full paths only - WP_CONTENT_URL is defined further down
110 if ( !extension_loaded('mysql') && !file_exists(WP_CONTENT_DIR . '/db.php') )
111 die( /*WP_I18N_OLD_MYSQL*/'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.'/*/WP_I18N_OLD_MYSQL*/ );
114 * timer_start() - PHP 4 standard microtime start capture
118 * @global int $timestart Seconds and Microseconds added together from when function is called
119 * @return bool Always returns true
121 function timer_start() {
123 $mtime = explode(' ', microtime() );
124 $mtime = $mtime[1] + $mtime[0];
130 * timer_stop() - Return and/or display the time from the page start to when function is called.
132 * You can get the results and print them by doing:
134 * $nTimePageTookToExecute = timer_stop();
135 * echo $nTimePageTookToExecute;
138 * Or instead, you can do:
142 * which will do what the above does. If you need the result, you can assign it to a variable, but
143 * most cases, you only need to echo it.
146 * @global int $timestart Seconds and Microseconds added together from when timer_start() is called
147 * @global int $timeend Seconds and Microseconds added together from when function is called
149 * @param int $display Use '0' or null to not echo anything and 1 to echo the total time
150 * @param int $precision The amount of digits from the right of the decimal to display. Default is 3.
151 * @return float The "second.microsecond" finished time calculation
153 function timer_stop($display = 0, $precision = 3) { //if called like timer_stop(1), will echo $timetotal
154 global $timestart, $timeend;
155 $mtime = microtime();
156 $mtime = explode(' ',$mtime);
157 $mtime = $mtime[1] + $mtime[0];
159 $timetotal = $timeend-$timestart;
160 $r = ( function_exists('number_format_i18n') ) ? number_format_i18n($timetotal, $precision) : number_format($timetotal, $precision);
167 // Add define('WP_DEBUG',true); to wp-config.php to enable display of notices during development.
168 if (defined('WP_DEBUG') and WP_DEBUG == true) {
169 error_reporting(E_ALL);
171 error_reporting(E_ALL ^ E_NOTICE ^ E_USER_NOTICE);
174 // For an advanced caching plugin to use, static because you would only want one
175 if ( defined('WP_CACHE') )
176 @include WP_CONTENT_DIR . '/advanced-cache.php';
179 * Stores the location of the WordPress directory of functions, classes, and core content.
183 define('WPINC', 'wp-includes');
185 if ( !defined('WP_LANG_DIR') ) {
187 * Stores the location of the language directory. First looks for language folder in WP_CONTENT_DIR
188 * and uses that folder if it exists. Or it uses the "languages" folder in WPINC.
192 if ( file_exists(WP_CONTENT_DIR . '/languages') && @is_dir(WP_CONTENT_DIR . '/languages') ) {
193 define('WP_LANG_DIR', WP_CONTENT_DIR . '/languages'); // no leading slash, no trailing slash, full path, not relative to ABSPATH
194 if (!defined('LANGDIR')) {
195 // Old static relative path maintained for limited backwards compatibility - won't work in some cases
196 define('LANGDIR', 'wp-content/languages');
199 define('WP_LANG_DIR', ABSPATH . WPINC . '/languages'); // no leading slash, no trailing slash, full path, not relative to ABSPATH
200 if (!defined('LANGDIR')) {
201 // Old relative path maintained for backwards compatibility
202 define('LANGDIR', WPINC . '/languages');
207 require (ABSPATH . WPINC . '/compat.php');
208 require (ABSPATH . WPINC . '/functions.php');
209 require (ABSPATH . WPINC . '/classes.php');
213 if ( !empty($wpdb->error) )
216 $prefix = $wpdb->set_prefix($table_prefix);
218 if ( is_wp_error($prefix) )
219 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*/);
221 if ( file_exists(WP_CONTENT_DIR . '/object-cache.php') )
222 require_once (WP_CONTENT_DIR . '/object-cache.php');
224 require_once (ABSPATH . WPINC . '/cache.php');
227 if ( function_exists('wp_cache_add_global_groups') ) {
228 wp_cache_add_global_groups(array ('users', 'userlogins', 'usermeta'));
229 wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' ));
232 require (ABSPATH . WPINC . '/plugin.php');
233 require (ABSPATH . WPINC . '/default-filters.php');
234 include_once(ABSPATH . WPINC . '/streams.php');
235 include_once(ABSPATH . WPINC . '/gettext.php');
236 require_once (ABSPATH . WPINC . '/l10n.php');
238 if ( !is_blog_installed() && (strpos($_SERVER['PHP_SELF'], 'install.php') === false && !defined('WP_INSTALLING')) ) {
239 if ( defined('WP_SITEURL') )
240 $link = WP_SITEURL . '/wp-admin/install.php';
241 elseif (strpos($_SERVER['PHP_SELF'], 'wp-admin') !== false)
242 $link = preg_replace('|/wp-admin/?.*?$|', '/', $_SERVER['PHP_SELF']) . 'wp-admin/install.php';
244 $link = preg_replace('|/[^/]+?$|', '/', $_SERVER['PHP_SELF']) . 'wp-admin/install.php';
245 require_once(ABSPATH . WPINC . '/kses.php');
246 require_once(ABSPATH . WPINC . '/pluggable.php');
248 die(); // have to die here ~ Mark
251 require (ABSPATH . WPINC . '/formatting.php');
252 require (ABSPATH . WPINC . '/capabilities.php');
253 require (ABSPATH . WPINC . '/query.php');
254 require (ABSPATH . WPINC . '/theme.php');
255 require (ABSPATH . WPINC . '/user.php');
256 require (ABSPATH . WPINC . '/general-template.php');
257 require (ABSPATH . WPINC . '/link-template.php');
258 require (ABSPATH . WPINC . '/author-template.php');
259 require (ABSPATH . WPINC . '/post.php');
260 require (ABSPATH . WPINC . '/post-template.php');
261 require (ABSPATH . WPINC . '/category.php');
262 require (ABSPATH . WPINC . '/category-template.php');
263 require (ABSPATH . WPINC . '/comment.php');
264 require (ABSPATH . WPINC . '/comment-template.php');
265 require (ABSPATH . WPINC . '/rewrite.php');
266 require (ABSPATH . WPINC . '/feed.php');
267 require (ABSPATH . WPINC . '/bookmark.php');
268 require (ABSPATH . WPINC . '/bookmark-template.php');
269 require (ABSPATH . WPINC . '/kses.php');
270 require (ABSPATH . WPINC . '/cron.php');
271 require (ABSPATH . WPINC . '/version.php');
272 require (ABSPATH . WPINC . '/deprecated.php');
273 require (ABSPATH . WPINC . '/script-loader.php');
274 require (ABSPATH . WPINC . '/taxonomy.php');
275 require (ABSPATH . WPINC . '/update.php');
276 require (ABSPATH . WPINC . '/canonical.php');
277 require (ABSPATH . WPINC . '/shortcodes.php');
278 require (ABSPATH . WPINC . '/media.php');
280 if ( !defined('WP_CONTENT_URL') )
281 define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content'); // full url - WP_CONTENT_DIR is defined further up
284 * Allows for the plugins directory to be moved from the default location.
288 if ( !defined('WP_PLUGIN_DIR') )
289 define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' ); // full path, no trailing slash
290 if ( !defined('WP_PLUGIN_URL') )
291 define( 'WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins' ); // full url, no trailing slash
292 if ( !defined('PLUGINDIR') )
293 define( 'PLUGINDIR', 'wp-content/plugins' ); // Relative to ABSPATH. For back compat.
295 if ( ! defined('WP_INSTALLING') ) {
296 // Used to guarantee unique hash cookies
297 $cookiehash = md5(get_option('siteurl'));
299 * Used to guarantee unique hash cookies
302 define('COOKIEHASH', $cookiehash);
306 * Should be exactly the same as the default value of SECRET_KEY in wp-config-sample.php
309 $wp_default_secret_key = 'put your unique phrase here';
312 * It is possible to define this in wp-config.php
315 if ( !defined('USER_COOKIE') )
316 define('USER_COOKIE', 'wordpressuser_' . COOKIEHASH);
319 * It is possible to define this in wp-config.php
322 if ( !defined('PASS_COOKIE') )
323 define('PASS_COOKIE', 'wordpresspass_' . COOKIEHASH);
326 * It is possible to define this in wp-config.php
329 if ( !defined('AUTH_COOKIE') )
330 define('AUTH_COOKIE', 'wordpress_' . COOKIEHASH);
333 * It is possible to define this in wp-config.php
336 if ( !defined('SECURE_AUTH_COOKIE') )
337 define('SECURE_AUTH_COOKIE', 'wordpress_sec_' . COOKIEHASH);
340 * It is possible to define this in wp-config.php
343 if ( !defined('LOGGED_IN_COOKIE') )
344 define('LOGGED_IN_COOKIE', 'wordpress_logged_in_' . COOKIEHASH);
347 * It is possible to define this in wp-config.php
350 if ( !defined('TEST_COOKIE') )
351 define('TEST_COOKIE', 'wordpress_test_cookie');
354 * It is possible to define this in wp-config.php
357 if ( !defined('COOKIEPATH') )
358 define('COOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('home') . '/' ) );
361 * It is possible to define this in wp-config.php
364 if ( !defined('SITECOOKIEPATH') )
365 define('SITECOOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('siteurl') . '/' ) );
368 * It is possible to define this in wp-config.php
371 if ( !defined('ADMIN_COOKIE_PATH') )
372 define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH . 'wp-admin' );
375 * It is possible to define this in wp-config.php
378 if ( !defined('PLUGINS_COOKIE_PATH') )
379 define( 'PLUGINS_COOKIE_PATH', preg_replace('|https?://[^/]+|i', '', WP_PLUGIN_URL) );
382 * It is possible to define this in wp-config.php
385 if ( !defined('COOKIE_DOMAIN') )
386 define('COOKIE_DOMAIN', false);
389 * It is possible to define this in wp-config.php
392 if ( !defined('FORCE_SSL_ADMIN') )
393 define('FORCE_SSL_ADMIN', false);
394 force_ssl_admin(FORCE_SSL_ADMIN);
397 * It is possible to define this in wp-config.php
400 if ( !defined('FORCE_SSL_LOGIN') )
401 define('FORCE_SSL_LOGIN', false);
402 force_ssl_login(FORCE_SSL_LOGIN);
405 * It is possible to define this in wp-config.php
408 if ( !defined( 'AUTOSAVE_INTERVAL' ) )
409 define( 'AUTOSAVE_INTERVAL', 60 );
412 require (ABSPATH . WPINC . '/vars.php');
414 // Check for hacks file if the option is enabled
415 if (get_option('hack_file')) {
416 if (file_exists(ABSPATH . 'my-hacks.php'))
417 require(ABSPATH . 'my-hacks.php');
420 if ( get_option('active_plugins') ) {
421 $current_plugins = get_option('active_plugins');
422 if ( is_array($current_plugins) ) {
423 foreach ($current_plugins as $plugin) {
424 if ( '' != $plugin && 0 == validate_file($plugin) && file_exists(WP_PLUGIN_DIR . '/' . $plugin) )
425 include_once(WP_PLUGIN_DIR . '/' . $plugin);
430 require (ABSPATH . WPINC . '/pluggable.php');
433 * In most cases the default internal encoding is latin1, which is of no use,
434 * since we want to use the mb_ functions for utf-8 strings
436 if (function_exists('mb_internal_encoding')) {
437 if (!@mb_internal_encoding(get_option('blog_charset')))
438 mb_internal_encoding('UTF-8');
442 if ( defined('WP_CACHE') && function_exists('wp_cache_postload') )
445 do_action('plugins_loaded');
447 $default_constants = array( 'WP_POST_REVISIONS' => true );
448 foreach ( $default_constants as $c => $v )
449 @define( $c, $v ); // will fail if the constant is already defined
450 unset($default_constants, $c, $v);
452 // If already slashed, strip.
453 if ( get_magic_quotes_gpc() ) {
454 $_GET = stripslashes_deep($_GET );
455 $_POST = stripslashes_deep($_POST );
456 $_COOKIE = stripslashes_deep($_COOKIE);
460 $_GET = add_magic_quotes($_GET );
461 $_POST = add_magic_quotes($_POST );
462 $_COOKIE = add_magic_quotes($_COOKIE);
463 $_SERVER = add_magic_quotes($_SERVER);
465 do_action('sanitize_comment_cookies');
468 * WordPress Query object
469 * @global object $wp_the_query
472 $wp_the_query =& new WP_Query();
475 * Holds the reference to @see $wp_the_query
476 * Use this global for WordPress queries
477 * @global object $wp_query
480 $wp_query =& $wp_the_query;
483 * Holds the WordPress Rewrite object for creating pretty URLs
484 * @global object $wp_rewrite
487 $wp_rewrite =& new WP_Rewrite();
496 do_action('setup_theme');
499 * Web Path to the current active template directory
502 define('TEMPLATEPATH', get_template_directory());
505 * Web Path to the current active template stylesheet directory
508 define('STYLESHEETPATH', get_stylesheet_directory());
510 // Load the default text localization domain.
511 load_default_textdomain();
514 * The locale of the blog
517 $locale = get_locale();
518 $locale_file = WP_LANG_DIR . "/$locale.php";
519 if ( is_readable($locale_file) )
520 require_once($locale_file);
522 // Pull in locale data after loading text domain.
523 require_once(ABSPATH . WPINC . '/locale.php');
526 * WordPress Locale object for loading locale domain date and various strings.
527 * @global object $wp_locale
530 $wp_locale =& new WP_Locale();
532 // Load functions for active theme.
533 if ( TEMPLATEPATH !== STYLESHEETPATH && file_exists(STYLESHEETPATH . '/functions.php') )
534 include(STYLESHEETPATH . '/functions.php');
535 if ( file_exists(TEMPLATEPATH . '/functions.php') )
536 include(TEMPLATEPATH . '/functions.php');
539 * shutdown_action_hook() - Runs just before PHP shuts down execution.
544 function shutdown_action_hook() {
545 do_action('shutdown');
548 register_shutdown_function('shutdown_action_hook');
550 $wp->init(); // Sets up current user.
552 // Everything is loaded and initialized.