wp/wp-includes/load.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
     8  */
     8  */
     9 
     9 
    10 /**
    10 /**
    11  * Turn register globals off.
    11  * Turn register globals off.
    12  *
    12  *
    13  * @access private
       
    14  * @since 2.1.0
    13  * @since 2.1.0
    15  * @return null Will return null if register_globals PHP directive was disabled
    14  * @access private
       
    15  *
       
    16  * @return null Will return null if register_globals PHP directive was disabled.
    16  */
    17  */
    17 function wp_unregister_GLOBALS() {
    18 function wp_unregister_GLOBALS() {
    18 	if ( !ini_get( 'register_globals' ) )
    19 	if ( !ini_get( 'register_globals' ) )
    19 		return;
    20 		return;
    20 
    21 
    30 			unset( $GLOBALS[$k] );
    31 			unset( $GLOBALS[$k] );
    31 		}
    32 		}
    32 }
    33 }
    33 
    34 
    34 /**
    35 /**
    35  * Fix $_SERVER variables for various setups.
    36  * Fix `$_SERVER` variables for various setups.
    36  *
    37  *
    37  * @access private
    38  * @since 3.0.0
    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.
    39  */
    43  */
    40 function wp_fix_server_vars() {
    44 function wp_fix_server_vars() {
    41 	global $PHP_SELF;
    45 	global $PHP_SELF;
    42 
    46 
    43 	$default_server_values = array(
    47 	$default_server_values = array(
    46 	);
    50 	);
    47 
    51 
    48 	$_SERVER = array_merge( $default_server_values, $_SERVER );
    52 	$_SERVER = array_merge( $default_server_values, $_SERVER );
    49 
    53 
    50 	// Fix for IIS when running with PHP ISAPI
    54 	// Fix for IIS when running with PHP ISAPI
    51 	if ( empty( $_SERVER['REQUEST_URI'] ) || ( php_sapi_name() != 'cgi-fcgi' && preg_match( '/^Microsoft-IIS\//', $_SERVER['SERVER_SOFTWARE'] ) ) ) {
    55 	if ( empty( $_SERVER['REQUEST_URI'] ) || ( PHP_SAPI != 'cgi-fcgi' && preg_match( '/^Microsoft-IIS\//', $_SERVER['SERVER_SOFTWARE'] ) ) ) {
    52 
    56 
    53 		// IIS Mod-Rewrite
    57 		// IIS Mod-Rewrite
    54 		if ( isset( $_SERVER['HTTP_X_ORIGINAL_URL'] ) ) {
    58 		if ( isset( $_SERVER['HTTP_X_ORIGINAL_URL'] ) ) {
    55 			$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
    59 			$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
    56 		}
    60 		}
    57 		// IIS Isapi_Rewrite
    61 		// IIS Isapi_Rewrite
    58 		else if ( isset( $_SERVER['HTTP_X_REWRITE_URL'] ) ) {
    62 		elseif ( isset( $_SERVER['HTTP_X_REWRITE_URL'] ) ) {
    59 			$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
    63 			$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
    60 		} else {
    64 		} else {
    61 			// Use ORIG_PATH_INFO if there is no PATH_INFO
    65 			// Use ORIG_PATH_INFO if there is no PATH_INFO
    62 			if ( !isset( $_SERVER['PATH_INFO'] ) && isset( $_SERVER['ORIG_PATH_INFO'] ) )
    66 			if ( !isset( $_SERVER['PATH_INFO'] ) && isset( $_SERVER['ORIG_PATH_INFO'] ) )
    63 				$_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'];
    67 				$_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'];
    90 	if ( empty( $PHP_SELF ) )
    94 	if ( empty( $PHP_SELF ) )
    91 		$_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace( '/(\?.*)?$/', '', $_SERVER["REQUEST_URI"] );
    95 		$_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace( '/(\?.*)?$/', '', $_SERVER["REQUEST_URI"] );
    92 }
    96 }
    93 
    97 
    94 /**
    98 /**
    95  * Check for the required PHP version, and the MySQL extension or a database drop-in.
    99  * Check for the required PHP version, and the MySQL extension or
       
   100  * a database drop-in.
    96  *
   101  *
    97  * Dies if requirements are not met.
   102  * Dies if requirements are not met.
    98  *
   103  *
    99  * @access private
   104  * @since 3.0.0
   100  * @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.
   101  */
   109  */
   102 function wp_check_php_mysql_versions() {
   110 function wp_check_php_mysql_versions() {
   103 	global $required_php_version, $wp_version;
   111 	global $required_php_version, $wp_version;
   104 	$php_version = phpversion();
   112 	$php_version = phpversion();
       
   113 
   105 	if ( version_compare( $required_php_version, $php_version, '>' ) ) {
   114 	if ( version_compare( $required_php_version, $php_version, '>' ) ) {
   106 		wp_load_translations_early();
   115 		wp_load_translations_early();
       
   116 		header( 'Content-Type: text/html; charset=utf-8' );
   107 		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 ) );
   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 ) );
   108 	}
   118 	}
   109 
   119 
   110 	if ( ! extension_loaded( 'mysql' ) && ! file_exists( WP_CONTENT_DIR . '/db.php' ) ) {
   120 	if ( ! extension_loaded( 'mysql' ) && ! extension_loaded( 'mysqli' ) && ! file_exists( WP_CONTENT_DIR . '/db.php' ) ) {
   111 		wp_load_translations_early();
   121 		wp_load_translations_early();
       
   122 		 header( 'Content-Type: text/html; charset=utf-8' );
   112 		die( __( 'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.' ) );
   123 		die( __( 'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.' ) );
   113 	}
   124 	}
   114 }
   125 }
   115 
   126 
   116 /**
   127 /**
   117  * Don't load all of WordPress when handling a favicon.ico request.
   128  * Don't load all of WordPress when handling a favicon.ico request.
       
   129  *
   118  * Instead, send the headers for a zero-length favicon and bail.
   130  * Instead, send the headers for a zero-length favicon and bail.
   119  *
   131  *
   120  * @since 3.0.0
   132  * @since 3.0.0
   121  */
   133  */
   122 function wp_favicon_request() {
   134 function wp_favicon_request() {
   126 		exit;
   138 		exit;
   127 	}
   139 	}
   128 }
   140 }
   129 
   141 
   130 /**
   142 /**
   131  * Dies with a maintenance message when conditions are met.
   143  * Die with a maintenance message when conditions are met.
   132  *
   144  *
   133  * Checks for a file in the WordPress root directory named ".maintenance".
   145  * Checks for a file in the WordPress root directory named ".maintenance".
   134  * This file will contain the variable $upgrading, set to the time the file
   146  * This file will contain the variable $upgrading, set to the time the file
   135  * was created. If the file was created less than 10 minutes ago, WordPress
   147  * was created. If the file was created less than 10 minutes ago, WordPress
   136  * enters maintenance mode and displays a message.
   148  * enters maintenance mode and displays a message.
   137  *
   149  *
   138  * The default message can be replaced by using a drop-in (maintenance.php in
   150  * The default message can be replaced by using a drop-in (maintenance.php in
   139  * the wp-content directory).
   151  * the wp-content directory).
   140  *
   152  *
   141  * @access private
   153  * @since 3.0.0
   142  * @since 3.0.0
   154  * @access private
       
   155  *
       
   156  * @global int $upgrading the unix timestamp marking when upgrading WordPress began.
   143  */
   157  */
   144 function wp_maintenance() {
   158 function wp_maintenance() {
   145 	if ( !file_exists( ABSPATH . '.maintenance' ) || defined( 'WP_INSTALLING' ) )
   159 	if ( !file_exists( ABSPATH . '.maintenance' ) || defined( 'WP_INSTALLING' ) )
   146 		return;
   160 		return;
   147 
   161 
   180 <?php
   194 <?php
   181 	die();
   195 	die();
   182 }
   196 }
   183 
   197 
   184 /**
   198 /**
   185  * PHP 5 standard microtime start capture.
   199  * Start the WordPress micro-timer.
   186  *
   200  *
   187  * @access private
       
   188  * @since 0.71
   201  * @since 0.71
   189  * @global float $timestart Seconds from when function is called.
   202  * @access private
       
   203  *
       
   204  * @global float $timestart Unix timestamp set at the beginning of the page load.
       
   205  * @see timer_stop()
       
   206  *
   190  * @return bool Always returns true.
   207  * @return bool Always returns true.
   191  */
   208  */
   192 function timer_start() {
   209 function timer_start() {
   193 	global $timestart;
   210 	global $timestart;
   194 	$timestart = microtime( true );
   211 	$timestart = microtime( true );
   195 	return true;
   212 	return true;
   196 }
   213 }
   197 
   214 
   198 /**
   215 /**
   199  * Return and/or display the time from the page start to when function is called.
   216  * Retrieve or display the time from the page start to when function is called.
   200  *
       
   201  * You can get the results and print them by doing:
       
   202  * <code>
       
   203  * $nTimePageTookToExecute = timer_stop();
       
   204  * echo $nTimePageTookToExecute;
       
   205  * </code>
       
   206  *
       
   207  * Or instead, you can do:
       
   208  * <code>
       
   209  * timer_stop(1);
       
   210  * </code>
       
   211  * which will do what the above does. If you need the result, you can assign it to a variable, but
       
   212  * in most cases, you only need to echo it.
       
   213  *
   217  *
   214  * @since 0.71
   218  * @since 0.71
   215  * @global float $timestart Seconds from when timer_start() is called
   219  *
   216  * @global float $timeend Seconds from when function is called
   220  * @global float   $timestart Seconds from when timer_start() is called.
   217  *
   221  * @global float   $timeend   Seconds from when function is called.
   218  * @param int $display Use '0' or null to not echo anything and 1 to echo the total time
   222  *
   219  * @param int $precision The amount of digits from the right of the decimal to display. Default is 3.
   223  * @param int|bool $display   Whether to echo or return the results. Accepts 0|false for return,
   220  * @return float The "second.microsecond" finished time calculation
   224  *                            1|true for echo. Default 0|false.
   221  */
   225  * @param int      $precision The number of digits from the right of the decimal to display.
   222 function timer_stop( $display = 0, $precision = 3 ) { // if called like timer_stop(1), will echo $timetotal
   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 ) {
   223 	global $timestart, $timeend;
   231 	global $timestart, $timeend;
   224 	$timeend = microtime( true );
   232 	$timeend = microtime( true );
   225 	$timetotal = $timeend - $timestart;
   233 	$timetotal = $timeend - $timestart;
   226 	$r = ( function_exists( 'number_format_i18n' ) ) ? number_format_i18n( $timetotal, $precision ) : number_format( $timetotal, $precision );
   234 	$r = ( function_exists( 'number_format_i18n' ) ) ? number_format_i18n( $timetotal, $precision ) : number_format( $timetotal, $precision );
   227 	if ( $display )
   235 	if ( $display )
   228 		echo $r;
   236 		echo $r;
   229 	return $r;
   237 	return $r;
   230 }
   238 }
   231 
   239 
   232 /**
   240 /**
   233  * Sets PHP error handling and handles WordPress debug mode.
   241  * Set PHP error reporting based on WordPress debug settings.
   234  *
   242  *
   235  * Uses three constants: WP_DEBUG, WP_DEBUG_DISPLAY, and WP_DEBUG_LOG. All three can be
   243  * Uses three constants: `WP_DEBUG`, `WP_DEBUG_DISPLAY`, and `WP_DEBUG_LOG`.
   236  * defined in wp-config.php. Example: <code> define( 'WP_DEBUG', true ); </code>
   244  * All three can be defined in wp-config.php, and by default are set to false.
   237  *
   245  *
   238  * WP_DEBUG_DISPLAY and WP_DEBUG_LOG perform no function unless WP_DEBUG is true.
   246  * When `WP_DEBUG` is true, all PHP notices are reported. WordPress will also
   239  * WP_DEBUG defaults to false.
   247  * display internal notices: when a deprecated WordPress function, function
   240  *
   248  * argument, or file is used. Deprecated code may be removed from a later
   241  * When WP_DEBUG is true, all PHP notices are reported. WordPress will also display
   249  * version.
   242  * notices, including one when a deprecated WordPress function, function argument,
   250  *
   243  * or file is used. Deprecated code may be removed from a later version.
   251  * It is strongly recommended that plugin and theme developers use `WP_DEBUG`
   244  *
   252  * in their development environments.
   245  * It is strongly recommended that plugin and theme developers use WP_DEBUG in their
   253  *
   246  * development environments.
   254  * `WP_DEBUG_DISPLAY` and `WP_DEBUG_LOG` perform no function unless `WP_DEBUG`
   247  *
   255  * is true.
   248  * When WP_DEBUG_DISPLAY is true, WordPress will force errors to be displayed.
   256  *
   249  * WP_DEBUG_DISPLAY defaults to true. Defining it as null prevents WordPress from
   257  * When `WP_DEBUG_DISPLAY` is true, WordPress will force errors to be displayed.
   250  * changing the global configuration setting. Defining WP_DEBUG_DISPLAY as false
   258  * `WP_DEBUG_DISPLAY` defaults to true. Defining it as null prevents WordPress
   251  * will force errors to be hidden.
   259  * from changing the global configuration setting. Defining `WP_DEBUG_DISPLAY`
   252  *
   260  * as false will force errors to be hidden.
   253  * When WP_DEBUG_LOG is true, errors will be logged to wp-content/debug.log.
   261  *
   254  * WP_DEBUG_LOG defaults to false.
   262  * When `WP_DEBUG_LOG` is true, errors will be logged to debug.log in the content
       
   263  * directory.
   255  *
   264  *
   256  * Errors are never displayed for XML-RPC requests.
   265  * Errors are never displayed for XML-RPC requests.
   257  *
   266  *
   258  * @access private
   267  * @since 3.0.0
   259  * @since 3.0.0
   268  * @access private
   260  */
   269  */
   261 function wp_debug_mode() {
   270 function wp_debug_mode() {
   262 	if ( WP_DEBUG ) {
   271 	if ( WP_DEBUG ) {
   263 		error_reporting( E_ALL );
   272 		error_reporting( E_ALL );
   264 
   273 
   277 	if ( defined( 'XMLRPC_REQUEST' ) )
   286 	if ( defined( 'XMLRPC_REQUEST' ) )
   278 		ini_set( 'display_errors', 0 );
   287 		ini_set( 'display_errors', 0 );
   279 }
   288 }
   280 
   289 
   281 /**
   290 /**
   282  * Sets the location of the language directory.
   291  * Set the location of the language directory.
   283  *
   292  *
   284  * To set directory manually, define <code>WP_LANG_DIR</code> in wp-config.php.
   293  * To set directory manually, define the `WP_LANG_DIR` constant
   285  *
   294  * in wp-config.php.
   286  * If the language directory exists within WP_CONTENT_DIR, that is used.
   295  *
   287  * Otherwise if the language directory exists within WPINC, that's used.
   296  * If the language directory exists within `WP_CONTENT_DIR`, it
   288  * Finally, if neither of the preceding directories are found,
   297  * is used. Otherwise the language directory is assumed to live
   289  * WP_CONTENT_DIR/languages is used.
   298  * in `WPINC`.
   290  *
   299  *
   291  * The WP_LANG_DIR constant was introduced in 2.1.0.
   300  * @since 3.0.0
   292  *
   301  * @access private
   293  * @access private
       
   294  * @since 3.0.0
       
   295  */
   302  */
   296 function wp_set_lang_dir() {
   303 function wp_set_lang_dir() {
   297 	if ( !defined( 'WP_LANG_DIR' ) ) {
   304 	if ( !defined( 'WP_LANG_DIR' ) ) {
   298 		if ( file_exists( WP_CONTENT_DIR . '/languages' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) || !@is_dir(ABSPATH . WPINC . '/languages') ) {
   305 		if ( file_exists( WP_CONTENT_DIR . '/languages' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) || !@is_dir(ABSPATH . WPINC . '/languages') ) {
   299 			define( 'WP_LANG_DIR', WP_CONTENT_DIR . '/languages' ); // no leading slash, no trailing slash, full path, not relative to ABSPATH
   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' );
   300 			if ( !defined( 'LANGDIR' ) ) {
   314 			if ( !defined( 'LANGDIR' ) ) {
   301 				// Old static relative path maintained for limited backwards compatibility - won't work in some cases
   315 				// Old static relative path maintained for limited backwards compatibility - won't work in some cases
   302 				define( 'LANGDIR', 'wp-content/languages' );
   316 				define( 'LANGDIR', 'wp-content/languages' );
   303 			}
   317 			}
   304 		} else {
   318 		} else {
   305 			define( 'WP_LANG_DIR', ABSPATH . WPINC . '/languages' ); // no leading slash, no trailing slash, full path, not relative to ABSPATH
   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' );
   306 			if ( !defined( 'LANGDIR' ) ) {
   327 			if ( !defined( 'LANGDIR' ) ) {
   307 				// Old relative path maintained for backwards compatibility
   328 				// Old relative path maintained for backwards compatibility
   308 				define( 'LANGDIR', WPINC . '/languages' );
   329 				define( 'LANGDIR', WPINC . '/languages' );
   309 			}
   330 			}
   310 		}
   331 		}
   311 	}
   332 	}
   312 }
   333 }
   313 
   334 
   314 /**
   335 /**
   315  * Load the correct database class file.
   336  * Load the database class file and instantiate the `$wpdb` global.
   316  *
       
   317  * This function is used to load the database class file either at runtime or by
       
   318  * wp-admin/setup-config.php. We must globalize $wpdb to ensure that it is
       
   319  * defined globally by the inline code in wp-db.php.
       
   320  *
   337  *
   321  * @since 2.5.0
   338  * @since 2.5.0
   322  * @global $wpdb WordPress Database Object
   339  *
       
   340  * @global wpdb $wpdb The WordPress database class.
   323  */
   341  */
   324 function require_wp_db() {
   342 function require_wp_db() {
   325 	global $wpdb;
   343 	global $wpdb;
   326 
   344 
   327 	require_once( ABSPATH . WPINC . '/wp-db.php' );
   345 	require_once( ABSPATH . WPINC . '/wp-db.php' );
   333 
   351 
   334 	$wpdb = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST );
   352 	$wpdb = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST );
   335 }
   353 }
   336 
   354 
   337 /**
   355 /**
   338  * Sets the database table prefix and the format specifiers for database table columns.
   356  * Set the database table prefix and the format specifiers for database
   339  *
   357  * table columns.
   340  * Columns not listed here default to %s.
   358  *
   341  *
   359  * Columns not listed here default to `%s`.
   342  * @see wpdb::$field_types Since 2.8.0
   360  *
   343  * @see wpdb::prepare()
   361  * @since 3.0.0
   344  * @see wpdb::insert()
   362  * @access private
   345  * @see wpdb::update()
   363  *
   346  * @see wpdb::set_prefix()
   364  * @global wpdb   $wpdb         The WordPress database class.
   347  *
   365  * @global string $table_prefix The database table prefix.
   348  * @access private
       
   349  * @since 3.0.0
       
   350  */
   366  */
   351 function wp_set_wpdb_vars() {
   367 function wp_set_wpdb_vars() {
   352 	global $wpdb, $table_prefix;
   368 	global $wpdb, $table_prefix;
   353 	if ( !empty( $wpdb->error ) )
   369 	if ( !empty( $wpdb->error ) )
   354 		dead_db();
   370 		dead_db();
   368 		wp_die( __( '<strong>ERROR</strong>: <code>$table_prefix</code> in <code>wp-config.php</code> can only contain numbers, letters, and underscores.' ) );
   384 		wp_die( __( '<strong>ERROR</strong>: <code>$table_prefix</code> in <code>wp-config.php</code> can only contain numbers, letters, and underscores.' ) );
   369 	}
   385 	}
   370 }
   386 }
   371 
   387 
   372 /**
   388 /**
   373  * Access/Modify private global variable $_wp_using_ext_object_cache
   389  * Access/Modify private global variable `$_wp_using_ext_object_cache`.
   374  *
   390  *
   375  * Toggle $_wp_using_ext_object_cache on and off without directly touching global
   391  * Toggle `$_wp_using_ext_object_cache` on and off without directly
       
   392  * touching global.
   376  *
   393  *
   377  * @since 3.7.0
   394  * @since 3.7.0
   378  *
   395  *
   379  * @param bool $using Whether external object cache is being used
   396  * @param bool $using Whether external object cache is being used.
   380  * @return bool The current 'using' setting
   397  * @return bool The current 'using' setting.
   381  */
   398  */
   382 function wp_using_ext_object_cache( $using = null ) {
   399 function wp_using_ext_object_cache( $using = null ) {
   383 	global $_wp_using_ext_object_cache;
   400 	global $_wp_using_ext_object_cache;
   384 	$current_using = $_wp_using_ext_object_cache;
   401 	$current_using = $_wp_using_ext_object_cache;
   385 	if ( null !== $using )
   402 	if ( null !== $using )
   386 		$_wp_using_ext_object_cache = $using;
   403 		$_wp_using_ext_object_cache = $using;
   387 	return $current_using;
   404 	return $current_using;
   388 }
   405 }
   389 
   406 
   390 /**
   407 /**
   391  * Starts the WordPress object cache.
   408  * Start the WordPress object cache.
   392  *
   409  *
   393  * If an object-cache.php file exists in the wp-content directory,
   410  * If an object-cache.php file exists in the wp-content directory,
   394  * it uses that drop-in as an external object cache.
   411  * it uses that drop-in as an external object cache.
   395  *
   412  *
   396  * @access private
   413  * @since 3.0.0
   397  * @since 3.0.0
   414  * @access private
       
   415  *
       
   416  * @global int $blog_id Blog ID.
   398  */
   417  */
   399 function wp_start_object_cache() {
   418 function wp_start_object_cache() {
   400 	global $blog_id;
   419 	global $blog_id;
   401 
   420 
   402 	$first_init = false;
   421 	$first_init = false;
   406 			if ( function_exists( 'wp_cache_init' ) )
   425 			if ( function_exists( 'wp_cache_init' ) )
   407 				wp_using_ext_object_cache( true );
   426 				wp_using_ext_object_cache( true );
   408 		}
   427 		}
   409 
   428 
   410 		$first_init = true;
   429 		$first_init = true;
   411 	} else if ( ! wp_using_ext_object_cache() && file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
   430 	} elseif ( ! wp_using_ext_object_cache() && file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
   412 		// Sometimes advanced-cache.php can load object-cache.php before it is loaded here.
   431 		/*
   413 		// This breaks the function_exists check above and can result in $_wp_using_ext_object_cache
   432 		 * Sometimes advanced-cache.php can load object-cache.php before
   414 		// being set incorrectly. Double check if an external cache exists.
   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 		 */
   415 		wp_using_ext_object_cache( true );
   437 		wp_using_ext_object_cache( true );
   416 	}
   438 	}
   417 
   439 
   418 	if ( ! wp_using_ext_object_cache() )
   440 	if ( ! wp_using_ext_object_cache() )
   419 		require_once ( ABSPATH . WPINC . '/cache.php' );
   441 		require_once ( ABSPATH . WPINC . '/cache.php' );
   420 
   442 
   421 	// If cache supports reset, reset instead of init if already initialized.
   443 	/*
   422 	// Reset signals to the cache that global IDs have changed and it may need to update keys
   444 	 * If cache supports reset, reset instead of init if already
   423 	// and cleanup caches.
   445 	 * initialized. Reset signals to the cache that global IDs
       
   446 	 * have changed and it may need to update keys and cleanup caches.
       
   447 	 */
   424 	if ( ! $first_init && function_exists( 'wp_cache_switch_to_blog' ) )
   448 	if ( ! $first_init && function_exists( 'wp_cache_switch_to_blog' ) )
   425 		wp_cache_switch_to_blog( $blog_id );
   449 		wp_cache_switch_to_blog( $blog_id );
   426 	elseif ( function_exists( 'wp_cache_init' ) )
   450 	elseif ( function_exists( 'wp_cache_init' ) )
   427 		wp_cache_init();
   451 		wp_cache_init();
   428 
   452 
   429 	if ( function_exists( 'wp_cache_add_global_groups' ) ) {
   453 	if ( function_exists( 'wp_cache_add_global_groups' ) ) {
   430 		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' ) );
   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' ) );
   431 		wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) );
   455 		wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) );
   432 	}
   456 	}
   433 }
   457 }
   434 
   458 
   435 /**
   459 /**
   436  * Redirects to the installer if WordPress is not installed.
   460  * Redirect to the installer if WordPress is not installed.
   437  *
   461  *
   438  * Dies with an error message when multisite is enabled.
   462  * Dies with an error message when Multisite is enabled.
   439  *
   463  *
   440  * @access private
   464  * @since 3.0.0
   441  * @since 3.0.0
   465  * @access private
   442  */
   466  */
   443 function wp_not_installed() {
   467 function wp_not_installed() {
   444 	if ( is_multisite() ) {
   468 	if ( is_multisite() ) {
   445 		if ( ! is_blog_installed() && ! defined( 'WP_INSTALLING' ) )
   469 		if ( ! is_blog_installed() && ! defined( 'WP_INSTALLING' ) ) {
       
   470 			nocache_headers();
       
   471 
   446 			wp_die( __( 'The site you have requested is not installed properly. Please contact the system administrator.' ) );
   472 			wp_die( __( 'The site you have requested is not installed properly. Please contact the system administrator.' ) );
   447 	} elseif ( ! is_blog_installed() && false === strpos( $_SERVER['PHP_SELF'], 'install.php' ) && !defined( 'WP_INSTALLING' ) ) {
   473 		}
       
   474 	} elseif ( ! is_blog_installed() && ! defined( 'WP_INSTALLING' ) ) {
       
   475 		nocache_headers();
       
   476 
   448 		require( ABSPATH . WPINC . '/kses.php' );
   477 		require( ABSPATH . WPINC . '/kses.php' );
   449 		require( ABSPATH . WPINC . '/pluggable.php' );
   478 		require( ABSPATH . WPINC . '/pluggable.php' );
   450 		require( ABSPATH . WPINC . '/formatting.php' );
   479 		require( ABSPATH . WPINC . '/formatting.php' );
   451 
   480 
   452 		$link = wp_guess_url() . '/wp-admin/install.php';
   481 		$link = wp_guess_url() . '/wp-admin/install.php';
   455 		die();
   484 		die();
   456 	}
   485 	}
   457 }
   486 }
   458 
   487 
   459 /**
   488 /**
   460  * Returns array of must-use plugin files to be included in global scope.
   489  * Retrieve an array of must-use plugin files.
   461  *
   490  *
   462  * The default directory is wp-content/mu-plugins. To change the default directory
   491  * The default directory is wp-content/mu-plugins. To change the default
   463  * manually, define <code>WPMU_PLUGIN_DIR</code> and <code>WPMU_PLUGIN_URL</code>
   492  * directory manually, define `WPMU_PLUGIN_DIR` and `WPMU_PLUGIN_URL`
   464  * in wp-config.php.
   493  * in wp-config.php.
   465  *
   494  *
   466  * @access private
   495  * @since 3.0.0
   467  * @since 3.0.0
   496  * @access private
   468  * @return array Files to include
   497  *
       
   498  * @return array Files to include.
   469  */
   499  */
   470 function wp_get_mu_plugins() {
   500 function wp_get_mu_plugins() {
   471 	$mu_plugins = array();
   501 	$mu_plugins = array();
   472 	if ( !is_dir( WPMU_PLUGIN_DIR ) )
   502 	if ( !is_dir( WPMU_PLUGIN_DIR ) )
   473 		return $mu_plugins;
   503 		return $mu_plugins;
   482 
   512 
   483 	return $mu_plugins;
   513 	return $mu_plugins;
   484 }
   514 }
   485 
   515 
   486 /**
   516 /**
   487  * Returns array of plugin files to be included in global scope.
   517  * Retrieve an array of active and valid plugin files.
   488  *
   518  *
   489  * The default directory is wp-content/plugins. To change the default directory
   519  * While upgrading or installing WordPress, no plugins are returned.
   490  * manually, define <code>WP_PLUGIN_DIR</code> and <code>WP_PLUGIN_URL</code>
   520  *
       
   521  * The default directory is wp-content/plugins. To change the default
       
   522  * directory manually, define `WP_PLUGIN_DIR` and `WP_PLUGIN_URL`
   491  * in wp-config.php.
   523  * in wp-config.php.
   492  *
   524  *
   493  * @access private
   525  * @since 3.0.0
   494  * @since 3.0.0
   526  * @access private
   495  * @return array Files to include
   527  *
       
   528  * @return array Files.
   496  */
   529  */
   497 function wp_get_active_and_valid_plugins() {
   530 function wp_get_active_and_valid_plugins() {
   498 	$plugins = array();
   531 	$plugins = array();
   499 	$active_plugins = (array) get_option( 'active_plugins', array() );
   532 	$active_plugins = (array) get_option( 'active_plugins', array() );
   500 
   533 
   520 	}
   553 	}
   521 	return $plugins;
   554 	return $plugins;
   522 }
   555 }
   523 
   556 
   524 /**
   557 /**
   525  * Sets internal encoding using mb_internal_encoding().
   558  * Set internal encoding.
   526  *
   559  *
   527  * In most cases the default internal encoding is latin1, which is of no use,
   560  * In most cases the default internal encoding is latin1, which is
   528  * since we want to use the mb_ functions for utf-8 strings.
   561  * of no use, since we want to use the `mb_` functions for `utf-8` strings.
   529  *
   562  *
   530  * @access private
   563  * @since 3.0.0
   531  * @since 3.0.0
   564  * @access private
   532  */
   565  */
   533 function wp_set_internal_encoding() {
   566 function wp_set_internal_encoding() {
   534 	if ( function_exists( 'mb_internal_encoding' ) ) {
   567 	if ( function_exists( 'mb_internal_encoding' ) ) {
   535 		$charset = get_option( 'blog_charset' );
   568 		$charset = get_option( 'blog_charset' );
   536 		if ( ! $charset || ! @mb_internal_encoding( $charset ) )
   569 		if ( ! $charset || ! @mb_internal_encoding( $charset ) )
   537 			mb_internal_encoding( 'UTF-8' );
   570 			mb_internal_encoding( 'UTF-8' );
   538 	}
   571 	}
   539 }
   572 }
   540 
   573 
   541 /**
   574 /**
   542  * Add magic quotes to $_GET, $_POST, $_COOKIE, and $_SERVER.
   575  * Add magic quotes to `$_GET`, `$_POST`, `$_COOKIE`, and `$_SERVER`.
   543  *
   576  *
   544  * Also forces $_REQUEST to be $_GET + $_POST. If $_SERVER, $_COOKIE,
   577  * Also forces `$_REQUEST` to be `$_GET + $_POST`. If `$_SERVER`,
   545  * or $_ENV are needed, use those superglobals directly.
   578  * `$_COOKIE`, or `$_ENV` are needed, use those superglobals directly.
   546  *
   579  *
   547  * @access private
   580  * @since 3.0.0
   548  * @since 3.0.0
   581  * @access private
   549  */
   582  */
   550 function wp_magic_quotes() {
   583 function wp_magic_quotes() {
   551 	// If already slashed, strip.
   584 	// If already slashed, strip.
   552 	if ( get_magic_quotes_gpc() ) {
   585 	if ( get_magic_quotes_gpc() ) {
   553 		$_GET    = stripslashes_deep( $_GET    );
   586 		$_GET    = stripslashes_deep( $_GET    );
   566 }
   599 }
   567 
   600 
   568 /**
   601 /**
   569  * Runs just before PHP shuts down execution.
   602  * Runs just before PHP shuts down execution.
   570  *
   603  *
   571  * @access private
       
   572  * @since 1.2.0
   604  * @since 1.2.0
       
   605  * @access private
   573  */
   606  */
   574 function shutdown_action_hook() {
   607 function shutdown_action_hook() {
   575 	/**
   608 	/**
   576 	 * Fires just before PHP shuts down execution.
   609 	 * Fires just before PHP shuts down execution.
   577 	 *
   610 	 *
   578 	 * @since 1.2.0
   611 	 * @since 1.2.0
   579 	 */
   612 	 */
   580 	do_action( 'shutdown' );
   613 	do_action( 'shutdown' );
       
   614 
   581 	wp_cache_close();
   615 	wp_cache_close();
   582 }
   616 }
   583 
   617 
   584 /**
   618 /**
   585  * Copy an object.
   619  * Copy an object.
   586  *
   620  *
   587  * @since 2.7.0
   621  * @since 2.7.0
   588  * @deprecated 3.2
   622  * @deprecated 3.2.0
   589  *
   623  *
   590  * @param object $object The object to clone
   624  * @param object $object The object to clone.
   591  * @return object The cloned object
   625  * @return object The cloned object.
   592  */
   626  */
   593 
       
   594 function wp_clone( $object ) {
   627 function wp_clone( $object ) {
   595 	// Use parens for clone to accommodate PHP 4. See #17880
   628 	// Use parens for clone to accommodate PHP 4. See #17880
   596 	return clone( $object );
   629 	return clone( $object );
   597 }
   630 }
   598 
   631 
   599 /**
   632 /**
   600  * Whether the current request is for a network or blog admin page
   633  * Whether the current request is for an administrative interface page.
   601  *
   634  *
   602  * Does not inform on whether the user is an admin! Use capability checks to
   635  * Does not check if the user is an administrator; {@see current_user_can()}
   603  * tell if the user should be accessing a section or not.
   636  * for checking roles and capabilities.
   604  *
   637  *
   605  * @since 1.5.1
   638  * @since 1.5.1
   606  *
   639  *
   607  * @return bool True if inside WordPress administration pages.
   640  * @return bool True if inside WordPress administration interface, false otherwise.
   608  */
   641  */
   609 function is_admin() {
   642 function is_admin() {
   610 	if ( isset( $GLOBALS['current_screen'] ) )
   643 	if ( isset( $GLOBALS['current_screen'] ) )
   611 		return $GLOBALS['current_screen']->in_admin();
   644 		return $GLOBALS['current_screen']->in_admin();
   612 	elseif ( defined( 'WP_ADMIN' ) )
   645 	elseif ( defined( 'WP_ADMIN' ) )
   614 
   647 
   615 	return false;
   648 	return false;
   616 }
   649 }
   617 
   650 
   618 /**
   651 /**
   619  * Whether the current request is for a blog admin screen /wp-admin/
   652  * Whether the current request is for a site's admininstrative interface.
   620  *
   653  *
   621  * Does not inform on whether the user is a blog admin! Use capability checks to
   654  * e.g. `/wp-admin/`
   622  * tell if the user should be accessing a section or not.
   655  *
       
   656  * Does not check if the user is an administrator; {@see current_user_can()}
       
   657  * for checking roles and capabilities.
   623  *
   658  *
   624  * @since 3.1.0
   659  * @since 3.1.0
   625  *
   660  *
   626  * @return bool True if inside WordPress network administration pages.
   661  * @return bool True if inside WordPress blog administration pages.
   627  */
   662  */
   628 function is_blog_admin() {
   663 function is_blog_admin() {
   629 	if ( isset( $GLOBALS['current_screen'] ) )
   664 	if ( isset( $GLOBALS['current_screen'] ) )
   630 		return $GLOBALS['current_screen']->in_admin( 'site' );
   665 		return $GLOBALS['current_screen']->in_admin( 'site' );
   631 	elseif ( defined( 'WP_BLOG_ADMIN' ) )
   666 	elseif ( defined( 'WP_BLOG_ADMIN' ) )
   633 
   668 
   634 	return false;
   669 	return false;
   635 }
   670 }
   636 
   671 
   637 /**
   672 /**
   638  * Whether the current request is for a network admin screen /wp-admin/network/
   673  * Whether the current request is for the network administrative interface.
   639  *
   674  *
   640  * Does not inform on whether the user is a network admin! Use capability checks to
   675  * e.g. `/wp-admin/network/`
   641  * tell if the user should be accessing a section or not.
   676  *
       
   677  * Does not check if the user is an administrator; {@see current_user_can()}
       
   678  * for checking roles and capabilities.
   642  *
   679  *
   643  * @since 3.1.0
   680  * @since 3.1.0
   644  *
   681  *
   645  * @return bool True if inside WordPress network administration pages.
   682  * @return bool True if inside WordPress network administration pages.
   646  */
   683  */
   652 
   689 
   653 	return false;
   690 	return false;
   654 }
   691 }
   655 
   692 
   656 /**
   693 /**
   657  * Whether the current request is for a user admin screen /wp-admin/user/
   694  * Whether the current request is for a user admin screen.
   658  *
   695  *
   659  * Does not inform on whether the user is an admin! Use capability checks to
   696  * e.g. `/wp-admin/user/`
   660  * tell if the user should be accessing a section or not.
   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()}.
   661  *
   701  *
   662  * @since 3.1.0
   702  * @since 3.1.0
   663  *
   703  *
   664  * @return bool True if inside WordPress user administration pages.
   704  * @return bool True if inside WordPress user administration pages.
   665  */
   705  */
   671 
   711 
   672 	return false;
   712 	return false;
   673 }
   713 }
   674 
   714 
   675 /**
   715 /**
   676  * Whether Multisite support is enabled
   716  * If Multisite is enabled.
   677  *
   717  *
   678  * @since 3.0.0
   718  * @since 3.0.0
   679  *
   719  *
   680  * @return bool True if multisite is enabled, false otherwise.
   720  * @return bool True if Multisite is enabled, false otherwise.
   681  */
   721  */
   682 function is_multisite() {
   722 function is_multisite() {
   683 	if ( defined( 'MULTISITE' ) )
   723 	if ( defined( 'MULTISITE' ) )
   684 		return MULTISITE;
   724 		return MULTISITE;
   685 
   725 
   688 
   728 
   689 	return false;
   729 	return false;
   690 }
   730 }
   691 
   731 
   692 /**
   732 /**
   693  * Retrieve the current blog id
   733  * Retrieve the current blog ID.
   694  *
   734  *
   695  * @since 3.1.0
   735  * @since 3.1.0
   696  *
   736  *
   697  * @return int Blog id
   737  * @return int Blog id
   698  */
   738  */
   700 	global $blog_id;
   740 	global $blog_id;
   701 	return absint($blog_id);
   741 	return absint($blog_id);
   702 }
   742 }
   703 
   743 
   704 /**
   744 /**
   705  * Attempts an early load of translations.
   745  * Attempt an early load of translations.
   706  *
   746  *
   707  * Used for errors encountered during the initial loading process, before the locale has been
   747  * Used for errors encountered during the initial loading process, before
   708  * properly detected and loaded.
   748  * the locale has been properly detected and loaded.
   709  *
   749  *
   710  * Designed for unusual load sequences (like setup-config.php) or for when the script will then
   750  * Designed for unusual load sequences (like setup-config.php) or for when
   711  * terminate with an error, otherwise there is a risk that a file can be double-included.
   751  * the script will then terminate with an error, otherwise there is a risk
       
   752  * that a file can be double-included.
   712  *
   753  *
   713  * @since 3.4.0
   754  * @since 3.4.0
   714  * @access private
   755  * @access private
       
   756  *
       
   757  * @global $wp_locale The WordPress date and time locale object.
   715  */
   758  */
   716 function wp_load_translations_early() {
   759 function wp_load_translations_early() {
   717 	global $text_direction, $wp_locale;
   760 	global $text_direction, $wp_locale;
   718 
   761 
   719 	static $loaded = false;
   762 	static $loaded = false;