]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-settings.php
Wordpress 2.5.1
[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                 // 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'];
75                         else
76                                 $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO'];
77                 }
78
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'];
82                 }
83         }
84 }
85
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'];
89
90 // Fix for Dreamhost and other PHP as CGI hosts
91 if (strpos($_SERVER['SCRIPT_NAME'], 'php.cgi') !== false)
92         unset($_SERVER['PATH_INFO']);
93
94 // Fix empty PHP_SELF
95 $PHP_SELF = $_SERVER['PHP_SELF'];
96 if ( empty($PHP_SELF) )
97         $_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace("/(\?.*)?$/",'',$_SERVER["REQUEST_URI"]);
98
99 if ( version_compare( '4.3', phpversion(), '>' ) ) {
100         die( 'Your server is running PHP version ' . phpversion() . ' but WordPress requires at least 4.3.' );
101 }
102
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.' );
105
106 /**
107  * timer_start() - PHP 4 standard microtime start capture
108  *
109  * @access private
110  * @since 0.71
111  * @global int $timestart Seconds and Microseconds added together from when function is called
112  * @return bool Always returns true
113  */
114 function timer_start() {
115         global $timestart;
116         $mtime = explode(' ', microtime() );
117         $mtime = $mtime[1] + $mtime[0];
118         $timestart = $mtime;
119         return true;
120 }
121
122 /**
123  * timer_stop() - Return and/or display the time from the page start to when function is called.
124  *
125  * You can get the results and print them by doing:
126  * <code>
127  * $nTimePageTookToExecute = timer_stop();
128  * echo $nTimePageTookToExecute;
129  * </code>
130  *
131  * Or instead, you can do:
132  * <code>
133  * timer_stop(1);
134  * </code>
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.
137  *
138  * @since 0.71
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
141  *
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
145  */
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];
151         $timeend = $mtime;
152         $timetotal = $timeend-$timestart;
153         $r = ( function_exists('number_format_i18n') ) ? number_format_i18n($timetotal, $precision) : number_format($timetotal, $precision);
154         if ( $display )
155                 echo $r;
156         return $r;
157 }
158 timer_start();
159
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);
163 } else {
164         error_reporting(E_ALL ^ E_NOTICE ^ E_USER_NOTICE);
165 }
166
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';
170
171 /**
172  * Stores the location of the WordPress directory of functions, classes, and core content.
173  *
174  * @since 1.0.0
175  */
176 define('WPINC', 'wp-includes');
177
178 if ( !defined('LANGDIR') ) {
179         /**
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.
182          *
183          * @since 2.1.0
184          */
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
187         else
188                 define('LANGDIR', WPINC . '/languages'); // no leading slash, no trailing slash
189 }
190
191 /**
192  * Allows for the plugins directory to be moved from the default location.
193  *
194  * This isn't used everywhere. Constant is not used in plugin_basename()
195  * which might cause conflicts with changing this.
196  *
197  * @since 2.1
198  */
199 if ( !defined('PLUGINDIR') )
200         define('PLUGINDIR', 'wp-content/plugins'); // no leading slash, no trailing slash
201
202 require (ABSPATH . WPINC . '/compat.php');
203 require (ABSPATH . WPINC . '/functions.php');
204 require (ABSPATH . WPINC . '/classes.php');
205
206 require_wp_db();
207
208 if ( !empty($wpdb->error) )
209         dead_db();
210
211 $prefix = $wpdb->set_prefix($table_prefix);
212
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.');
215
216 if ( file_exists(ABSPATH . 'wp-content/object-cache.php') )
217         require_once (ABSPATH . 'wp-content/object-cache.php');
218 else
219         require_once (ABSPATH . WPINC . '/cache.php');
220
221 wp_cache_init();
222
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');
228
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';
234         else
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');
238         wp_redirect($link);
239         die(); // have to die here ~ Mark
240 }
241
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');
270
271 if (strpos($_SERVER['PHP_SELF'], 'install.php') === false) {
272         // Used to guarantee unique hash cookies
273         $cookiehash = md5(get_option('siteurl'));
274         /**
275          * Used to guarantee unique hash cookies
276          * @since 1.5
277          */
278         define('COOKIEHASH', $cookiehash);
279 }
280
281 /**
282  * Should be exactly the same as the default value of SECRET_KEY in wp-config-sample.php
283  * @since 2.5
284  */
285 $wp_default_secret_key = 'put your unique phrase here';
286
287 /**
288  * It is possible to define this in wp-config.php
289  * @since 2.0.0
290  */
291 if ( !defined('USER_COOKIE') )
292         define('USER_COOKIE', 'wordpressuser_' . COOKIEHASH);
293
294 /**
295  * It is possible to define this in wp-config.php
296  * @since 2.0.0
297  */
298 if ( !defined('PASS_COOKIE') )
299         define('PASS_COOKIE', 'wordpresspass_' . COOKIEHASH);
300
301 /**
302  * It is possible to define this in wp-config.php
303  * @since 2.5
304  */
305 if ( !defined('AUTH_COOKIE') )
306         define('AUTH_COOKIE', 'wordpress_' . COOKIEHASH);
307
308 /**
309  * It is possible to define this in wp-config.php
310  * @since 2.3.0
311  */
312 if ( !defined('TEST_COOKIE') )
313         define('TEST_COOKIE', 'wordpress_test_cookie');
314
315 /**
316  * It is possible to define this in wp-config.php
317  * @since 1.2.0
318  */
319 if ( !defined('COOKIEPATH') )
320         define('COOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('home') . '/' ) );
321
322 /**
323  * It is possible to define this in wp-config.php
324  * @since 1.5.0
325  */
326 if ( !defined('SITECOOKIEPATH') )
327         define('SITECOOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('siteurl') . '/' ) );
328
329 /**
330  * It is possible to define this in wp-config.php
331  * @since 2.0.0
332  */
333 if ( !defined('COOKIE_DOMAIN') )
334         define('COOKIE_DOMAIN', false);
335         
336 /**
337  * It is possible to define this in wp-config.php
338  * @since 2.5.0
339  */
340 if ( !defined( 'AUTOSAVE_INTERVAL' ) )
341         define( 'AUTOSAVE_INTERVAL', 60 );
342         
343
344 require (ABSPATH . WPINC . '/vars.php');
345
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');
350 }
351
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);
358                 }
359         }
360 }
361
362 require (ABSPATH . WPINC . '/pluggable.php');
363
364 /*
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
367  */
368 if (function_exists('mb_internal_encoding')) {
369         if (!@mb_internal_encoding(get_option('blog_charset')))
370                 mb_internal_encoding('UTF-8');
371 }
372
373
374 if ( defined('WP_CACHE') && function_exists('wp_cache_postload') )
375         wp_cache_postload();
376
377 do_action('plugins_loaded');
378
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);
384 }
385
386 // Escape with wpdb.
387 $_GET    = add_magic_quotes($_GET   );
388 $_POST   = add_magic_quotes($_POST  );
389 $_COOKIE = add_magic_quotes($_COOKIE);
390 $_SERVER = add_magic_quotes($_SERVER);
391
392 do_action('sanitize_comment_cookies');
393
394 /**
395  * WordPress Query object
396  * @global object $wp_the_query
397  * @since 2.0.0
398  */
399 $wp_the_query =& new WP_Query();
400
401 /**
402  * Holds the reference to @see $wp_the_query
403  * Use this global for WordPress queries
404  * @global object $wp_query
405  * @since 1.5.0
406  */
407 $wp_query     =& $wp_the_query;
408
409 /**
410  * Holds the WordPress Rewrite object for creating pretty URLs
411  * @global object $wp_rewrite
412  * @since 1.5.0
413  */
414 $wp_rewrite   =& new WP_Rewrite();
415
416 /**
417  * WordPress Object
418  * @global object $wp
419  * @since 2.0.0
420  */
421 $wp           =& new WP();
422
423
424 /**
425  * Web Path to the current active template directory
426  * @since 1.5
427  */
428 define('TEMPLATEPATH', get_template_directory());
429
430 /**
431  * Web Path to the current active template stylesheet directory
432  * @since 2.1
433  */
434 define('STYLESHEETPATH', get_stylesheet_directory());
435
436 // Load the default text localization domain.
437 load_default_textdomain();
438
439 /**
440  * The locale of the blog
441  * @since 1.5.0
442  */
443 $locale = get_locale();
444 $locale_file = ABSPATH . LANGDIR . "/$locale.php";
445 if ( is_readable($locale_file) )
446         require_once($locale_file);
447
448 // Pull in locale data after loading text domain.
449 require_once(ABSPATH . WPINC . '/locale.php');
450
451 /**
452  * WordPress Locale object for loading locale domain date and various strings.
453  * @global object $wp_locale
454  * @since 2.1.0
455  */
456 $wp_locale =& new WP_Locale();
457
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');
463
464 /**
465  * shutdown_action_hook() - Runs just before PHP shuts down execution.
466  *
467  * @access private
468  * @since 1.2
469  */
470 function shutdown_action_hook() {
471         do_action('shutdown');
472         wp_cache_close();
473 }
474 register_shutdown_function('shutdown_action_hook');
475
476 $wp->init();  // Sets up current user.
477
478 // Everything is loaded and initialized.
479 do_action('init');
480
481 ?>