]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-settings.php
Wordpress 2.6.2
[autoinstalls/wordpress.git] / wp-settings.php
1 <?php
2 /**
3  * Used to setup and fix common variables and include
4  * the WordPress procedural and class library.
5  *
6  * You should not have to change this file and allows
7  * for some configuration in wp-config.php.
8  *
9  * @package WordPress
10  */
11
12 if ( !defined('WP_MEMORY_LIMIT') )
13         define('WP_MEMORY_LIMIT', '32M');
14
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);
17
18
19 /**
20  * wp_unregister_GLOBALS() - Turn register globals off
21  *
22  * @access private
23  * @since 2.1.0
24  * @return null Will return null if register_globals PHP directive was disabled
25  */
26 function wp_unregister_GLOBALS() {
27         if ( !ini_get('register_globals') )
28                 return;
29
30         if ( isset($_REQUEST['GLOBALS']) )
31                 die('GLOBALS overwrite attempt detected');
32
33         // Variables that shouldn't be unset
34         $noUnset = array('GLOBALS', '_GET', '_POST', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES', 'table_prefix');
35
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]) ) {
39                         $GLOBALS[$k] = NULL;
40                         unset($GLOBALS[$k]);
41                 }
42 }
43
44 wp_unregister_GLOBALS();
45
46 unset( $wp_filter, $cache_lastcommentmodified, $cache_lastpostdate );
47
48 /**
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.
51  *
52  * @global int $blog_id
53  * @since 2.0.0
54  */
55 if ( ! isset($blog_id) )
56         $blog_id = 1;
57
58 // Fix for IIS, which doesn't set REQUEST_URI
59 if ( empty( $_SERVER['REQUEST_URI'] ) ) {
60
61         // IIS Mod-Rewrite
62         if (isset($_SERVER['HTTP_X_ORIGINAL_URL'])) {
63                 $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
64         }
65         // IIS Isapi_Rewrite
66         else if (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
67                 $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
68         }
69         else
70         {
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'];
74
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'];
79                         else
80                                 $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO'];
81                 }
82
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'];
86                 }
87         }
88 }
89
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'];
93
94 // Fix for Dreamhost and other PHP as CGI hosts
95 if (strpos($_SERVER['SCRIPT_NAME'], 'php.cgi') !== false)
96         unset($_SERVER['PATH_INFO']);
97
98 // Fix empty PHP_SELF
99 $PHP_SELF = $_SERVER['PHP_SELF'];
100 if ( empty($PHP_SELF) )
101         $_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace("/(\?.*)?$/",'',$_SERVER["REQUEST_URI"]);
102
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() ) );
105 }
106
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
109
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*/ );
112
113 /**
114  * timer_start() - PHP 4 standard microtime start capture
115  *
116  * @access private
117  * @since 0.71
118  * @global int $timestart Seconds and Microseconds added together from when function is called
119  * @return bool Always returns true
120  */
121 function timer_start() {
122         global $timestart;
123         $mtime = explode(' ', microtime() );
124         $mtime = $mtime[1] + $mtime[0];
125         $timestart = $mtime;
126         return true;
127 }
128
129 /**
130  * timer_stop() - Return and/or display the time from the page start to when function is called.
131  *
132  * You can get the results and print them by doing:
133  * <code>
134  * $nTimePageTookToExecute = timer_stop();
135  * echo $nTimePageTookToExecute;
136  * </code>
137  *
138  * Or instead, you can do:
139  * <code>
140  * timer_stop(1);
141  * </code>
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.
144  *
145  * @since 0.71
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
148  *
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
152  */
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];
158         $timeend = $mtime;
159         $timetotal = $timeend-$timestart;
160         $r = ( function_exists('number_format_i18n') ) ? number_format_i18n($timetotal, $precision) : number_format($timetotal, $precision);
161         if ( $display )
162                 echo $r;
163         return $r;
164 }
165 timer_start();
166
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);
170 } else {
171         error_reporting(E_ALL ^ E_NOTICE ^ E_USER_NOTICE);
172 }
173
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';
177
178 /**
179  * Stores the location of the WordPress directory of functions, classes, and core content.
180  *
181  * @since 1.0.0
182  */
183 define('WPINC', 'wp-includes');
184
185 if ( !defined('WP_LANG_DIR') ) {
186         /**
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.
189          *
190          * @since 2.1.0
191          */
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');
197                 }
198         } else {
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');
203                 }
204         }
205 }
206
207 require (ABSPATH . WPINC . '/compat.php');
208 require (ABSPATH . WPINC . '/functions.php');
209 require (ABSPATH . WPINC . '/classes.php');
210
211 require_wp_db();
212
213 if ( !empty($wpdb->error) )
214         dead_db();
215
216 $prefix = $wpdb->set_prefix($table_prefix);
217
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*/);
220
221 if ( file_exists(WP_CONTENT_DIR . '/object-cache.php') )
222         require_once (WP_CONTENT_DIR . '/object-cache.php');
223 else
224         require_once (ABSPATH . WPINC . '/cache.php');
225
226 wp_cache_init();
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' ));
230 }
231
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');
237
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';
243         else
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');
247         wp_redirect($link);
248         die(); // have to die here ~ Mark
249 }
250
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');
279
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
282
283 /**
284  * Allows for the plugins directory to be moved from the default location.
285  *
286  * @since 2.6
287  */
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.
294
295 if ( ! defined('WP_INSTALLING') ) {
296         // Used to guarantee unique hash cookies
297         $cookiehash = md5(get_option('siteurl'));
298         /**
299          * Used to guarantee unique hash cookies
300          * @since 1.5
301          */
302         define('COOKIEHASH', $cookiehash);
303 }
304
305 /**
306  * Should be exactly the same as the default value of SECRET_KEY in wp-config-sample.php
307  * @since 2.5
308  */
309 $wp_default_secret_key = 'put your unique phrase here';
310
311 /**
312  * It is possible to define this in wp-config.php
313  * @since 2.0.0
314  */
315 if ( !defined('USER_COOKIE') )
316         define('USER_COOKIE', 'wordpressuser_' . COOKIEHASH);
317
318 /**
319  * It is possible to define this in wp-config.php
320  * @since 2.0.0
321  */
322 if ( !defined('PASS_COOKIE') )
323         define('PASS_COOKIE', 'wordpresspass_' . COOKIEHASH);
324
325 /**
326  * It is possible to define this in wp-config.php
327  * @since 2.5
328  */
329 if ( !defined('AUTH_COOKIE') )
330         define('AUTH_COOKIE', 'wordpress_' . COOKIEHASH);
331
332 /**
333  * It is possible to define this in wp-config.php
334  * @since 2.6
335  */
336 if ( !defined('SECURE_AUTH_COOKIE') )
337         define('SECURE_AUTH_COOKIE', 'wordpress_sec_' . COOKIEHASH);
338
339 /**
340  * It is possible to define this in wp-config.php
341  * @since 2.6
342  */
343 if ( !defined('LOGGED_IN_COOKIE') )
344         define('LOGGED_IN_COOKIE', 'wordpress_logged_in_' . COOKIEHASH);
345
346 /**
347  * It is possible to define this in wp-config.php
348  * @since 2.3.0
349  */
350 if ( !defined('TEST_COOKIE') )
351         define('TEST_COOKIE', 'wordpress_test_cookie');
352
353 /**
354  * It is possible to define this in wp-config.php
355  * @since 1.2.0
356  */
357 if ( !defined('COOKIEPATH') )
358         define('COOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('home') . '/' ) );
359
360 /**
361  * It is possible to define this in wp-config.php
362  * @since 1.5.0
363  */
364 if ( !defined('SITECOOKIEPATH') )
365         define('SITECOOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('siteurl') . '/' ) );
366
367 /**
368  * It is possible to define this in wp-config.php
369  * @since 2.6
370  */
371 if ( !defined('ADMIN_COOKIE_PATH') )
372         define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH . 'wp-admin' );
373
374 /**
375  * It is possible to define this in wp-config.php
376  * @since 2.6
377  */
378 if ( !defined('PLUGINS_COOKIE_PATH') )
379         define( 'PLUGINS_COOKIE_PATH', preg_replace('|https?://[^/]+|i', '', WP_PLUGIN_URL)  );
380
381 /**
382  * It is possible to define this in wp-config.php
383  * @since 2.0.0
384  */
385 if ( !defined('COOKIE_DOMAIN') )
386         define('COOKIE_DOMAIN', false);
387
388 /**
389  * It is possible to define this in wp-config.php
390  * @since 2.6
391  */
392 if ( !defined('FORCE_SSL_ADMIN') )
393         define('FORCE_SSL_ADMIN', false);
394 force_ssl_admin(FORCE_SSL_ADMIN);
395
396 /**
397  * It is possible to define this in wp-config.php
398  * @since 2.6
399  */
400 if ( !defined('FORCE_SSL_LOGIN') )
401         define('FORCE_SSL_LOGIN', false);
402 force_ssl_login(FORCE_SSL_LOGIN);
403
404 /**
405  * It is possible to define this in wp-config.php
406  * @since 2.5.0
407  */
408 if ( !defined( 'AUTOSAVE_INTERVAL' ) )
409         define( 'AUTOSAVE_INTERVAL', 60 );
410         
411
412 require (ABSPATH . WPINC . '/vars.php');
413
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');
418 }
419
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);
426                 }
427         }
428 }
429
430 require (ABSPATH . WPINC . '/pluggable.php');
431
432 /*
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
435  */
436 if (function_exists('mb_internal_encoding')) {
437         if (!@mb_internal_encoding(get_option('blog_charset')))
438                 mb_internal_encoding('UTF-8');
439 }
440
441
442 if ( defined('WP_CACHE') && function_exists('wp_cache_postload') )
443         wp_cache_postload();
444
445 do_action('plugins_loaded');
446
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);
451
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);
457 }
458
459 // Escape with wpdb.
460 $_GET    = add_magic_quotes($_GET   );
461 $_POST   = add_magic_quotes($_POST  );
462 $_COOKIE = add_magic_quotes($_COOKIE);
463 $_SERVER = add_magic_quotes($_SERVER);
464
465 do_action('sanitize_comment_cookies');
466
467 /**
468  * WordPress Query object
469  * @global object $wp_the_query
470  * @since 2.0.0
471  */
472 $wp_the_query =& new WP_Query();
473
474 /**
475  * Holds the reference to @see $wp_the_query
476  * Use this global for WordPress queries
477  * @global object $wp_query
478  * @since 1.5.0
479  */
480 $wp_query     =& $wp_the_query;
481
482 /**
483  * Holds the WordPress Rewrite object for creating pretty URLs
484  * @global object $wp_rewrite
485  * @since 1.5.0
486  */
487 $wp_rewrite   =& new WP_Rewrite();
488
489 /**
490  * WordPress Object
491  * @global object $wp
492  * @since 2.0.0
493  */
494 $wp           =& new WP();
495
496 do_action('setup_theme');
497
498 /**
499  * Web Path to the current active template directory
500  * @since 1.5
501  */
502 define('TEMPLATEPATH', get_template_directory());
503
504 /**
505  * Web Path to the current active template stylesheet directory
506  * @since 2.1
507  */
508 define('STYLESHEETPATH', get_stylesheet_directory());
509
510 // Load the default text localization domain.
511 load_default_textdomain();
512
513 /**
514  * The locale of the blog
515  * @since 1.5.0
516  */
517 $locale = get_locale();
518 $locale_file = WP_LANG_DIR . "/$locale.php";
519 if ( is_readable($locale_file) )
520         require_once($locale_file);
521
522 // Pull in locale data after loading text domain.
523 require_once(ABSPATH . WPINC . '/locale.php');
524
525 /**
526  * WordPress Locale object for loading locale domain date and various strings.
527  * @global object $wp_locale
528  * @since 2.1.0
529  */
530 $wp_locale =& new WP_Locale();
531
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');
537
538 /**
539  * shutdown_action_hook() - Runs just before PHP shuts down execution.
540  *
541  * @access private
542  * @since 1.2
543  */
544 function shutdown_action_hook() {
545         do_action('shutdown');
546         wp_cache_close();
547 }
548 register_shutdown_function('shutdown_action_hook');
549
550 $wp->init();  // Sets up current user.
551
552 // Everything is loaded and initialized.
553 do_action('init');
554
555 ?>