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 // Some IIS + PHP configurations puts the script-name in the path-info (No need to append it twice)
72 if ( isset($_SERVER['PATH_INFO']) ) {
73 if ( $_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME'] )
74 $_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'];
76 $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO'];
79 // Append the query string if it exists and isn't null
80 if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) {
81 $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
86 // Fix for PHP as CGI hosts that set SCRIPT_FILENAME to something ending in php.cgi for all requests
87 if ( isset($_SERVER['SCRIPT_FILENAME']) && ( strpos($_SERVER['SCRIPT_FILENAME'], 'php.cgi') == strlen($_SERVER['SCRIPT_FILENAME']) - 7 ) )
88 $_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED'];
90 // Fix for Dreamhost and other PHP as CGI hosts
91 if (strpos($_SERVER['SCRIPT_NAME'], 'php.cgi') !== false)
92 unset($_SERVER['PATH_INFO']);
95 $PHP_SELF = $_SERVER['PHP_SELF'];
96 if ( empty($PHP_SELF) )
97 $_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace("/(\?.*)?$/",'',$_SERVER["REQUEST_URI"]);
99 if ( version_compare( '4.3', phpversion(), '>' ) ) {
100 die( 'Your server is running PHP version ' . phpversion() . ' but WordPress requires at least 4.3.' );
103 if ( !extension_loaded('mysql') && !file_exists(ABSPATH . 'wp-content/db.php') )
104 die( 'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.' );
107 * timer_start() - PHP 4 standard microtime start capture
111 * @global int $timestart Seconds and Microseconds added together from when function is called
112 * @return bool Always returns true
114 function timer_start() {
116 $mtime = explode(' ', microtime() );
117 $mtime = $mtime[1] + $mtime[0];
123 * timer_stop() - Return and/or display the time from the page start to when function is called.
125 * You can get the results and print them by doing:
127 * $nTimePageTookToExecute = timer_stop();
128 * echo $nTimePageTookToExecute;
131 * Or instead, you can do:
135 * which will do what the above does. If you need the result, you can assign it to a variable, but
136 * most cases, you only need to echo it.
139 * @global int $timestart Seconds and Microseconds added together from when timer_start() is called
140 * @global int $timeend Seconds and Microseconds added together from when function is called
142 * @param int $display Use '0' or null to not echo anything and 1 to echo the total time
143 * @param int $precision The amount of digits from the right of the decimal to display. Default is 3.
144 * @return float The "second.microsecond" finished time calculation
146 function timer_stop($display = 0, $precision = 3) { //if called like timer_stop(1), will echo $timetotal
147 global $timestart, $timeend;
148 $mtime = microtime();
149 $mtime = explode(' ',$mtime);
150 $mtime = $mtime[1] + $mtime[0];
152 $timetotal = $timeend-$timestart;
153 $r = ( function_exists('number_format_i18n') ) ? number_format_i18n($timetotal, $precision) : number_format($timetotal, $precision);
160 // Add define('WP_DEBUG',true); to wp-config.php to enable display of notices during development.
161 if (defined('WP_DEBUG') and WP_DEBUG == true) {
162 error_reporting(E_ALL);
164 error_reporting(E_ALL ^ E_NOTICE ^ E_USER_NOTICE);
167 // For an advanced caching plugin to use, static because you would only want one
168 if ( defined('WP_CACHE') )
169 @include ABSPATH . 'wp-content/advanced-cache.php';
172 * Stores the location of the WordPress directory of functions, classes, and core content.
176 define('WPINC', 'wp-includes');
178 if ( !defined('LANGDIR') ) {
180 * Stores the location of the language directory. First looks for language folder in wp-content
181 * and uses that folder if it exists. Or it uses the "languages" folder in WPINC.
185 if ( file_exists(ABSPATH . 'wp-content/languages') && @is_dir(ABSPATH . 'wp-content/languages') )
186 define('LANGDIR', 'wp-content/languages'); // no leading slash, no trailing slash
188 define('LANGDIR', WPINC . '/languages'); // no leading slash, no trailing slash
192 * Allows for the plugins directory to be moved from the default location.
194 * This isn't used everywhere. Constant is not used in plugin_basename()
195 * which might cause conflicts with changing this.
199 if ( !defined('PLUGINDIR') )
200 define('PLUGINDIR', 'wp-content/plugins'); // no leading slash, no trailing slash
202 require (ABSPATH . WPINC . '/compat.php');
203 require (ABSPATH . WPINC . '/functions.php');
204 require (ABSPATH . WPINC . '/classes.php');
208 if ( !empty($wpdb->error) )
211 $prefix = $wpdb->set_prefix($table_prefix);
213 if ( is_wp_error($prefix) )
214 wp_die('<strong>ERROR</strong>: <code>$table_prefix</code> in <code>wp-config.php</code> can only contain numbers, letters, and underscores.');
216 if ( file_exists(ABSPATH . 'wp-content/object-cache.php') )
217 require_once (ABSPATH . 'wp-content/object-cache.php');
219 require_once (ABSPATH . WPINC . '/cache.php');
223 require (ABSPATH . WPINC . '/plugin.php');
224 require (ABSPATH . WPINC . '/default-filters.php');
225 include_once(ABSPATH . WPINC . '/streams.php');
226 include_once(ABSPATH . WPINC . '/gettext.php');
227 require_once (ABSPATH . WPINC . '/l10n.php');
229 if ( !is_blog_installed() && (strpos($_SERVER['PHP_SELF'], 'install.php') === false && !defined('WP_INSTALLING')) ) {
230 if ( defined('WP_SITEURL') )
231 $link = WP_SITEURL . '/wp-admin/install.php';
232 elseif (strpos($_SERVER['PHP_SELF'], 'wp-admin') !== false)
233 $link = preg_replace('|/wp-admin/?.*?$|', '/', $_SERVER['PHP_SELF']) . 'wp-admin/install.php';
235 $link = preg_replace('|/[^/]+?$|', '/', $_SERVER['PHP_SELF']) . 'wp-admin/install.php';
236 require_once(ABSPATH . WPINC . '/kses.php');
237 require_once(ABSPATH . WPINC . '/pluggable.php');
239 die(); // have to die here ~ Mark
242 require (ABSPATH . WPINC . '/formatting.php');
243 require (ABSPATH . WPINC . '/capabilities.php');
244 require (ABSPATH . WPINC . '/query.php');
245 require (ABSPATH . WPINC . '/theme.php');
246 require (ABSPATH . WPINC . '/user.php');
247 require (ABSPATH . WPINC . '/general-template.php');
248 require (ABSPATH . WPINC . '/link-template.php');
249 require (ABSPATH . WPINC . '/author-template.php');
250 require (ABSPATH . WPINC . '/post.php');
251 require (ABSPATH . WPINC . '/post-template.php');
252 require (ABSPATH . WPINC . '/category.php');
253 require (ABSPATH . WPINC . '/category-template.php');
254 require (ABSPATH . WPINC . '/comment.php');
255 require (ABSPATH . WPINC . '/comment-template.php');
256 require (ABSPATH . WPINC . '/rewrite.php');
257 require (ABSPATH . WPINC . '/feed.php');
258 require (ABSPATH . WPINC . '/bookmark.php');
259 require (ABSPATH . WPINC . '/bookmark-template.php');
260 require (ABSPATH . WPINC . '/kses.php');
261 require (ABSPATH . WPINC . '/cron.php');
262 require (ABSPATH . WPINC . '/version.php');
263 require (ABSPATH . WPINC . '/deprecated.php');
264 require (ABSPATH . WPINC . '/script-loader.php');
265 require (ABSPATH . WPINC . '/taxonomy.php');
266 require (ABSPATH . WPINC . '/update.php');
267 require (ABSPATH . WPINC . '/canonical.php');
268 require (ABSPATH . WPINC . '/shortcodes.php');
269 require (ABSPATH . WPINC . '/media.php');
271 if (strpos($_SERVER['PHP_SELF'], 'install.php') === false) {
272 // Used to guarantee unique hash cookies
273 $cookiehash = md5(get_option('siteurl'));
275 * Used to guarantee unique hash cookies
278 define('COOKIEHASH', $cookiehash);
282 * Should be exactly the same as the default value of SECRET_KEY in wp-config-sample.php
285 $wp_default_secret_key = 'put your unique phrase here';
288 * It is possible to define this in wp-config.php
291 if ( !defined('USER_COOKIE') )
292 define('USER_COOKIE', 'wordpressuser_' . COOKIEHASH);
295 * It is possible to define this in wp-config.php
298 if ( !defined('PASS_COOKIE') )
299 define('PASS_COOKIE', 'wordpresspass_' . COOKIEHASH);
302 * It is possible to define this in wp-config.php
305 if ( !defined('AUTH_COOKIE') )
306 define('AUTH_COOKIE', 'wordpress_' . COOKIEHASH);
309 * It is possible to define this in wp-config.php
312 if ( !defined('TEST_COOKIE') )
313 define('TEST_COOKIE', 'wordpress_test_cookie');
316 * It is possible to define this in wp-config.php
319 if ( !defined('COOKIEPATH') )
320 define('COOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('home') . '/' ) );
323 * It is possible to define this in wp-config.php
326 if ( !defined('SITECOOKIEPATH') )
327 define('SITECOOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('siteurl') . '/' ) );
330 * It is possible to define this in wp-config.php
333 if ( !defined('COOKIE_DOMAIN') )
334 define('COOKIE_DOMAIN', false);
337 * It is possible to define this in wp-config.php
340 if ( !defined( 'AUTOSAVE_INTERVAL' ) )
341 define( 'AUTOSAVE_INTERVAL', 60 );
344 require (ABSPATH . WPINC . '/vars.php');
346 // Check for hacks file if the option is enabled
347 if (get_option('hack_file')) {
348 if (file_exists(ABSPATH . 'my-hacks.php'))
349 require(ABSPATH . 'my-hacks.php');
352 if ( get_option('active_plugins') ) {
353 $current_plugins = get_option('active_plugins');
354 if ( is_array($current_plugins) ) {
355 foreach ($current_plugins as $plugin) {
356 if ('' != $plugin && file_exists(ABSPATH . PLUGINDIR . '/' . $plugin))
357 include_once(ABSPATH . PLUGINDIR . '/' . $plugin);
362 require (ABSPATH . WPINC . '/pluggable.php');
365 * In most cases the default internal encoding is latin1, which is of no use,
366 * since we want to use the mb_ functions for utf-8 strings
368 if (function_exists('mb_internal_encoding')) {
369 if (!@mb_internal_encoding(get_option('blog_charset')))
370 mb_internal_encoding('UTF-8');
374 if ( defined('WP_CACHE') && function_exists('wp_cache_postload') )
377 do_action('plugins_loaded');
379 // If already slashed, strip.
380 if ( get_magic_quotes_gpc() ) {
381 $_GET = stripslashes_deep($_GET );
382 $_POST = stripslashes_deep($_POST );
383 $_COOKIE = stripslashes_deep($_COOKIE);
387 $_GET = add_magic_quotes($_GET );
388 $_POST = add_magic_quotes($_POST );
389 $_COOKIE = add_magic_quotes($_COOKIE);
390 $_SERVER = add_magic_quotes($_SERVER);
392 do_action('sanitize_comment_cookies');
395 * WordPress Query object
396 * @global object $wp_the_query
399 $wp_the_query =& new WP_Query();
402 * Holds the reference to @see $wp_the_query
403 * Use this global for WordPress queries
404 * @global object $wp_query
407 $wp_query =& $wp_the_query;
410 * Holds the WordPress Rewrite object for creating pretty URLs
411 * @global object $wp_rewrite
414 $wp_rewrite =& new WP_Rewrite();
425 * Web Path to the current active template directory
428 define('TEMPLATEPATH', get_template_directory());
431 * Web Path to the current active template stylesheet directory
434 define('STYLESHEETPATH', get_stylesheet_directory());
436 // Load the default text localization domain.
437 load_default_textdomain();
440 * The locale of the blog
443 $locale = get_locale();
444 $locale_file = ABSPATH . LANGDIR . "/$locale.php";
445 if ( is_readable($locale_file) )
446 require_once($locale_file);
448 // Pull in locale data after loading text domain.
449 require_once(ABSPATH . WPINC . '/locale.php');
452 * WordPress Locale object for loading locale domain date and various strings.
453 * @global object $wp_locale
456 $wp_locale =& new WP_Locale();
458 // Load functions for active theme.
459 if ( TEMPLATEPATH !== STYLESHEETPATH && file_exists(STYLESHEETPATH . '/functions.php') )
460 include(STYLESHEETPATH . '/functions.php');
461 if ( file_exists(TEMPLATEPATH . '/functions.php') )
462 include(TEMPLATEPATH . '/functions.php');
465 * shutdown_action_hook() - Runs just before PHP shuts down execution.
470 function shutdown_action_hook() {
471 do_action('shutdown');
474 register_shutdown_function('shutdown_action_hook');
476 $wp->init(); // Sets up current user.
478 // Everything is loaded and initialized.