PageRenderTime 47ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-includes/load.php

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