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