PageRenderTime 59ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-includes/load.php

https://github.com/muskmelon/Greemo
PHP | 654 lines | 290 code | 67 blank | 297 comment | 94 complexity | 9f79362cab951feeea1a5878862f4bfa 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( /*WP_I18N_GLOBALS_OVERWRITE*/'GLOBALS overwrite attempt detected'/*/WP_I18N_GLOBALS_OVERWRITE*/ );
  21. // Variables that shouldn't be unset
  22. $no_unset = array( 'GLOBALS', '_GET', '_POST', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES', 'table_prefix' );
  23. $input = array_merge( $_GET, $_POST, $_COOKIE, $_SERVER, $_ENV, $_FILES, isset( $_SESSION ) && is_array( $_SESSION ) ? $_SESSION : array() );
  24. foreach ( $input as $k => $v )
  25. if ( !in_array( $k, $no_unset ) && isset( $GLOBALS[$k] ) ) {
  26. $GLOBALS[$k] = null;
  27. unset( $GLOBALS[$k] );
  28. }
  29. }
  30. /**
  31. * Fix $_SERVER variables for various setups.
  32. *
  33. * @access private
  34. * @since 3.0.0
  35. */
  36. function wp_fix_server_vars() {
  37. global $PHP_SELF;
  38. $default_server_values = array(
  39. 'SERVER_SOFTWARE' => '',
  40. 'REQUEST_URI' => '',
  41. );
  42. $_SERVER = array_merge( $default_server_values, $_SERVER );
  43. // Fix for IIS when running with PHP ISAPI
  44. if ( empty( $_SERVER['REQUEST_URI'] ) || ( php_sapi_name() != 'cgi-fcgi' && preg_match( '/^Microsoft-IIS\//', $_SERVER['SERVER_SOFTWARE'] ) ) ) {
  45. // IIS Mod-Rewrite
  46. if ( isset( $_SERVER['HTTP_X_ORIGINAL_URL'] ) ) {
  47. $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
  48. }
  49. // IIS Isapi_Rewrite
  50. else if ( isset( $_SERVER['HTTP_X_REWRITE_URL'] ) ) {
  51. $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
  52. } else {
  53. // Use ORIG_PATH_INFO if there is no PATH_INFO
  54. if ( !isset( $_SERVER['PATH_INFO'] ) && isset( $_SERVER['ORIG_PATH_INFO'] ) )
  55. $_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'];
  56. // Some IIS + PHP configurations puts the script-name in the path-info (No need to append it twice)
  57. if ( isset( $_SERVER['PATH_INFO'] ) ) {
  58. if ( $_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME'] )
  59. $_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'];
  60. else
  61. $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO'];
  62. }
  63. // Append the query string if it exists and isn't null
  64. if ( ! empty( $_SERVER['QUERY_STRING'] ) ) {
  65. $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
  66. }
  67. }
  68. }
  69. // Fix for PHP as CGI hosts that set SCRIPT_FILENAME to something ending in php.cgi for all requests
  70. if ( isset( $_SERVER['SCRIPT_FILENAME'] ) && ( strpos( $_SERVER['SCRIPT_FILENAME'], 'php.cgi' ) == strlen( $_SERVER['SCRIPT_FILENAME'] ) - 7 ) )
  71. $_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED'];
  72. // Fix for Dreamhost and other PHP as CGI hosts
  73. if ( strpos( $_SERVER['SCRIPT_NAME'], 'php.cgi' ) !== false )
  74. unset( $_SERVER['PATH_INFO'] );
  75. // Fix empty PHP_SELF
  76. $PHP_SELF = $_SERVER['PHP_SELF'];
  77. if ( empty( $PHP_SELF ) )
  78. $_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace( '/(\?.*)?$/', '', $_SERVER["REQUEST_URI"] );
  79. }
  80. /**
  81. * Check for the required PHP version, and the MySQL extension or a database drop-in.
  82. *
  83. * Dies if requirements are not met.
  84. *
  85. * This function must be able to work without a complete environment set up. In wp-load.php, for
  86. * example, WP_CONTENT_DIR is defined and version.php is included before this function is called.
  87. *
  88. * @access private
  89. * @since 3.0.0
  90. */
  91. function wp_check_php_mysql_versions() {
  92. // we can probably extend this function to check if wp_die() exists then use translated strings, and then use it in install.php etc.
  93. global $required_php_version, $wp_version;
  94. $php_version = phpversion();
  95. if ( version_compare( $required_php_version, $php_version, '>' ) )
  96. die( sprintf( /*WP_I18N_OLD_PHP*/'Your server is running PHP version %1$s but WordPress %2$s requires at least %3$s.'/*/WP_I18N_OLD_PHP*/, $php_version, $wp_version, $required_php_version ) );
  97. if ( !extension_loaded( 'mysql' ) && !file_exists( WP_CONTENT_DIR . '/db.php' ) )
  98. die( /*WP_I18N_OLD_MYSQL*/'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.'/*/WP_I18N_OLD_MYSQL*/ );
  99. }
  100. /**
  101. * Don't load all of WordPress when handling a favicon.ico request.
  102. * Instead, send the headers for a zero-length favicon and bail.
  103. *
  104. * @since 3.0.0
  105. */
  106. function wp_favicon_request() {
  107. if ( '/favicon.ico' == $_SERVER['REQUEST_URI'] ) {
  108. header('Content-Type: image/vnd.microsoft.icon');
  109. header('Content-Length: 0');
  110. exit;
  111. }
  112. }
  113. /**
  114. * Dies with a maintenance message when conditions are met.
  115. *
  116. * Checks for a file in the WordPress root directory named ".maintenance".
  117. * This file will contain the variable $upgrading, set to the time the file
  118. * was created. If the file was created less than 10 minutes ago, WordPress
  119. * enters maintenance mode and displays a message.
  120. *
  121. * The default message can be replaced by using a drop-in (maintenance.php in
  122. * the wp-content directory).
  123. *
  124. * @access private
  125. * @since 3.0.0
  126. */
  127. function wp_maintenance() {
  128. if ( !file_exists( ABSPATH . '.maintenance' ) || defined( 'WP_INSTALLING' ) )
  129. return;
  130. global $upgrading;
  131. include( ABSPATH . '.maintenance' );
  132. // If the $upgrading timestamp is older than 10 minutes, don't die.
  133. if ( ( time() - $upgrading ) >= 600 )
  134. return;
  135. if ( file_exists( WP_CONTENT_DIR . '/maintenance.php' ) ) {
  136. require_once( WP_CONTENT_DIR . '/maintenance.php' );
  137. die();
  138. }
  139. $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 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  147. <html xmlns="http://www.w3.org/1999/xhtml">
  148. <head>
  149. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  150. <title><?php echo /*WP_I18N_MAINTENANCE*/'Maintenance'/*/WP_I18N_MAINTENANCE*/; ?></title>
  151. </head>
  152. <body>
  153. <h1><?php echo /*WP_I18N_MAINT_MSG*/'Briefly unavailable for scheduled maintenance. Check back in a minute.'/*/WP_I18N_MAINT_MSG*/; ?></h1>
  154. </body>
  155. </html>
  156. <?php
  157. die();
  158. }
  159. /**
  160. * PHP 4 standard microtime start capture.
  161. *
  162. * @access private
  163. * @since 0.71
  164. * @global int $timestart Seconds and Microseconds added together from when function is called.
  165. * @return bool Always returns true.
  166. */
  167. function timer_start() {
  168. global $timestart;
  169. $mtime = explode( ' ', microtime() );
  170. $timestart = $mtime[1] + $mtime[0];
  171. return true;
  172. }
  173. /**
  174. * Return and/or display the time from the page start to when function is called.
  175. *
  176. * You can get the results and print them by doing:
  177. * <code>
  178. * $nTimePageTookToExecute = timer_stop();
  179. * echo $nTimePageTookToExecute;
  180. * </code>
  181. *
  182. * Or instead, you can do:
  183. * <code>
  184. * timer_stop(1);
  185. * </code>
  186. * which will do what the above does. If you need the result, you can assign it to a variable, but
  187. * most cases, you only need to echo it.
  188. *
  189. * @since 0.71
  190. * @global int $timestart Seconds and Microseconds added together from when timer_start() is called
  191. * @global int $timeend Seconds and Microseconds added together from when function is called
  192. *
  193. * @param int $display Use '0' or null to not echo anything and 1 to echo the total time
  194. * @param int $precision The amount of digits from the right of the decimal to display. Default is 3.
  195. * @return float The "second.microsecond" finished time calculation
  196. */
  197. function timer_stop( $display = 0, $precision = 3 ) { // if called like timer_stop(1), will echo $timetotal
  198. global $timestart, $timeend;
  199. $mtime = microtime();
  200. $mtime = explode( ' ', $mtime );
  201. $timeend = $mtime[1] + $mtime[0];
  202. $timetotal = $timeend - $timestart;
  203. $r = ( function_exists( 'number_format_i18n' ) ) ? number_format_i18n( $timetotal, $precision ) : number_format( $timetotal, $precision );
  204. if ( $display )
  205. echo $r;
  206. return $r;
  207. }
  208. /**
  209. * Sets PHP error handling and handles WordPress debug mode.
  210. *
  211. * Uses three constants: WP_DEBUG, WP_DEBUG_DISPLAY, and WP_DEBUG_LOG. All three can be
  212. * defined in wp-config.php. Example: <code> define( 'WP_DEBUG', true ); </code>
  213. *
  214. * WP_DEBUG_DISPLAY and WP_DEBUG_LOG perform no function unless WP_DEBUG is true.
  215. * WP_DEBUG defaults to false.
  216. *
  217. * When WP_DEBUG is true, all PHP notices are reported. WordPress will also display
  218. * notices, including one when a deprecated WordPress function, function argument,
  219. * or file is used. Deprecated code may be removed from a later version.
  220. *
  221. * It is strongly recommended that plugin and theme developers use WP_DEBUG in their
  222. * development environments.
  223. *
  224. * When WP_DEBUG_DISPLAY is true, WordPress will force errors to be displayed.
  225. * WP_DEBUG_DISPLAY defaults to true. Defining it as false prevents WordPress from
  226. * changing the global configuration setting. (Defining WP_DEBUG_DISPLAY as false
  227. * will never force errors to be hidden.)
  228. *
  229. * When WP_DEBUG_LOG is true, errors will be logged to wp-content/debug.log.
  230. * WP_DEBUG_LOG defaults to false.
  231. *
  232. * @access private
  233. * @since 3.0.0
  234. */
  235. function wp_debug_mode() {
  236. if ( WP_DEBUG ) {
  237. // E_DEPRECATED is a core PHP constant in PHP 5.3. Don't define this yourself.
  238. // The two statements are equivalent, just one is for 5.3+ and for less than 5.3.
  239. if ( defined( 'E_DEPRECATED' ) )
  240. error_reporting( E_ALL & ~E_DEPRECATED & ~E_STRICT );
  241. else
  242. error_reporting( E_ALL );
  243. if ( WP_DEBUG_DISPLAY )
  244. ini_set( 'display_errors', 1 );
  245. if ( WP_DEBUG_LOG ) {
  246. ini_set( 'log_errors', 1 );
  247. ini_set( 'error_log', WP_CONTENT_DIR . '/debug.log' );
  248. }
  249. } else {
  250. error_reporting( E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR );
  251. }
  252. }
  253. /**
  254. * Sets the location of the language directory.
  255. *
  256. * To set directory manually, define <code>WP_LANG_DIR</code> in wp-config.php.
  257. *
  258. * If the language directory exists within WP_CONTENT_DIR that is used
  259. * Otherwise if the language directory exists within WPINC, that's used
  260. * Finally, If neither of the preceeding directories is found,
  261. * WP_CONTENT_DIR/languages is used.
  262. *
  263. * The WP_LANG_DIR constant was introduced in 2.1.0.
  264. *
  265. * @access private
  266. * @since 3.0.0
  267. */
  268. function wp_set_lang_dir() {
  269. if ( !defined( 'WP_LANG_DIR' ) ) {
  270. if ( file_exists( WP_CONTENT_DIR . '/languages' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) || !@is_dir(ABSPATH . WPINC . '/languages') ) {
  271. define( 'WP_LANG_DIR', WP_CONTENT_DIR . '/languages' ); // no leading slash, no trailing slash, full path, not relative to ABSPATH
  272. if ( !defined( 'LANGDIR' ) ) {
  273. // Old static relative path maintained for limited backwards compatibility - won't work in some cases
  274. define( 'LANGDIR', 'wp-content/languages' );
  275. }
  276. } else {
  277. define( 'WP_LANG_DIR', ABSPATH . WPINC . '/languages' ); // no leading slash, no trailing slash, full path, not relative to ABSPATH
  278. if ( !defined( 'LANGDIR' ) ) {
  279. // Old relative path maintained for backwards compatibility
  280. define( 'LANGDIR', WPINC . '/languages' );
  281. }
  282. }
  283. }
  284. }
  285. /**
  286. * Load the correct database class file.
  287. *
  288. * This function is used to load the database class file either at runtime or by
  289. * wp-admin/setup-config.php. We must globalize $wpdb to ensure that it is
  290. * defined globally by the inline code in wp-db.php.
  291. *
  292. * @since 2.5.0
  293. * @global $wpdb WordPress Database Object
  294. */
  295. function require_wp_db() {
  296. global $wpdb;
  297. require_once( ABSPATH . WPINC . '/wp-db.php' );
  298. if ( file_exists( WP_CONTENT_DIR . '/db.php' ) )
  299. require_once( WP_CONTENT_DIR . '/db.php' );
  300. if ( isset( $wpdb ) )
  301. return;
  302. $wpdb = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST );
  303. }
  304. /**
  305. * Sets the database table prefix and the format specifiers for database table columns.
  306. *
  307. * Columns not listed here default to %s.
  308. *
  309. * @see wpdb::$field_types Since 2.8.0
  310. * @see wpdb::prepare()
  311. * @see wpdb::insert()
  312. * @see wpdb::update()
  313. * @see wpdb::set_prefix()
  314. *
  315. * @access private
  316. * @since 3.0.0
  317. */
  318. function wp_set_wpdb_vars() {
  319. global $wpdb, $table_prefix;
  320. if ( !empty( $wpdb->error ) )
  321. dead_db();
  322. $wpdb->field_types = array( 'post_author' => '%d', 'post_parent' => '%d', 'menu_order' => '%d', 'term_id' => '%d', 'term_group' => '%d', 'term_taxonomy_id' => '%d',
  323. 'parent' => '%d', 'count' => '%d','object_id' => '%d', 'term_order' => '%d', 'ID' => '%d', 'commment_ID' => '%d', 'comment_post_ID' => '%d', 'comment_parent' => '%d',
  324. 'user_id' => '%d', 'link_id' => '%d', 'link_owner' => '%d', 'link_rating' => '%d', 'option_id' => '%d', 'blog_id' => '%d', 'meta_id' => '%d', 'post_id' => '%d',
  325. 'user_status' => '%d', 'umeta_id' => '%d', 'comment_karma' => '%d', 'comment_count' => '%d',
  326. // multisite:
  327. 'active' => '%d', 'cat_id' => '%d', 'deleted' => '%d', 'lang_id' => '%d', 'mature' => '%d', 'public' => '%d', 'site_id' => '%d', 'spam' => '%d',
  328. );
  329. $prefix = $wpdb->set_prefix( $table_prefix );
  330. if ( is_wp_error( $prefix ) )
  331. wp_die( /*WP_I18N_BAD_PREFIX*/'<strong>ERROR</strong>: <code>$table_prefix</code> in <code>wp-config.php</code> can only contain numbers, letters, and underscores.'/*/WP_I18N_BAD_PREFIX*/ );
  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;
  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_reset') )
  364. wp_cache_reset();
  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' ) );
  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. if ( !@mb_internal_encoding( get_option( 'blog_charset' ) ) )
  463. mb_internal_encoding( 'UTF-8' );
  464. }
  465. }
  466. /**
  467. * Add magic quotes to $_GET, $_POST, $_COOKIE, and $_SERVER.
  468. *
  469. * Also forces $_REQUEST to be $_GET + $_POST. If $_SERVER, $_COOKIE,
  470. * or $_ENV are needed, use those superglobals directly.
  471. *
  472. * @access private
  473. * @since 3.0.0
  474. */
  475. function wp_magic_quotes() {
  476. // If already slashed, strip.
  477. if ( get_magic_quotes_gpc() ) {
  478. $_GET = stripslashes_deep( $_GET );
  479. $_POST = stripslashes_deep( $_POST );
  480. $_COOKIE = stripslashes_deep( $_COOKIE );
  481. }
  482. // Escape with wpdb.
  483. $_GET = add_magic_quotes( $_GET );
  484. $_POST = add_magic_quotes( $_POST );
  485. $_COOKIE = add_magic_quotes( $_COOKIE );
  486. $_SERVER = add_magic_quotes( $_SERVER );
  487. // Force REQUEST to be GET + POST.
  488. $_REQUEST = array_merge( $_GET, $_POST );
  489. }
  490. /**
  491. * Runs just before PHP shuts down execution.
  492. *
  493. * @access private
  494. * @since 1.2.0
  495. */
  496. function shutdown_action_hook() {
  497. do_action( 'shutdown' );
  498. wp_cache_close();
  499. }
  500. /**
  501. * Copy an object.
  502. *
  503. * @since 2.7.0
  504. * @deprecated 3.2
  505. *
  506. * @param object $object The object to clone
  507. * @return object The cloned object
  508. */
  509. function wp_clone( $object ) {
  510. // Use parens for clone to accommodate PHP 4. See #17880
  511. return clone( $object );
  512. }
  513. /**
  514. * Whether the current request is for a network or blog admin page
  515. *
  516. * Does not inform on whether the user is an admin! Use capability checks to
  517. * tell if the user should be accessing a section or not.
  518. *
  519. * @since 1.5.1
  520. *
  521. * @return bool True if inside WordPress administration pages.
  522. */
  523. function is_admin() {
  524. if ( defined( 'WP_ADMIN' ) )
  525. return WP_ADMIN;
  526. return false;
  527. }
  528. /**
  529. * Whether the current request is for a blog admin screen /wp-admin/
  530. *
  531. * Does not inform on whether the user is a blog admin! Use capability checks to
  532. * tell if the user should be accessing a section or not.
  533. *
  534. * @since 3.1.0
  535. *
  536. * @return bool True if inside WordPress network administration pages.
  537. */
  538. function is_blog_admin() {
  539. if ( defined( 'WP_BLOG_ADMIN' ) )
  540. return WP_BLOG_ADMIN;
  541. return false;
  542. }
  543. /**
  544. * Whether the current request is for a network admin screen /wp-admin/network/
  545. *
  546. * Does not inform on whether the user is a network admin! Use capability checks to
  547. * tell if the user should be accessing a section or not.
  548. *
  549. * @since 3.1.0
  550. *
  551. * @return bool True if inside WordPress network administration pages.
  552. */
  553. function is_network_admin() {
  554. if ( defined( 'WP_NETWORK_ADMIN' ) )
  555. return WP_NETWORK_ADMIN;
  556. return false;
  557. }
  558. /**
  559. * Whether the current request is for a user admin screen /wp-admin/user/
  560. *
  561. * Does not inform on whether the user is an admin! Use capability checks to
  562. * tell if the user should be accessing a section or not.
  563. *
  564. * @since 3.1.0
  565. *
  566. * @return bool True if inside WordPress user administration pages.
  567. */
  568. function is_user_admin() {
  569. if ( defined( 'WP_USER_ADMIN' ) )
  570. return WP_USER_ADMIN;
  571. return false;
  572. }
  573. /**
  574. * Whether Multisite support is enabled
  575. *
  576. * @since 3.0.0
  577. *
  578. * @return bool True if multisite is enabled, false otherwise.
  579. */
  580. function is_multisite() {
  581. if ( defined( 'MULTISITE' ) )
  582. return MULTISITE;
  583. if ( defined( 'SUBDOMAIN_INSTALL' ) || defined( 'VHOST' ) || defined( 'SUNRISE' ) )
  584. return true;
  585. return false;
  586. }
  587. ?>