PageRenderTime 57ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/APP/wp-includes/load.php

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