PageRenderTime 38ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-includes/load.php

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