| [ PHPXref.com ] | [ Generated: Sun Jul 20 01:56:22 2008 ] | [ WordPress 2.6 ] |
| [ Index ] [ Classes ] [ Functions ] [ Variables ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
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( sprintf( /*WP_I18N_OLD_PHP*/'Your server is running PHP version %s but WordPress requires at least 4.3.'/*/WP_I18N_OLD_PHP*/, php_version() ) ); 101 } 102 103 if ( !defined('WP_CONTENT_DIR') ) 104 define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' ); // no trailing slash, full paths only - WP_CONTENT_URL is defined further down 105 106 if ( !extension_loaded('mysql') && !file_exists(WP_CONTENT_DIR . '/db.php') ) 107 die( /*WP_I18N_OLD_MYSQL*/'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.'/*/WP_I18N_OLD_MYSQL*/ ); 108 109 /** 110 * timer_start() - PHP 4 standard microtime start capture 111 * 112 * @access private 113 * @since 0.71 114 * @global int $timestart Seconds and Microseconds added together from when function is called 115 * @return bool Always returns true 116 */ 117 function timer_start() { 118 global $timestart; 119 $mtime = explode(' ', microtime() ); 120 $mtime = $mtime[1] + $mtime[0]; 121 $timestart = $mtime; 122 return true; 123 } 124 125 /** 126 * timer_stop() - Return and/or display the time from the page start to when function is called. 127 * 128 * You can get the results and print them by doing: 129 * <code> 130 * $nTimePageTookToExecute = timer_stop(); 131 * echo $nTimePageTookToExecute; 132 * </code> 133 * 134 * Or instead, you can do: 135 * <code> 136 * timer_stop(1); 137 * </code> 138 * which will do what the above does. If you need the result, you can assign it to a variable, but 139 * most cases, you only need to echo it. 140 * 141 * @since 0.71 142 * @global int $timestart Seconds and Microseconds added together from when timer_start() is called 143 * @global int $timeend Seconds and Microseconds added together from when function is called 144 * 145 * @param int $display Use '0' or null to not echo anything and 1 to echo the total time 146 * @param int $precision The amount of digits from the right of the decimal to display. Default is 3. 147 * @return float The "second.microsecond" finished time calculation 148 */ 149 function timer_stop($display = 0, $precision = 3) { //if called like timer_stop(1), will echo $timetotal 150 global $timestart, $timeend; 151 $mtime = microtime(); 152 $mtime = explode(' ',$mtime); 153 $mtime = $mtime[1] + $mtime[0]; 154 $timeend = $mtime; 155 $timetotal = $timeend-$timestart; 156 $r = ( function_exists('number_format_i18n') ) ? number_format_i18n($timetotal, $precision) : number_format($timetotal, $precision); 157 if ( $display ) 158 echo $r; 159 return $r; 160 } 161 timer_start(); 162 163 // Add define('WP_DEBUG',true); to wp-config.php to enable display of notices during development. 164 if (defined('WP_DEBUG') and WP_DEBUG == true) { 165 error_reporting(E_ALL); 166 } else { 167 error_reporting(E_ALL ^ E_NOTICE ^ E_USER_NOTICE); 168 } 169 170 // For an advanced caching plugin to use, static because you would only want one 171 if ( defined('WP_CACHE') ) 172 @include WP_CONTENT_DIR . '/advanced-cache.php'; 173 174 /** 175 * Stores the location of the WordPress directory of functions, classes, and core content. 176 * 177 * @since 1.0.0 178 */ 179 define('WPINC', 'wp-includes'); 180 181 if ( !defined('WP_LANG_DIR') ) { 182 /** 183 * Stores the location of the language directory. First looks for language folder in WP_CONTENT_DIR 184 * and uses that folder if it exists. Or it uses the "languages" folder in WPINC. 185 * 186 * @since 2.1.0 187 */ 188 if ( file_exists(WP_CONTENT_DIR . '/languages') && @is_dir(WP_CONTENT_DIR . '/languages') ) { 189 define('WP_LANG_DIR', WP_CONTENT_DIR . '/languages'); // no leading slash, no trailing slash, full path, not relative to ABSPATH 190 if (!defined('LANGDIR')) { 191 // Old static relative path maintained for limited backwards compatibility - won't work in some cases 192 define('LANGDIR', 'wp-content/languages'); 193 } 194 } else { 195 define('WP_LANG_DIR', ABSPATH . WPINC . '/languages'); // no leading slash, no trailing slash, full path, not relative to ABSPATH 196 if (!defined('LANGDIR')) { 197 // Old relative path maintained for backwards compatibility 198 define('LANGDIR', WPINC . '/languages'); 199 } 200 } 201 } 202 203 require (ABSPATH . WPINC . '/compat.php'); 204 require (ABSPATH . WPINC . '/functions.php'); 205 require (ABSPATH . WPINC . '/classes.php'); 206 207 require_wp_db(); 208 209 if ( !empty($wpdb->error) ) 210 dead_db(); 211 212 $prefix = $wpdb->set_prefix($table_prefix); 213 214 if ( is_wp_error($prefix) ) 215 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*/); 216 217 if ( file_exists(WP_CONTENT_DIR . '/object-cache.php') ) 218 require_once (WP_CONTENT_DIR . '/object-cache.php'); 219 else 220 require_once (ABSPATH . WPINC . '/cache.php'); 221 222 wp_cache_init(); 223 if ( function_exists('wp_cache_add_global_groups') ) { 224 wp_cache_add_global_groups(array ('users', 'userlogins', 'usermeta')); 225 wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' )); 226 } 227 228 require (ABSPATH . WPINC . '/plugin.php'); 229 require (ABSPATH . WPINC . '/default-filters.php'); 230 include_once(ABSPATH . WPINC . '/streams.php'); 231 include_once(ABSPATH . WPINC . '/gettext.php'); 232 require_once (ABSPATH . WPINC . '/l10n.php'); 233 234 if ( !is_blog_installed() && (strpos($_SERVER['PHP_SELF'], 'install.php') === false && !defined('WP_INSTALLING')) ) { 235 if ( defined('WP_SITEURL') ) 236 $link = WP_SITEURL . '/wp-admin/install.php'; 237 elseif (strpos($_SERVER['PHP_SELF'], 'wp-admin') !== false) 238 $link = preg_replace('|/wp-admin/?.*?$|', '/', $_SERVER['PHP_SELF']) . 'wp-admin/install.php'; 239 else 240 $link = preg_replace('|/[^/]+?$|', '/', $_SERVER['PHP_SELF']) . 'wp-admin/install.php'; 241 require_once(ABSPATH . WPINC . '/kses.php'); 242 require_once(ABSPATH . WPINC . '/pluggable.php'); 243 wp_redirect($link); 244 die(); // have to die here ~ Mark 245 } 246 247 require (ABSPATH . WPINC . '/formatting.php'); 248 require (ABSPATH . WPINC . '/capabilities.php'); 249 require (ABSPATH . WPINC . '/query.php'); 250 require (ABSPATH . WPINC . '/theme.php'); 251 require (ABSPATH . WPINC . '/user.php'); 252 require (ABSPATH . WPINC . '/general-template.php'); 253 require (ABSPATH . WPINC . '/link-template.php'); 254 require (ABSPATH . WPINC . '/author-template.php'); 255 require (ABSPATH . WPINC . '/post.php'); 256 require (ABSPATH . WPINC . '/post-template.php'); 257 require (ABSPATH . WPINC . '/category.php'); 258 require (ABSPATH . WPINC . '/category-template.php'); 259 require (ABSPATH . WPINC . '/comment.php'); 260 require (ABSPATH . WPINC . '/comment-template.php'); 261 require (ABSPATH . WPINC . '/rewrite.php'); 262 require (ABSPATH . WPINC . '/feed.php'); 263 require (ABSPATH . WPINC . '/bookmark.php'); 264 require (ABSPATH . WPINC . '/bookmark-template.php'); 265 require (ABSPATH . WPINC . '/kses.php'); 266 require (ABSPATH . WPINC . '/cron.php'); 267 require (ABSPATH . WPINC . '/version.php'); 268 require (ABSPATH . WPINC . '/deprecated.php'); 269 require (ABSPATH . WPINC . '/script-loader.php'); 270 require (ABSPATH . WPINC . '/taxonomy.php'); 271 require (ABSPATH . WPINC . '/update.php'); 272 require (ABSPATH . WPINC . '/canonical.php'); 273 require (ABSPATH . WPINC . '/shortcodes.php'); 274 require (ABSPATH . WPINC . '/media.php'); 275 276 if ( !defined('WP_CONTENT_URL') ) 277 define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content'); // full url - WP_CONTENT_DIR is defined further up 278 279 /** 280 * Allows for the plugins directory to be moved from the default location. 281 * 282 * @since 2.6 283 */ 284 if ( !defined('WP_PLUGIN_DIR') ) 285 define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' ); // full path, no trailing slash 286 if ( !defined('WP_PLUGIN_URL') ) 287 define( 'WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins' ); // full url, no trailing slash 288 if ( !defined('PLUGINDIR') ) 289 define( 'PLUGINDIR', 'wp-content/plugins' ); // Relative to ABSPATH. For back compat. 290 291 if ( ! defined('WP_INSTALLING') ) { 292 // Used to guarantee unique hash cookies 293 $cookiehash = md5(get_option('siteurl')); 294 /** 295 * Used to guarantee unique hash cookies 296 * @since 1.5 297 */ 298 define('COOKIEHASH', $cookiehash); 299 } 300 301 /** 302 * Should be exactly the same as the default value of SECRET_KEY in wp-config-sample.php 303 * @since 2.5 304 */ 305 $wp_default_secret_key = 'put your unique phrase here'; 306 307 /** 308 * It is possible to define this in wp-config.php 309 * @since 2.0.0 310 */ 311 if ( !defined('USER_COOKIE') ) 312 define('USER_COOKIE', 'wordpressuser_' . COOKIEHASH); 313 314 /** 315 * It is possible to define this in wp-config.php 316 * @since 2.0.0 317 */ 318 if ( !defined('PASS_COOKIE') ) 319 define('PASS_COOKIE', 'wordpresspass_' . COOKIEHASH); 320 321 /** 322 * It is possible to define this in wp-config.php 323 * @since 2.5 324 */ 325 if ( !defined('AUTH_COOKIE') ) 326 define('AUTH_COOKIE', 'wordpress_' . COOKIEHASH); 327 328 /** 329 * It is possible to define this in wp-config.php 330 * @since 2.6 331 */ 332 if ( !defined('SECURE_AUTH_COOKIE') ) 333 define('SECURE_AUTH_COOKIE', 'wordpress_sec_' . COOKIEHASH); 334 335 /** 336 * It is possible to define this in wp-config.php 337 * @since 2.6 338 */ 339 if ( !defined('LOGGED_IN_COOKIE') ) 340 define('LOGGED_IN_COOKIE', 'wordpress_logged_in_' . COOKIEHASH); 341 342 /** 343 * It is possible to define this in wp-config.php 344 * @since 2.3.0 345 */ 346 if ( !defined('TEST_COOKIE') ) 347 define('TEST_COOKIE', 'wordpress_test_cookie'); 348 349 /** 350 * It is possible to define this in wp-config.php 351 * @since 1.2.0 352 */ 353 if ( !defined('COOKIEPATH') ) 354 define('COOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('home') . '/' ) ); 355 356 /** 357 * It is possible to define this in wp-config.php 358 * @since 1.5.0 359 */ 360 if ( !defined('SITECOOKIEPATH') ) 361 define('SITECOOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('siteurl') . '/' ) ); 362 363 /** 364 * It is possible to define this in wp-config.php 365 * @since 2.6 366 */ 367 if ( !defined('ADMIN_COOKIE_PATH') ) 368 define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH . 'wp-admin' ); 369 370 /** 371 * It is possible to define this in wp-config.php 372 * @since 2.6 373 */ 374 if ( !defined('PLUGINS_COOKIE_PATH') ) 375 define( 'PLUGINS_COOKIE_PATH', preg_replace('|https?://[^/]+|i', '', WP_PLUGIN_URL) ); 376 377 /** 378 * It is possible to define this in wp-config.php 379 * @since 2.0.0 380 */ 381 if ( !defined('COOKIE_DOMAIN') ) 382 define('COOKIE_DOMAIN', false); 383 384 /** 385 * It is possible to define this in wp-config.php 386 * @since 2.6 387 */ 388 if ( !defined('FORCE_SSL_ADMIN') ) 389 define('FORCE_SSL_ADMIN', false); 390 force_ssl_admin(FORCE_SSL_ADMIN); 391 392 /** 393 * It is possible to define this in wp-config.php 394 * @since 2.6 395 */ 396 if ( !defined('FORCE_SSL_LOGIN') ) 397 define('FORCE_SSL_LOGIN', false); 398 force_ssl_login(FORCE_SSL_LOGIN); 399 400 /** 401 * It is possible to define this in wp-config.php 402 * @since 2.5.0 403 */ 404 if ( !defined( 'AUTOSAVE_INTERVAL' ) ) 405 define( 'AUTOSAVE_INTERVAL', 60 ); 406 407 408 require (ABSPATH . WPINC . '/vars.php'); 409 410 // Check for hacks file if the option is enabled 411 if (get_option('hack_file')) { 412 if (file_exists(ABSPATH . 'my-hacks.php')) 413 require(ABSPATH . 'my-hacks.php'); 414 } 415 416 if ( get_option('active_plugins') ) { 417 $current_plugins = get_option('active_plugins'); 418 if ( is_array($current_plugins) ) { 419 foreach ($current_plugins as $plugin) { 420 if ('' != $plugin && file_exists(WP_PLUGIN_DIR . '/' . $plugin)) 421 include_once(WP_PLUGIN_DIR . '/' . $plugin); 422 } 423 } 424 } 425 426 require (ABSPATH . WPINC . '/pluggable.php'); 427 428 /* 429 * In most cases the default internal encoding is latin1, which is of no use, 430 * since we want to use the mb_ functions for utf-8 strings 431 */ 432 if (function_exists('mb_internal_encoding')) { 433 if (!@mb_internal_encoding(get_option('blog_charset'))) 434 mb_internal_encoding('UTF-8'); 435 } 436 437 438 if ( defined('WP_CACHE') && function_exists('wp_cache_postload') ) 439 wp_cache_postload(); 440 441 do_action('plugins_loaded'); 442 443 $default_constants = array( 'WP_POST_REVISIONS' => true ); 444 foreach ( $default_constants as $c => $v ) 445 @define( $c, $v ); // will fail if the constant is already defined 446 unset($default_constants, $c, $v); 447 448 // If already slashed, strip. 449 if ( get_magic_quotes_gpc() ) { 450 $_GET = stripslashes_deep($_GET ); 451 $_POST = stripslashes_deep($_POST ); 452 $_COOKIE = stripslashes_deep($_COOKIE); 453 } 454 455 // Escape with wpdb. 456 $_GET = add_magic_quotes($_GET ); 457 $_POST = add_magic_quotes($_POST ); 458 $_COOKIE = add_magic_quotes($_COOKIE); 459 $_SERVER = add_magic_quotes($_SERVER); 460 461 do_action('sanitize_comment_cookies'); 462 463 /** 464 * WordPress Query object 465 * @global object $wp_the_query 466 * @since 2.0.0 467 */ 468 $wp_the_query =& new WP_Query(); 469 470 /** 471 * Holds the reference to @see $wp_the_query 472 * Use this global for WordPress queries 473 * @global object $wp_query 474 * @since 1.5.0 475 */ 476 $wp_query =& $wp_the_query; 477 478 /** 479 * Holds the WordPress Rewrite object for creating pretty URLs 480 * @global object $wp_rewrite 481 * @since 1.5.0 482 */ 483 $wp_rewrite =& new WP_Rewrite(); 484 485 /** 486 * WordPress Object 487 * @global object $wp 488 * @since 2.0.0 489 */ 490 $wp =& new WP(); 491 492 do_action('setup_theme'); 493 494 /** 495 * Web Path to the current active template directory 496 * @since 1.5 497 */ 498 define('TEMPLATEPATH', get_template_directory()); 499 500 /** 501 * Web Path to the current active template stylesheet directory 502 * @since 2.1 503 */ 504 define('STYLESHEETPATH', get_stylesheet_directory()); 505 506 // Load the default text localization domain. 507 load_default_textdomain(); 508 509 /** 510 * The locale of the blog 511 * @since 1.5.0 512 */ 513 $locale = get_locale(); 514 $locale_file = WP_LANG_DIR . "/$locale.php"; 515 if ( is_readable($locale_file) ) 516 require_once($locale_file); 517 518 // Pull in locale data after loading text domain. 519 require_once(ABSPATH . WPINC . '/locale.php'); 520 521 /** 522 * WordPress Locale object for loading locale domain date and various strings. 523 * @global object $wp_locale 524 * @since 2.1.0 525 */ 526 $wp_locale =& new WP_Locale(); 527 528 // Load functions for active theme. 529 if ( TEMPLATEPATH !== STYLESHEETPATH && file_exists(STYLESHEETPATH . '/functions.php') ) 530 include(STYLESHEETPATH . '/functions.php'); 531 if ( file_exists(TEMPLATEPATH . '/functions.php') ) 532 include(TEMPLATEPATH . '/functions.php'); 533 534 /** 535 * shutdown_action_hook() - Runs just before PHP shuts down execution. 536 * 537 * @access private 538 * @since 1.2 539 */ 540 function shutdown_action_hook() { 541 do_action('shutdown'); 542 wp_cache_close(); 543 } 544 register_shutdown_function('shutdown_action_hook'); 545 546 $wp->init(); // Sets up current user. 547 548 // Everything is loaded and initialized. 549 do_action('init'); 550 551 ?>