PageRenderTime 30ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-includes/load.php

https://bitbucket.org/Thane2376/death-edge.ru
PHP | 828 lines | 367 code | 96 blank | 365 comment | 117 complexity | 5380875b9f82352cb81f4849783d2679 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, LGPL-3.0, AGPL-1.0
  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. nocache_headers();
  424. wp_die( __( 'The site you have requested is not installed properly. Please contact the system administrator.' ) );
  425. }
  426. } elseif ( ! is_blog_installed() && false === strpos( $_SERVER['PHP_SELF'], 'install.php' ) && !defined( 'WP_INSTALLING' ) ) {
  427. nocache_headers();
  428. require( ABSPATH . WPINC . '/kses.php' );
  429. require( ABSPATH . WPINC . '/pluggable.php' );
  430. require( ABSPATH . WPINC . '/formatting.php' );
  431. $link = wp_guess_url() . '/wp-admin/install.php';
  432. wp_redirect( $link );
  433. die();
  434. }
  435. }
  436. /**
  437. * Retrieve an array of must-use plugin files.
  438. *
  439. * The default directory is wp-content/mu-plugins. To change the default
  440. * directory manually, define `WPMU_PLUGIN_DIR` and `WPMU_PLUGIN_URL`
  441. * in wp-config.php.
  442. *
  443. * @since 3.0.0
  444. * @access private
  445. *
  446. * @return array Files to include.
  447. */
  448. function wp_get_mu_plugins() {
  449. $mu_plugins = array();
  450. if ( !is_dir( WPMU_PLUGIN_DIR ) )
  451. return $mu_plugins;
  452. if ( ! $dh = opendir( WPMU_PLUGIN_DIR ) )
  453. return $mu_plugins;
  454. while ( ( $plugin = readdir( $dh ) ) !== false ) {
  455. if ( substr( $plugin, -4 ) == '.php' )
  456. $mu_plugins[] = WPMU_PLUGIN_DIR . '/' . $plugin;
  457. }
  458. closedir( $dh );
  459. sort( $mu_plugins );
  460. return $mu_plugins;
  461. }
  462. /**
  463. * Retrieve an array of active and valid plugin files.
  464. *
  465. * While upgrading or installing WordPress, no plugins are returned.
  466. *
  467. * The default directory is wp-content/plugins. To change the default
  468. * directory manually, define `WP_PLUGIN_DIR` and `WP_PLUGIN_URL`
  469. * in wp-config.php.
  470. *
  471. * @since 3.0.0
  472. * @access private
  473. *
  474. * @return array Files.
  475. */
  476. function wp_get_active_and_valid_plugins() {
  477. $plugins = array();
  478. $active_plugins = (array) get_option( 'active_plugins', array() );
  479. // Check for hacks file if the option is enabled
  480. if ( get_option( 'hack_file' ) && file_exists( ABSPATH . 'my-hacks.php' ) ) {
  481. _deprecated_file( 'my-hacks.php', '1.5' );
  482. array_unshift( $plugins, ABSPATH . 'my-hacks.php' );
  483. }
  484. if ( empty( $active_plugins ) || defined( 'WP_INSTALLING' ) )
  485. return $plugins;
  486. $network_plugins = is_multisite() ? wp_get_active_network_plugins() : false;
  487. foreach ( $active_plugins as $plugin ) {
  488. if ( ! validate_file( $plugin ) // $plugin must validate as file
  489. && '.php' == substr( $plugin, -4 ) // $plugin must end with '.php'
  490. && file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist
  491. // not already included as a network plugin
  492. && ( ! $network_plugins || ! in_array( WP_PLUGIN_DIR . '/' . $plugin, $network_plugins ) )
  493. )
  494. $plugins[] = WP_PLUGIN_DIR . '/' . $plugin;
  495. }
  496. return $plugins;
  497. }
  498. /**
  499. * Set internal encoding.
  500. *
  501. * In most cases the default internal encoding is latin1, which is
  502. * of no use, since we want to use the `mb_` functions for `utf-8` strings.
  503. *
  504. * @since 3.0.0
  505. * @access private
  506. */
  507. function wp_set_internal_encoding() {
  508. if ( function_exists( 'mb_internal_encoding' ) ) {
  509. $charset = get_option( 'blog_charset' );
  510. if ( ! $charset || ! @mb_internal_encoding( $charset ) )
  511. mb_internal_encoding( 'UTF-8' );
  512. }
  513. }
  514. /**
  515. * Add magic quotes to `$_GET`, `$_POST`, `$_COOKIE`, and `$_SERVER`.
  516. *
  517. * Also forces `$_REQUEST` to be `$_GET + $_POST`. If `$_SERVER`,
  518. * `$_COOKIE`, or `$_ENV` are needed, use those superglobals directly.
  519. *
  520. * @since 3.0.0
  521. * @access private
  522. */
  523. function wp_magic_quotes() {
  524. // If already slashed, strip.
  525. if ( get_magic_quotes_gpc() ) {
  526. $_GET = stripslashes_deep( $_GET );
  527. $_POST = stripslashes_deep( $_POST );
  528. $_COOKIE = stripslashes_deep( $_COOKIE );
  529. }
  530. // Escape with wpdb.
  531. $_GET = add_magic_quotes( $_GET );
  532. $_POST = add_magic_quotes( $_POST );
  533. $_COOKIE = add_magic_quotes( $_COOKIE );
  534. $_SERVER = add_magic_quotes( $_SERVER );
  535. // Force REQUEST to be GET + POST.
  536. $_REQUEST = array_merge( $_GET, $_POST );
  537. }
  538. /**
  539. * Runs just before PHP shuts down execution.
  540. *
  541. * @since 1.2.0
  542. * @access private
  543. */
  544. function shutdown_action_hook() {
  545. /**
  546. * Fires just before PHP shuts down execution.
  547. *
  548. * @since 1.2.0
  549. */
  550. do_action( 'shutdown' );
  551. wp_cache_close();
  552. }
  553. /**
  554. * Copy an object.
  555. *
  556. * @since 2.7.0
  557. * @deprecated 3.2.0
  558. *
  559. * @param object $object The object to clone.
  560. * @return object The cloned object.
  561. */
  562. function wp_clone( $object ) {
  563. // Use parens for clone to accommodate PHP 4. See #17880
  564. return clone( $object );
  565. }
  566. /**
  567. * Whether the current request is for an administrative interface page.
  568. *
  569. * Does not check if the user is an administrator; {@see current_user_can()}
  570. * for checking roles and capabilities.
  571. *
  572. * @since 1.5.1
  573. *
  574. * @return bool True if inside WordPress administration interface, false otherwise.
  575. */
  576. function is_admin() {
  577. if ( isset( $GLOBALS['current_screen'] ) )
  578. return $GLOBALS['current_screen']->in_admin();
  579. elseif ( defined( 'WP_ADMIN' ) )
  580. return WP_ADMIN;
  581. return false;
  582. }
  583. /**
  584. * Whether the current request is for a site's admininstrative interface.
  585. *
  586. * e.g. `/wp-admin/`
  587. *
  588. * Does not check if the user is an administrator; {@see current_user_can()}
  589. * for checking roles and capabilities.
  590. *
  591. * @since 3.1.0
  592. *
  593. * @return bool True if inside WordPress blog administration pages.
  594. */
  595. function is_blog_admin() {
  596. if ( isset( $GLOBALS['current_screen'] ) )
  597. return $GLOBALS['current_screen']->in_admin( 'site' );
  598. elseif ( defined( 'WP_BLOG_ADMIN' ) )
  599. return WP_BLOG_ADMIN;
  600. return false;
  601. }
  602. /**
  603. * Whether the current request is for the network administrative interface.
  604. *
  605. * e.g. `/wp-admin/network/`
  606. *
  607. * Does not check if the user is an administrator; {@see current_user_can()}
  608. * for checking roles and capabilities.
  609. *
  610. * @since 3.1.0
  611. *
  612. * @return bool True if inside WordPress network administration pages.
  613. */
  614. function is_network_admin() {
  615. if ( isset( $GLOBALS['current_screen'] ) )
  616. return $GLOBALS['current_screen']->in_admin( 'network' );
  617. elseif ( defined( 'WP_NETWORK_ADMIN' ) )
  618. return WP_NETWORK_ADMIN;
  619. return false;
  620. }
  621. /**
  622. * Whether the current request is for a user admin screen.
  623. *
  624. * e.g. `/wp-admin/user/`
  625. *
  626. * Does not inform on whether the user is an admin! Use capability
  627. * checks to tell if the user should be accessing a section or not
  628. * {@see current_user_can()}.
  629. *
  630. * @since 3.1.0
  631. *
  632. * @return bool True if inside WordPress user administration pages.
  633. */
  634. function is_user_admin() {
  635. if ( isset( $GLOBALS['current_screen'] ) )
  636. return $GLOBALS['current_screen']->in_admin( 'user' );
  637. elseif ( defined( 'WP_USER_ADMIN' ) )
  638. return WP_USER_ADMIN;
  639. return false;
  640. }
  641. /**
  642. * If Multisite is enabled.
  643. *
  644. * @since 3.0.0
  645. *
  646. * @return bool True if Multisite is enabled, false otherwise.
  647. */
  648. function is_multisite() {
  649. if ( defined( 'MULTISITE' ) )
  650. return MULTISITE;
  651. if ( defined( 'SUBDOMAIN_INSTALL' ) || defined( 'VHOST' ) || defined( 'SUNRISE' ) )
  652. return true;
  653. return false;
  654. }
  655. /**
  656. * Retrieve the current blog ID.
  657. *
  658. * @since 3.1.0
  659. *
  660. * @return int Blog id
  661. */
  662. function get_current_blog_id() {
  663. global $blog_id;
  664. return absint($blog_id);
  665. }
  666. /**
  667. * Attempt an early load of translations.
  668. *
  669. * Used for errors encountered during the initial loading process, before
  670. * the locale has been properly detected and loaded.
  671. *
  672. * Designed for unusual load sequences (like setup-config.php) or for when
  673. * the script will then terminate with an error, otherwise there is a risk
  674. * that a file can be double-included.
  675. *
  676. * @since 3.4.0
  677. * @access private
  678. *
  679. * @global $wp_locale The WordPress date and time locale object.
  680. */
  681. function wp_load_translations_early() {
  682. global $text_direction, $wp_locale;
  683. static $loaded = false;
  684. if ( $loaded )
  685. return;
  686. $loaded = true;
  687. if ( function_exists( 'did_action' ) && did_action( 'init' ) )
  688. return;
  689. // We need $wp_local_package
  690. require ABSPATH . WPINC . '/version.php';
  691. // Translation and localization
  692. require_once ABSPATH . WPINC . '/pomo/mo.php';
  693. require_once ABSPATH . WPINC . '/l10n.php';
  694. require_once ABSPATH . WPINC . '/locale.php';
  695. // General libraries
  696. require_once ABSPATH . WPINC . '/plugin.php';
  697. $locales = $locations = array();
  698. while ( true ) {
  699. if ( defined( 'WPLANG' ) ) {
  700. if ( '' == WPLANG )
  701. break;
  702. $locales[] = WPLANG;
  703. }
  704. if ( isset( $wp_local_package ) )
  705. $locales[] = $wp_local_package;
  706. if ( ! $locales )
  707. break;
  708. if ( defined( 'WP_LANG_DIR' ) && @is_dir( WP_LANG_DIR ) )
  709. $locations[] = WP_LANG_DIR;
  710. if ( defined( 'WP_CONTENT_DIR' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) )
  711. $locations[] = WP_CONTENT_DIR . '/languages';
  712. if ( @is_dir( ABSPATH . 'wp-content/languages' ) )
  713. $locations[] = ABSPATH . 'wp-content/languages';
  714. if ( @is_dir( ABSPATH . WPINC . '/languages' ) )
  715. $locations[] = ABSPATH . WPINC . '/languages';
  716. if ( ! $locations )
  717. break;
  718. $locations = array_unique( $locations );
  719. foreach ( $locales as $locale ) {
  720. foreach ( $locations as $location ) {
  721. if ( file_exists( $location . '/' . $locale . '.mo' ) ) {
  722. load_textdomain( 'default', $location . '/' . $locale . '.mo' );
  723. if ( defined( 'WP_SETUP_CONFIG' ) && file_exists( $location . '/admin-' . $locale . '.mo' ) )
  724. load_textdomain( 'default', $location . '/admin-' . $locale . '.mo' );
  725. break 2;
  726. }
  727. }
  728. }
  729. break;
  730. }
  731. $wp_locale = new WP_Locale();
  732. }