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