PageRenderTime 61ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-includes/load.php

https://github.com/dipakdotyadav/WordPress
PHP | 762 lines | 357 code | 90 blank | 315 comment | 114 complexity | 98d18350e2b66c58f87100cc06dd6557 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. /**
  3. * These functions are needed to load WordPress.
  4. *
  5. * @internal This file must be parsable by PHP4.
  6. *
  7. * @package WordPress
  8. */
  9. /**
  10. * Turn register globals off.
  11. *
  12. * @access private
  13. * @since 2.1.0
  14. * @return null Will return null if register_globals PHP directive was disabled
  15. */
  16. function wp_unregister_GLOBALS() {
  17. if ( !ini_get( 'register_globals' ) )
  18. return;
  19. if ( isset( $_REQUEST['GLOBALS'] ) )
  20. die( 'GLOBALS overwrite attempt detected' );
  21. // Variables that shouldn't be unset
  22. $no_unset = array( 'GLOBALS', '_GET', '_POST', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES', 'table_prefix' );
  23. $input = array_merge( $_GET, $_POST, $_COOKIE, $_SERVER, $_ENV, $_FILES, isset( $_SESSION ) && is_array( $_SESSION ) ? $_SESSION : array() );
  24. foreach ( $input as $k => $v )
  25. if ( !in_array( $k, $no_unset ) && isset( $GLOBALS[$k] ) ) {
  26. $GLOBALS[$k] = null;
  27. unset( $GLOBALS[$k] );
  28. }
  29. }
  30. /**
  31. * Fix $_SERVER variables for various setups.
  32. *
  33. * @access private
  34. * @since 3.0.0
  35. */
  36. function wp_fix_server_vars() {
  37. global $PHP_SELF;
  38. $default_server_values = array(
  39. 'SERVER_SOFTWARE' => '',
  40. 'REQUEST_URI' => '',
  41. );
  42. $_SERVER = array_merge( $default_server_values, $_SERVER );
  43. // Fix for IIS when running with PHP ISAPI
  44. if ( empty( $_SERVER['REQUEST_URI'] ) || ( php_sapi_name() != 'cgi-fcgi' && preg_match( '/^Microsoft-IIS\//', $_SERVER['SERVER_SOFTWARE'] ) ) ) {
  45. // IIS Mod-Rewrite
  46. if ( isset( $_SERVER['HTTP_X_ORIGINAL_URL'] ) ) {
  47. $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
  48. }
  49. // IIS Isapi_Rewrite
  50. else if ( isset( $_SERVER['HTTP_X_REWRITE_URL'] ) ) {
  51. $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
  52. } else {
  53. // Use ORIG_PATH_INFO if there is no PATH_INFO
  54. if ( !isset( $_SERVER['PATH_INFO'] ) && isset( $_SERVER['ORIG_PATH_INFO'] ) )
  55. $_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'];
  56. // Some IIS + PHP configurations puts the script-name in the path-info (No need to append it twice)
  57. if ( isset( $_SERVER['PATH_INFO'] ) ) {
  58. if ( $_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME'] )
  59. $_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'];
  60. else
  61. $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO'];
  62. }
  63. // Append the query string if it exists and isn't null
  64. if ( ! empty( $_SERVER['QUERY_STRING'] ) ) {
  65. $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
  66. }
  67. }
  68. }
  69. // Fix for PHP as CGI hosts that set SCRIPT_FILENAME to something ending in php.cgi for all requests
  70. if ( isset( $_SERVER['SCRIPT_FILENAME'] ) && ( strpos( $_SERVER['SCRIPT_FILENAME'], 'php.cgi' ) == strlen( $_SERVER['SCRIPT_FILENAME'] ) - 7 ) )
  71. $_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED'];
  72. // Fix for Dreamhost and other PHP as CGI hosts
  73. if ( strpos( $_SERVER['SCRIPT_NAME'], 'php.cgi' ) !== false )
  74. unset( $_SERVER['PATH_INFO'] );
  75. // Fix empty PHP_SELF
  76. $PHP_SELF = $_SERVER['PHP_SELF'];
  77. if ( empty( $PHP_SELF ) )
  78. $_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace( '/(\?.*)?$/', '', $_SERVER["REQUEST_URI"] );
  79. }
  80. /**
  81. * Check for the required PHP version, and the MySQL extension or a database drop-in.
  82. *
  83. * Dies if requirements are not met.
  84. *
  85. * @access private
  86. * @since 3.0.0
  87. */
  88. function wp_check_php_mysql_versions() {
  89. global $required_php_version, $wp_version;
  90. $php_version = phpversion();
  91. if ( version_compare( $required_php_version, $php_version, '>' ) ) {
  92. wp_load_translations_early();
  93. die( sprintf( __( 'Your server is running PHP version %1$s but WordPress %2$s requires at least %3$s.' ), $php_version, $wp_version, $required_php_version ) );
  94. }
  95. if ( ! extension_loaded( 'mysql' ) && ! file_exists( WP_CONTENT_DIR . '/db.php' ) ) {
  96. wp_load_translations_early();
  97. die( __( 'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.' ) );
  98. }
  99. }
  100. /**
  101. * Don't load all of WordPress when handling a favicon.ico request.
  102. * Instead, send the headers for a zero-length favicon and bail.
  103. *
  104. * @since 3.0.0
  105. */
  106. function wp_favicon_request() {
  107. if ( '/favicon.ico' == $_SERVER['REQUEST_URI'] ) {
  108. header('Content-Type: image/vnd.microsoft.icon');
  109. header('Content-Length: 0');
  110. exit;
  111. }
  112. }
  113. /**
  114. * Dies with a maintenance message when conditions are met.
  115. *
  116. * Checks for a file in the WordPress root directory named ".maintenance".
  117. * This file will contain the variable $upgrading, set to the time the file
  118. * was created. If the file was created less than 10 minutes ago, WordPress
  119. * enters maintenance mode and displays a message.
  120. *
  121. * The default message can be replaced by using a drop-in (maintenance.php in
  122. * the wp-content directory).
  123. *
  124. * @access private
  125. * @since 3.0.0
  126. */
  127. function wp_maintenance() {
  128. if ( !file_exists( ABSPATH . '.maintenance' ) || defined( 'WP_INSTALLING' ) )
  129. return;
  130. global $upgrading;
  131. include( ABSPATH . '.maintenance' );
  132. // If the $upgrading timestamp is older than 10 minutes, don't die.
  133. if ( ( time() - $upgrading ) >= 600 )
  134. return;
  135. if ( file_exists( WP_CONTENT_DIR . '/maintenance.php' ) ) {
  136. require_once( WP_CONTENT_DIR . '/maintenance.php' );
  137. die();
  138. }
  139. wp_load_translations_early();
  140. $protocol = $_SERVER["SERVER_PROTOCOL"];
  141. if ( 'HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol )
  142. $protocol = 'HTTP/1.0';
  143. header( "$protocol 503 Service Unavailable", true, 503 );
  144. header( 'Content-Type: text/html; charset=utf-8' );
  145. header( 'Retry-After: 600' );
  146. ?>
  147. <!DOCTYPE html>
  148. <html xmlns="http://www.w3.org/1999/xhtml"<?php if ( is_rtl() ) echo ' dir="rtl"'; ?>>
  149. <head>
  150. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  151. <title><?php _e( 'Maintenance' ); ?></title>
  152. </head>
  153. <body>
  154. <h1><?php _e( 'Briefly unavailable for scheduled maintenance. Check back in a minute.' ); ?></h1>
  155. </body>
  156. </html>
  157. <?php
  158. die();
  159. }
  160. /**
  161. * PHP 5 standard microtime start capture.
  162. *
  163. * @access private
  164. * @since 0.71
  165. * @global float $timestart Seconds from when function is called.
  166. * @return bool Always returns true.
  167. */
  168. function timer_start() {
  169. global $timestart;
  170. $timestart = microtime( true );
  171. return true;
  172. }
  173. /**
  174. * Return and/or display the time from the page start to when function is called.
  175. *
  176. * You can get the results and print them by doing:
  177. * <code>
  178. * $nTimePageTookToExecute = timer_stop();
  179. * echo $nTimePageTookToExecute;
  180. * </code>
  181. *
  182. * Or instead, you can do:
  183. * <code>
  184. * timer_stop(1);
  185. * </code>
  186. * which will do what the above does. If you need the result, you can assign it to a variable, but
  187. * in most cases, you only need to echo it.
  188. *
  189. * @since 0.71
  190. * @global float $timestart Seconds from when timer_start() is called
  191. * @global float $timeend Seconds from when function is called
  192. *
  193. * @param int $display Use '0' or null to not echo anything and 1 to echo the total time
  194. * @param int $precision The amount of digits from the right of the decimal to display. Default is 3.
  195. * @return float The "second.microsecond" finished time calculation
  196. */
  197. function timer_stop( $display = 0, $precision = 3 ) { // if called like timer_stop(1), will echo $timetotal
  198. global $timestart, $timeend;
  199. $timeend = microtime( true );
  200. $timetotal = $timeend - $timestart;
  201. $r = ( function_exists( 'number_format_i18n' ) ) ? number_format_i18n( $timetotal, $precision ) : number_format( $timetotal, $precision );
  202. if ( $display )
  203. echo $r;
  204. return $r;
  205. }
  206. /**
  207. * Sets PHP error handling and handles WordPress debug mode.
  208. *
  209. * Uses three constants: WP_DEBUG, WP_DEBUG_DISPLAY, and WP_DEBUG_LOG. All three can be
  210. * defined in wp-config.php. Example: <code> define( 'WP_DEBUG', true ); </code>
  211. *
  212. * WP_DEBUG_DISPLAY and WP_DEBUG_LOG perform no function unless WP_DEBUG is true.
  213. * WP_DEBUG defaults to false.
  214. *
  215. * When WP_DEBUG is true, all PHP notices are reported. WordPress will also display
  216. * notices, including one when a deprecated WordPress function, function argument,
  217. * or file is used. Deprecated code may be removed from a later version.
  218. *
  219. * It is strongly recommended that plugin and theme developers use WP_DEBUG in their
  220. * development environments.
  221. *
  222. * When WP_DEBUG_DISPLAY is true, WordPress will force errors to be displayed.
  223. * WP_DEBUG_DISPLAY defaults to true. Defining it as null prevents WordPress from
  224. * changing the global configuration setting. Defining WP_DEBUG_DISPLAY as false
  225. * will force errors to be hidden.
  226. *
  227. * When WP_DEBUG_LOG is true, errors will be logged to wp-content/debug.log.
  228. * WP_DEBUG_LOG defaults to false.
  229. *
  230. * @access private
  231. * @since 3.0.0
  232. */
  233. function wp_debug_mode() {
  234. if ( WP_DEBUG ) {
  235. // E_DEPRECATED is a core PHP constant in PHP 5.3. Don't define this yourself.
  236. // The two statements are equivalent, just one is for 5.3+ and for less than 5.3.
  237. if ( defined( 'E_DEPRECATED' ) )
  238. error_reporting( E_ALL & ~E_DEPRECATED & ~E_STRICT );
  239. else
  240. error_reporting( E_ALL );
  241. if ( WP_DEBUG_DISPLAY )
  242. ini_set( 'display_errors', 1 );
  243. elseif ( null !== WP_DEBUG_DISPLAY )
  244. ini_set( 'display_errors', 0 );
  245. if ( WP_DEBUG_LOG ) {
  246. ini_set( 'log_errors', 1 );
  247. ini_set( 'error_log', WP_CONTENT_DIR . '/debug.log' );
  248. }
  249. } else {
  250. error_reporting( E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR );
  251. }
  252. }
  253. /**
  254. * Sets the location of the language directory.
  255. *
  256. * To set directory manually, define <code>WP_LANG_DIR</code> in wp-config.php.
  257. *
  258. * If the language directory exists within WP_CONTENT_DIR, that is used.
  259. * Otherwise if the language directory exists within WPINC, that's used.
  260. * Finally, if neither of the preceding directories are found,
  261. * WP_CONTENT_DIR/languages is used.
  262. *
  263. * The WP_LANG_DIR constant was introduced in 2.1.0.
  264. *
  265. * @access private
  266. * @since 3.0.0
  267. */
  268. function wp_set_lang_dir() {
  269. if ( !defined( 'WP_LANG_DIR' ) ) {
  270. if ( file_exists( WP_CONTENT_DIR . '/languages' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) || !@is_dir(ABSPATH . WPINC . '/languages') ) {
  271. define( 'WP_LANG_DIR', WP_CONTENT_DIR . '/languages' ); // no leading slash, no trailing slash, full path, not relative to ABSPATH
  272. if ( !defined( 'LANGDIR' ) ) {
  273. // Old static relative path maintained for limited backwards compatibility - won't work in some cases
  274. define( 'LANGDIR', 'wp-content/languages' );
  275. }
  276. } else {
  277. define( 'WP_LANG_DIR', ABSPATH . WPINC . '/languages' ); // no leading slash, no trailing slash, full path, not relative to ABSPATH
  278. if ( !defined( 'LANGDIR' ) ) {
  279. // Old relative path maintained for backwards compatibility
  280. define( 'LANGDIR', WPINC . '/languages' );
  281. }
  282. }
  283. }
  284. }
  285. /**
  286. * Load the correct database class file.
  287. *
  288. * This function is used to load the database class file either at runtime or by
  289. * wp-admin/setup-config.php. We must globalize $wpdb to ensure that it is
  290. * defined globally by the inline code in wp-db.php.
  291. *
  292. * @since 2.5.0
  293. * @global $wpdb WordPress Database Object
  294. */
  295. function require_wp_db() {
  296. global $wpdb;
  297. require_once( ABSPATH . WPINC . '/wp-db.php' );
  298. if ( file_exists( WP_CONTENT_DIR . '/db.php' ) )
  299. require_once( WP_CONTENT_DIR . '/db.php' );
  300. if ( isset( $wpdb ) )
  301. return;
  302. $wpdb = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST );
  303. }
  304. /**
  305. * Sets the database table prefix and the format specifiers for database table columns.
  306. *
  307. * Columns not listed here default to %s.
  308. *
  309. * @see wpdb::$field_types Since 2.8.0
  310. * @see wpdb::prepare()
  311. * @see wpdb::insert()
  312. * @see wpdb::update()
  313. * @see wpdb::set_prefix()
  314. *
  315. * @access private
  316. * @since 3.0.0
  317. */
  318. function wp_set_wpdb_vars() {
  319. global $wpdb, $table_prefix;
  320. if ( !empty( $wpdb->error ) )
  321. dead_db();
  322. $wpdb->field_types = array( 'post_author' => '%d', 'post_parent' => '%d', 'menu_order' => '%d', 'term_id' => '%d', 'term_group' => '%d', 'term_taxonomy_id' => '%d',
  323. 'parent' => '%d', 'count' => '%d','object_id' => '%d', 'term_order' => '%d', 'ID' => '%d', 'comment_ID' => '%d', 'comment_post_ID' => '%d', 'comment_parent' => '%d',
  324. 'user_id' => '%d', 'link_id' => '%d', 'link_owner' => '%d', 'link_rating' => '%d', 'option_id' => '%d', 'blog_id' => '%d', 'meta_id' => '%d', 'post_id' => '%d',
  325. 'user_status' => '%d', 'umeta_id' => '%d', 'comment_karma' => '%d', 'comment_count' => '%d',
  326. // multisite:
  327. 'active' => '%d', 'cat_id' => '%d', 'deleted' => '%d', 'lang_id' => '%d', 'mature' => '%d', 'public' => '%d', 'site_id' => '%d', 'spam' => '%d',
  328. );
  329. $prefix = $wpdb->set_prefix( $table_prefix );
  330. if ( is_wp_error( $prefix ) ) {
  331. wp_load_translations_early();
  332. wp_die( __( '<strong>ERROR</strong>: <code>$table_prefix</code> in <code>wp-config.php</code> can only contain numbers, letters, and underscores.' ) );
  333. }
  334. }
  335. /**
  336. * Starts the WordPress object cache.
  337. *
  338. * If an object-cache.php file exists in the wp-content directory,
  339. * it uses that drop-in as an external object cache.
  340. *
  341. * @access private
  342. * @since 3.0.0
  343. */
  344. function wp_start_object_cache() {
  345. global $_wp_using_ext_object_cache, $blog_id;
  346. $first_init = false;
  347. if ( ! function_exists( 'wp_cache_init' ) ) {
  348. if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
  349. require_once ( WP_CONTENT_DIR . '/object-cache.php' );
  350. $_wp_using_ext_object_cache = true;
  351. } else {
  352. require_once ( ABSPATH . WPINC . '/cache.php' );
  353. $_wp_using_ext_object_cache = false;
  354. }
  355. $first_init = true;
  356. } else if ( !$_wp_using_ext_object_cache && file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
  357. // Sometimes advanced-cache.php can load object-cache.php before it is loaded here.
  358. // This breaks the function_exists check above and can result in $_wp_using_ext_object_cache
  359. // being set incorrectly. Double check if an external cache exists.
  360. $_wp_using_ext_object_cache = true;
  361. }
  362. // If cache supports reset, reset instead of init if already initialized.
  363. // Reset signals to the cache that global IDs have changed and it may need to update keys
  364. // and cleanup caches.
  365. if ( ! $first_init && function_exists( 'wp_cache_switch_to_blog' ) )
  366. wp_cache_switch_to_blog( $blog_id );
  367. else
  368. wp_cache_init();
  369. if ( function_exists( 'wp_cache_add_global_groups' ) ) {
  370. wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache' ) );
  371. wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) );
  372. }
  373. }
  374. /**
  375. * Redirects to the installer if WordPress is not installed.
  376. *
  377. * Dies with an error message when multisite is enabled.
  378. *
  379. * @access private
  380. * @since 3.0.0
  381. */
  382. function wp_not_installed() {
  383. if ( is_multisite() ) {
  384. if ( ! is_blog_installed() && ! defined( 'WP_INSTALLING' ) )
  385. wp_die( __( 'The site you have requested is not installed properly. Please contact the system administrator.' ) );
  386. } elseif ( ! is_blog_installed() && false === strpos( $_SERVER['PHP_SELF'], 'install.php' ) && !defined( 'WP_INSTALLING' ) ) {
  387. $link = wp_guess_url() . '/wp-admin/install.php';
  388. require( ABSPATH . WPINC . '/kses.php' );
  389. require( ABSPATH . WPINC . '/pluggable.php' );
  390. require( ABSPATH . WPINC . '/formatting.php' );
  391. wp_redirect( $link );
  392. die();
  393. }
  394. }
  395. /**
  396. * Returns array of must-use plugin files to be included in global scope.
  397. *
  398. * The default directory is wp-content/mu-plugins. To change the default directory
  399. * manually, define <code>WPMU_PLUGIN_DIR</code> and <code>WPMU_PLUGIN_URL</code>
  400. * in wp-config.php.
  401. *
  402. * @access private
  403. * @since 3.0.0
  404. * @return array Files to include
  405. */
  406. function wp_get_mu_plugins() {
  407. $mu_plugins = array();
  408. if ( !is_dir( WPMU_PLUGIN_DIR ) )
  409. return $mu_plugins;
  410. if ( ! $dh = opendir( WPMU_PLUGIN_DIR ) )
  411. return $mu_plugins;
  412. while ( ( $plugin = readdir( $dh ) ) !== false ) {
  413. if ( substr( $plugin, -4 ) == '.php' )
  414. $mu_plugins[] = WPMU_PLUGIN_DIR . '/' . $plugin;
  415. }
  416. closedir( $dh );
  417. sort( $mu_plugins );
  418. return $mu_plugins;
  419. }
  420. /**
  421. * Returns array of plugin files to be included in global scope.
  422. *
  423. * The default directory is wp-content/plugins. To change the default directory
  424. * manually, define <code>WP_PLUGIN_DIR</code> and <code>WP_PLUGIN_URL</code>
  425. * in wp-config.php.
  426. *
  427. * @access private
  428. * @since 3.0.0
  429. * @return array Files to include
  430. */
  431. function wp_get_active_and_valid_plugins() {
  432. $plugins = array();
  433. $active_plugins = (array) get_option( 'active_plugins', array() );
  434. // Check for hacks file if the option is enabled
  435. if ( get_option( 'hack_file' ) && file_exists( ABSPATH . 'my-hacks.php' ) ) {
  436. _deprecated_file( 'my-hacks.php', '1.5' );
  437. array_unshift( $plugins, ABSPATH . 'my-hacks.php' );
  438. }
  439. if ( empty( $active_plugins ) || defined( 'WP_INSTALLING' ) )
  440. return $plugins;
  441. $network_plugins = is_multisite() ? wp_get_active_network_plugins() : false;
  442. foreach ( $active_plugins as $plugin ) {
  443. if ( ! validate_file( $plugin ) // $plugin must validate as file
  444. && '.php' == substr( $plugin, -4 ) // $plugin must end with '.php'
  445. && file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist
  446. // not already included as a network plugin
  447. && ( ! $network_plugins || ! in_array( WP_PLUGIN_DIR . '/' . $plugin, $network_plugins ) )
  448. )
  449. $plugins[] = WP_PLUGIN_DIR . '/' . $plugin;
  450. }
  451. return $plugins;
  452. }
  453. /**
  454. * Sets internal encoding using mb_internal_encoding().
  455. *
  456. * In most cases the default internal encoding is latin1, which is of no use,
  457. * since we want to use the mb_ functions for utf-8 strings.
  458. *
  459. * @access private
  460. * @since 3.0.0
  461. */
  462. function wp_set_internal_encoding() {
  463. if ( function_exists( 'mb_internal_encoding' ) ) {
  464. $charset = get_option( 'blog_charset' );
  465. if ( ! $charset || ! @mb_internal_encoding( $charset ) )
  466. mb_internal_encoding( 'UTF-8' );
  467. }
  468. }
  469. /**
  470. * Add magic quotes to $_GET, $_POST, $_COOKIE, and $_SERVER.
  471. *
  472. * Also forces $_REQUEST to be $_GET + $_POST. If $_SERVER, $_COOKIE,
  473. * or $_ENV are needed, use those superglobals directly.
  474. *
  475. * @access private
  476. * @since 3.0.0
  477. */
  478. function wp_magic_quotes() {
  479. // If already slashed, strip.
  480. if ( get_magic_quotes_gpc() ) {
  481. $_GET = stripslashes_deep( $_GET );
  482. $_POST = stripslashes_deep( $_POST );
  483. $_COOKIE = stripslashes_deep( $_COOKIE );
  484. }
  485. // Escape with wpdb.
  486. $_GET = add_magic_quotes( $_GET );
  487. $_POST = add_magic_quotes( $_POST );
  488. $_COOKIE = add_magic_quotes( $_COOKIE );
  489. $_SERVER = add_magic_quotes( $_SERVER );
  490. // Force REQUEST to be GET + POST.
  491. $_REQUEST = array_merge( $_GET, $_POST );
  492. }
  493. /**
  494. * Runs just before PHP shuts down execution.
  495. *
  496. * @access private
  497. * @since 1.2.0
  498. */
  499. function shutdown_action_hook() {
  500. do_action( 'shutdown' );
  501. wp_cache_close();
  502. }
  503. /**
  504. * Copy an object.
  505. *
  506. * @since 2.7.0
  507. * @deprecated 3.2
  508. *
  509. * @param object $object The object to clone
  510. * @return object The cloned object
  511. */
  512. function wp_clone( $object ) {
  513. // Use parens for clone to accommodate PHP 4. See #17880
  514. return clone( $object );
  515. }
  516. /**
  517. * Whether the current request is for a network or blog admin page
  518. *
  519. * Does not inform on whether the user is an admin! Use capability checks to
  520. * tell if the user should be accessing a section or not.
  521. *
  522. * @since 1.5.1
  523. *
  524. * @return bool True if inside WordPress administration pages.
  525. */
  526. function is_admin() {
  527. if ( isset( $GLOBALS['current_screen'] ) )
  528. return $GLOBALS['current_screen']->in_admin();
  529. elseif ( defined( 'WP_ADMIN' ) )
  530. return WP_ADMIN;
  531. return false;
  532. }
  533. /**
  534. * Whether the current request is for a blog admin screen /wp-admin/
  535. *
  536. * Does not inform on whether the user is a blog admin! Use capability checks to
  537. * tell if the user should be accessing a section or not.
  538. *
  539. * @since 3.1.0
  540. *
  541. * @return bool True if inside WordPress network administration pages.
  542. */
  543. function is_blog_admin() {
  544. if ( isset( $GLOBALS['current_screen'] ) )
  545. return $GLOBALS['current_screen']->in_admin( 'site' );
  546. elseif ( defined( 'WP_BLOG_ADMIN' ) )
  547. return WP_BLOG_ADMIN;
  548. return false;
  549. }
  550. /**
  551. * Whether the current request is for a network admin screen /wp-admin/network/
  552. *
  553. * Does not inform on whether the user is a network admin! Use capability checks to
  554. * tell if the user should be accessing a section or not.
  555. *
  556. * @since 3.1.0
  557. *
  558. * @return bool True if inside WordPress network administration pages.
  559. */
  560. function is_network_admin() {
  561. if ( isset( $GLOBALS['current_screen'] ) )
  562. return $GLOBALS['current_screen']->in_admin( 'network' );
  563. elseif ( defined( 'WP_NETWORK_ADMIN' ) )
  564. return WP_NETWORK_ADMIN;
  565. return false;
  566. }
  567. /**
  568. * Whether the current request is for a user admin screen /wp-admin/user/
  569. *
  570. * Does not inform on whether the user is an admin! Use capability checks to
  571. * tell if the user should be accessing a section or not.
  572. *
  573. * @since 3.1.0
  574. *
  575. * @return bool True if inside WordPress user administration pages.
  576. */
  577. function is_user_admin() {
  578. if ( isset( $GLOBALS['current_screen'] ) )
  579. return $GLOBALS['current_screen']->in_admin( 'user' );
  580. elseif ( defined( 'WP_USER_ADMIN' ) )
  581. return WP_USER_ADMIN;
  582. return false;
  583. }
  584. /**
  585. * Whether Multisite support is enabled
  586. *
  587. * @since 3.0.0
  588. *
  589. * @return bool True if multisite is enabled, false otherwise.
  590. */
  591. function is_multisite() {
  592. if ( defined( 'MULTISITE' ) )
  593. return MULTISITE;
  594. if ( defined( 'SUBDOMAIN_INSTALL' ) || defined( 'VHOST' ) || defined( 'SUNRISE' ) )
  595. return true;
  596. return false;
  597. }
  598. /**
  599. * Retrieve the current blog id
  600. *
  601. * @since 3.1.0
  602. *
  603. * @return int Blog id
  604. */
  605. function get_current_blog_id() {
  606. global $blog_id;
  607. return absint($blog_id);
  608. }
  609. /**
  610. * Attempts an early load of translations.
  611. *
  612. * Used for errors encountered during the initial loading process, before the locale has been
  613. * properly detected and loaded.
  614. *
  615. * Designed for unusual load sequences (like setup-config.php) or for when the script will then
  616. * terminate with an error, otherwise there is a risk that a file can be double-included.
  617. *
  618. * @since 3.4.0
  619. * @access private
  620. */
  621. function wp_load_translations_early() {
  622. global $text_direction, $wp_locale;
  623. static $loaded = false;
  624. if ( $loaded )
  625. return;
  626. $loaded = true;
  627. if ( function_exists( 'did_action' ) && did_action( 'init' ) )
  628. return;
  629. // We need $wp_local_package
  630. require ABSPATH . WPINC . '/version.php';
  631. // Translation and localization
  632. require_once ABSPATH . WPINC . '/pomo/mo.php';
  633. require_once ABSPATH . WPINC . '/l10n.php';
  634. require_once ABSPATH . WPINC . '/locale.php';
  635. // General libraries
  636. require_once ABSPATH . WPINC . '/plugin.php';
  637. $locales = $locations = array();
  638. while ( true ) {
  639. if ( defined( 'WPLANG' ) ) {
  640. if ( '' == WPLANG )
  641. break;
  642. $locales[] = WPLANG;
  643. }
  644. if ( isset( $wp_local_package ) )
  645. $locales[] = $wp_local_package;
  646. if ( ! $locales )
  647. break;
  648. if ( defined( 'WP_LANG_DIR' ) && @is_dir( WP_LANG_DIR ) )
  649. $locations[] = WP_LANG_DIR;
  650. if ( defined( 'WP_CONTENT_DIR' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) )
  651. $locations[] = WP_CONTENT_DIR . '/languages';
  652. if ( @is_dir( ABSPATH . 'wp-content/languages' ) )
  653. $locations[] = ABSPATH . 'wp-content/languages';
  654. if ( @is_dir( ABSPATH . WPINC . '/languages' ) )
  655. $locations[] = ABSPATH . WPINC . '/languages';
  656. if ( ! $locations )
  657. break;
  658. $locations = array_unique( $locations );
  659. foreach ( $locales as $locale ) {
  660. foreach ( $locations as $location ) {
  661. if ( file_exists( $location . '/' . $locale . '.mo' ) ) {
  662. load_textdomain( 'default', $location . '/' . $locale . '.mo' );
  663. if ( defined( 'WP_SETUP_CONFIG' ) && file_exists( $location . '/admin-' . $locale . '.mo' ) )
  664. load_textdomain( 'default', $location . '/admin-' . $locale . '.mo' );
  665. break 2;
  666. }
  667. }
  668. }
  669. break;
  670. }
  671. $wp_locale = new WP_Locale();
  672. }