wp/wp-includes/load.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
    11  * @since 4.4.0
    11  * @since 4.4.0
    12  *
    12  *
    13  * @return string The HTTP protocol. Default: HTTP/1.0.
    13  * @return string The HTTP protocol. Default: HTTP/1.0.
    14  */
    14  */
    15 function wp_get_server_protocol() {
    15 function wp_get_server_protocol() {
    16 	$protocol = $_SERVER['SERVER_PROTOCOL'];
    16 	$protocol = isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : '';
    17 	if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0' ) ) ) {
    17 	if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0' ), true ) ) {
    18 		$protocol = 'HTTP/1.0';
    18 		$protocol = 'HTTP/1.0';
    19 	}
    19 	}
    20 	return $protocol;
    20 	return $protocol;
    21 }
       
    22 
       
    23 /**
       
    24  * Turn register globals off.
       
    25  *
       
    26  * @since 2.1.0
       
    27  * @access private
       
    28  */
       
    29 function wp_unregister_GLOBALS() {
       
    30 	if ( ! ini_get( 'register_globals' ) ) {
       
    31 		return;
       
    32 	}
       
    33 
       
    34 	if ( isset( $_REQUEST['GLOBALS'] ) ) {
       
    35 		die( 'GLOBALS overwrite attempt detected' );
       
    36 	}
       
    37 
       
    38 	// Variables that shouldn't be unset
       
    39 	$no_unset = array( 'GLOBALS', '_GET', '_POST', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES', 'table_prefix' );
       
    40 
       
    41 	$input = array_merge( $_GET, $_POST, $_COOKIE, $_SERVER, $_ENV, $_FILES, isset( $_SESSION ) && is_array( $_SESSION ) ? $_SESSION : array() );
       
    42 	foreach ( $input as $k => $v ) {
       
    43 		if ( ! in_array( $k, $no_unset ) && isset( $GLOBALS[ $k ] ) ) {
       
    44 			unset( $GLOBALS[ $k ] );
       
    45 		}
       
    46 	}
       
    47 }
    21 }
    48 
    22 
    49 /**
    23 /**
    50  * Fix `$_SERVER` variables for various setups.
    24  * Fix `$_SERVER` variables for various setups.
    51  *
    25  *
    63 		'REQUEST_URI'     => '',
    37 		'REQUEST_URI'     => '',
    64 	);
    38 	);
    65 
    39 
    66 	$_SERVER = array_merge( $default_server_values, $_SERVER );
    40 	$_SERVER = array_merge( $default_server_values, $_SERVER );
    67 
    41 
    68 	// Fix for IIS when running with PHP ISAPI
    42 	// Fix for IIS when running with PHP ISAPI.
    69 	if ( empty( $_SERVER['REQUEST_URI'] ) || ( PHP_SAPI != 'cgi-fcgi' && preg_match( '/^Microsoft-IIS\//', $_SERVER['SERVER_SOFTWARE'] ) ) ) {
    43 	if ( empty( $_SERVER['REQUEST_URI'] ) || ( 'cgi-fcgi' !== PHP_SAPI && preg_match( '/^Microsoft-IIS\//', $_SERVER['SERVER_SOFTWARE'] ) ) ) {
    70 
    44 
    71 		if ( isset( $_SERVER['HTTP_X_ORIGINAL_URL'] ) ) {
    45 		if ( isset( $_SERVER['HTTP_X_ORIGINAL_URL'] ) ) {
    72 			// IIS Mod-Rewrite
    46 			// IIS Mod-Rewrite.
    73 			$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
    47 			$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
    74 		} elseif ( isset( $_SERVER['HTTP_X_REWRITE_URL'] ) ) {
    48 		} elseif ( isset( $_SERVER['HTTP_X_REWRITE_URL'] ) ) {
    75 			// IIS Isapi_Rewrite
    49 			// IIS Isapi_Rewrite.
    76 			$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
    50 			$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
    77 		} else {
    51 		} else {
    78 			// Use ORIG_PATH_INFO if there is no PATH_INFO
    52 			// Use ORIG_PATH_INFO if there is no PATH_INFO.
    79 			if ( ! isset( $_SERVER['PATH_INFO'] ) && isset( $_SERVER['ORIG_PATH_INFO'] ) ) {
    53 			if ( ! isset( $_SERVER['PATH_INFO'] ) && isset( $_SERVER['ORIG_PATH_INFO'] ) ) {
    80 				$_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'];
    54 				$_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'];
    81 			}
    55 			}
    82 
    56 
    83 			// Some IIS + PHP configurations puts the script-name in the path-info (No need to append it twice)
    57 			// Some IIS + PHP configurations put the script-name in the path-info (no need to append it twice).
    84 			if ( isset( $_SERVER['PATH_INFO'] ) ) {
    58 			if ( isset( $_SERVER['PATH_INFO'] ) ) {
    85 				if ( $_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME'] ) {
    59 				if ( $_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME'] ) {
    86 					$_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'];
    60 					$_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'];
    87 				} else {
    61 				} else {
    88 					$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO'];
    62 					$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO'];
    89 				}
    63 				}
    90 			}
    64 			}
    91 
    65 
    92 			// Append the query string if it exists and isn't null
    66 			// Append the query string if it exists and isn't null.
    93 			if ( ! empty( $_SERVER['QUERY_STRING'] ) ) {
    67 			if ( ! empty( $_SERVER['QUERY_STRING'] ) ) {
    94 				$_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
    68 				$_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
    95 			}
    69 			}
    96 		}
    70 		}
    97 	}
    71 	}
    98 
    72 
    99 	// Fix for PHP as CGI hosts that set SCRIPT_FILENAME to something ending in php.cgi for all requests
    73 	// Fix for PHP as CGI hosts that set SCRIPT_FILENAME to something ending in php.cgi for all requests.
   100 	if ( isset( $_SERVER['SCRIPT_FILENAME'] ) && ( strpos( $_SERVER['SCRIPT_FILENAME'], 'php.cgi' ) == strlen( $_SERVER['SCRIPT_FILENAME'] ) - 7 ) ) {
    74 	if ( isset( $_SERVER['SCRIPT_FILENAME'] ) && ( strpos( $_SERVER['SCRIPT_FILENAME'], 'php.cgi' ) == strlen( $_SERVER['SCRIPT_FILENAME'] ) - 7 ) ) {
   101 		$_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED'];
    75 		$_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED'];
   102 	}
    76 	}
   103 
    77 
   104 	// Fix for Dreamhost and other PHP as CGI hosts
    78 	// Fix for Dreamhost and other PHP as CGI hosts.
   105 	if ( strpos( $_SERVER['SCRIPT_NAME'], 'php.cgi' ) !== false ) {
    79 	if ( strpos( $_SERVER['SCRIPT_NAME'], 'php.cgi' ) !== false ) {
   106 		unset( $_SERVER['PATH_INFO'] );
    80 		unset( $_SERVER['PATH_INFO'] );
   107 	}
    81 	}
   108 
    82 
   109 	// Fix empty PHP_SELF
    83 	// Fix empty PHP_SELF.
   110 	$PHP_SELF = $_SERVER['PHP_SELF'];
    84 	$PHP_SELF = $_SERVER['PHP_SELF'];
   111 	if ( empty( $PHP_SELF ) ) {
    85 	if ( empty( $PHP_SELF ) ) {
   112 		$_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace( '/(\?.*)?$/', '', $_SERVER['REQUEST_URI'] );
    86 		$_SERVER['PHP_SELF'] = preg_replace( '/(\?.*)?$/', '', $_SERVER['REQUEST_URI'] );
       
    87 		$PHP_SELF            = $_SERVER['PHP_SELF'];
   113 	}
    88 	}
   114 }
    89 }
   115 
    90 
   116 /**
    91 /**
   117  * Check for the required PHP version, and the MySQL extension or
    92  * Check for the required PHP version, and the MySQL extension or
   128 function wp_check_php_mysql_versions() {
   103 function wp_check_php_mysql_versions() {
   129 	global $required_php_version, $wp_version;
   104 	global $required_php_version, $wp_version;
   130 	$php_version = phpversion();
   105 	$php_version = phpversion();
   131 
   106 
   132 	if ( version_compare( $required_php_version, $php_version, '>' ) ) {
   107 	if ( version_compare( $required_php_version, $php_version, '>' ) ) {
   133 		wp_load_translations_early();
       
   134 
       
   135 		$protocol = wp_get_server_protocol();
   108 		$protocol = wp_get_server_protocol();
   136 		header( sprintf( '%s 500 Internal Server Error', $protocol ), true, 500 );
   109 		header( sprintf( '%s 500 Internal Server Error', $protocol ), true, 500 );
   137 		header( 'Content-Type: text/html; charset=utf-8' );
   110 		header( 'Content-Type: text/html; charset=utf-8' );
   138 		/* translators: 1: Current PHP version number, 2: WordPress version number, 3: Minimum required PHP version number */
   111 		printf( 'Your server is running PHP version %1$s but WordPress %2$s requires at least %3$s.', $php_version, $wp_version, $required_php_version );
   139 		printf( __( 'Your server is running PHP version %1$s but WordPress %2$s requires at least %3$s.' ), $php_version, $wp_version, $required_php_version );
       
   140 		exit( 1 );
   112 		exit( 1 );
   141 	}
   113 	}
   142 
   114 
   143 	if ( ! extension_loaded( 'mysql' ) && ! extension_loaded( 'mysqli' ) && ! extension_loaded( 'mysqlnd' ) && ! file_exists( WP_CONTENT_DIR . '/db.php' ) ) {
   115 	if ( ! extension_loaded( 'mysql' ) && ! extension_loaded( 'mysqli' ) && ! extension_loaded( 'mysqlnd' ) && ! file_exists( WP_CONTENT_DIR . '/db.php' ) ) {
   144 		require_once( ABSPATH . WPINC . '/functions.php' );
   116 		require_once ABSPATH . WPINC . '/functions.php';
   145 		wp_load_translations_early();
   117 		wp_load_translations_early();
   146 		$args = array(
   118 		$args = array(
   147 			'exit' => false,
   119 			'exit' => false,
   148 			'code' => 'mysql_not_found',
   120 			'code' => 'mysql_not_found',
   149 		);
   121 		);
   150 		wp_die(
   122 		wp_die(
   151 			__( 'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.' ),
   123 			__( 'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.' ),
   152 			__( 'Insufficient Requirements' ),
   124 			__( 'Requirements Not Met' ),
   153 			$args
   125 			$args
   154 		);
   126 		);
   155 		exit( 1 );
   127 		exit( 1 );
   156 	}
   128 	}
   157 }
   129 }
   158 
   130 
   159 /**
   131 /**
       
   132  * Retrieves the current environment type.
       
   133  *
       
   134  * The type can be set via the `WP_ENVIRONMENT_TYPE` global system variable,
       
   135  * or a constant of the same name.
       
   136  *
       
   137  * Possible values include 'local', 'development', 'staging', 'production'.
       
   138  * If not set, the type defaults to 'production'.
       
   139  *
       
   140  * @since 5.5.0
       
   141  * @since 5.5.1 Added the 'local' type.
       
   142  * @since 5.5.1 Removed the ability to alter the list of types.
       
   143  *
       
   144  * @return string The current environment type.
       
   145  */
       
   146 function wp_get_environment_type() {
       
   147 	static $current_env = '';
       
   148 
       
   149 	if ( $current_env ) {
       
   150 		return $current_env;
       
   151 	}
       
   152 
       
   153 	$wp_environments = array(
       
   154 		'local',
       
   155 		'development',
       
   156 		'staging',
       
   157 		'production',
       
   158 	);
       
   159 
       
   160 	// Add a note about the deprecated WP_ENVIRONMENT_TYPES constant.
       
   161 	if ( defined( 'WP_ENVIRONMENT_TYPES' ) && function_exists( '_deprecated_argument' ) ) {
       
   162 		if ( function_exists( '__' ) ) {
       
   163 			/* translators: %s: WP_ENVIRONMENT_TYPES */
       
   164 			$message = sprintf( __( 'The %s constant is no longer supported.' ), 'WP_ENVIRONMENT_TYPES' );
       
   165 		} else {
       
   166 			$message = sprintf( 'The %s constant is no longer supported.', 'WP_ENVIRONMENT_TYPES' );
       
   167 		}
       
   168 
       
   169 		_deprecated_argument(
       
   170 			'define()',
       
   171 			'5.5.1',
       
   172 			$message
       
   173 		);
       
   174 	}
       
   175 
       
   176 	// Check if the environment variable has been set, if `getenv` is available on the system.
       
   177 	if ( function_exists( 'getenv' ) ) {
       
   178 		$has_env = getenv( 'WP_ENVIRONMENT_TYPE' );
       
   179 		if ( false !== $has_env ) {
       
   180 			$current_env = $has_env;
       
   181 		}
       
   182 	}
       
   183 
       
   184 	// Fetch the environment from a constant, this overrides the global system variable.
       
   185 	if ( defined( 'WP_ENVIRONMENT_TYPE' ) ) {
       
   186 		$current_env = WP_ENVIRONMENT_TYPE;
       
   187 	}
       
   188 
       
   189 	// Make sure the environment is an allowed one, and not accidentally set to an invalid value.
       
   190 	if ( ! in_array( $current_env, $wp_environments, true ) ) {
       
   191 		$current_env = 'production';
       
   192 	}
       
   193 
       
   194 	return $current_env;
       
   195 }
       
   196 
       
   197 /**
   160  * Don't load all of WordPress when handling a favicon.ico request.
   198  * Don't load all of WordPress when handling a favicon.ico request.
   161  *
   199  *
   162  * Instead, send the headers for a zero-length favicon and bail.
   200  * Instead, send the headers for a zero-length favicon and bail.
   163  *
   201  *
   164  * @since 3.0.0
   202  * @since 3.0.0
       
   203  * @deprecated 5.4.0 Deprecated in favor of do_favicon().
   165  */
   204  */
   166 function wp_favicon_request() {
   205 function wp_favicon_request() {
   167 	if ( '/favicon.ico' == $_SERVER['REQUEST_URI'] ) {
   206 	if ( '/favicon.ico' === $_SERVER['REQUEST_URI'] ) {
   168 		header( 'Content-Type: image/vnd.microsoft.icon' );
   207 		header( 'Content-Type: image/vnd.microsoft.icon' );
   169 		exit;
   208 		exit;
   170 	}
   209 	}
   171 }
   210 }
   172 
   211 
   173 /**
   212 /**
   174  * Die with a maintenance message when conditions are met.
   213  * Die with a maintenance message when conditions are met.
   175  *
   214  *
   176  * Checks for a file in the WordPress root directory named ".maintenance".
       
   177  * This file will contain the variable $upgrading, set to the time the file
       
   178  * was created. If the file was created less than 10 minutes ago, WordPress
       
   179  * enters maintenance mode and displays a message.
       
   180  *
       
   181  * The default message can be replaced by using a drop-in (maintenance.php in
   215  * The default message can be replaced by using a drop-in (maintenance.php in
   182  * the wp-content directory).
   216  * the wp-content directory).
   183  *
   217  *
   184  * @since 3.0.0
   218  * @since 3.0.0
   185  * @access private
   219  * @access private
   186  *
       
   187  * @global int $upgrading the unix timestamp marking when upgrading WordPress began.
       
   188  */
   220  */
   189 function wp_maintenance() {
   221 function wp_maintenance() {
   190 	if ( ! file_exists( ABSPATH . '.maintenance' ) || wp_installing() ) {
   222 	// Return if maintenance mode is disabled.
       
   223 	if ( ! wp_is_maintenance_mode() ) {
   191 		return;
   224 		return;
   192 	}
   225 	}
   193 
   226 
   194 	global $upgrading;
       
   195 
       
   196 	include( ABSPATH . '.maintenance' );
       
   197 	// If the $upgrading timestamp is older than 10 minutes, don't die.
       
   198 	if ( ( time() - $upgrading ) >= 600 ) {
       
   199 		return;
       
   200 	}
       
   201 
       
   202 	/**
       
   203 	 * Filters whether to enable maintenance mode.
       
   204 	 *
       
   205 	 * This filter runs before it can be used by plugins. It is designed for
       
   206 	 * non-web runtimes. If this filter returns true, maintenance mode will be
       
   207 	 * active and the request will end. If false, the request will be allowed to
       
   208 	 * continue processing even if maintenance mode should be active.
       
   209 	 *
       
   210 	 * @since 4.6.0
       
   211 	 *
       
   212 	 * @param bool $enable_checks Whether to enable maintenance mode. Default true.
       
   213 	 * @param int  $upgrading     The timestamp set in the .maintenance file.
       
   214 	 */
       
   215 	if ( ! apply_filters( 'enable_maintenance_mode', true, $upgrading ) ) {
       
   216 		return;
       
   217 	}
       
   218 
       
   219 	if ( file_exists( WP_CONTENT_DIR . '/maintenance.php' ) ) {
   227 	if ( file_exists( WP_CONTENT_DIR . '/maintenance.php' ) ) {
   220 		require_once( WP_CONTENT_DIR . '/maintenance.php' );
   228 		require_once WP_CONTENT_DIR . '/maintenance.php';
   221 		die();
   229 		die();
   222 	}
   230 	}
   223 
   231 
   224 	require_once( ABSPATH . WPINC . '/functions.php' );
   232 	require_once ABSPATH . WPINC . '/functions.php';
   225 	wp_load_translations_early();
   233 	wp_load_translations_early();
   226 
   234 
   227 	header( 'Retry-After: 600' );
   235 	header( 'Retry-After: 600' );
   228 
   236 
   229 	wp_die(
   237 	wp_die(
   230 		__( 'Briefly unavailable for scheduled maintenance. Check back in a minute.' ),
   238 		__( 'Briefly unavailable for scheduled maintenance. Check back in a minute.' ),
   231 		__( 'Maintenance' ),
   239 		__( 'Maintenance' ),
   232 		503
   240 		503
   233 	);
   241 	);
       
   242 }
       
   243 
       
   244 /**
       
   245  * Check if maintenance mode is enabled.
       
   246  *
       
   247  * Checks for a file in the WordPress root directory named ".maintenance".
       
   248  * This file will contain the variable $upgrading, set to the time the file
       
   249  * was created. If the file was created less than 10 minutes ago, WordPress
       
   250  * is in maintenance mode.
       
   251  *
       
   252  * @since 5.5.0
       
   253  *
       
   254  * @global int $upgrading The Unix timestamp marking when upgrading WordPress began.
       
   255  *
       
   256  * @return bool True if maintenance mode is enabled, false otherwise.
       
   257  */
       
   258 function wp_is_maintenance_mode() {
       
   259 	global $upgrading;
       
   260 
       
   261 	if ( ! file_exists( ABSPATH . '.maintenance' ) || wp_installing() ) {
       
   262 		return false;
       
   263 	}
       
   264 
       
   265 	require ABSPATH . '.maintenance';
       
   266 	// If the $upgrading timestamp is older than 10 minutes, consider maintenance over.
       
   267 	if ( ( time() - $upgrading ) >= 10 * MINUTE_IN_SECONDS ) {
       
   268 		return false;
       
   269 	}
       
   270 
       
   271 	/**
       
   272 	 * Filters whether to enable maintenance mode.
       
   273 	 *
       
   274 	 * This filter runs before it can be used by plugins. It is designed for
       
   275 	 * non-web runtimes. If this filter returns true, maintenance mode will be
       
   276 	 * active and the request will end. If false, the request will be allowed to
       
   277 	 * continue processing even if maintenance mode should be active.
       
   278 	 *
       
   279 	 * @since 4.6.0
       
   280 	 *
       
   281 	 * @param bool $enable_checks Whether to enable maintenance mode. Default true.
       
   282 	 * @param int  $upgrading     The timestamp set in the .maintenance file.
       
   283 	 */
       
   284 	if ( ! apply_filters( 'enable_maintenance_mode', true, $upgrading ) ) {
       
   285 		return false;
       
   286 	}
       
   287 
       
   288 	return true;
   234 }
   289 }
   235 
   290 
   236 /**
   291 /**
   237  * Start the WordPress micro-timer.
   292  * Start the WordPress micro-timer.
   238  *
   293  *
   312 	/**
   367 	/**
   313 	 * Filters whether to allow the debug mode check to occur.
   368 	 * Filters whether to allow the debug mode check to occur.
   314 	 *
   369 	 *
   315 	 * This filter runs before it can be used by plugins. It is designed for
   370 	 * This filter runs before it can be used by plugins. It is designed for
   316 	 * non-web run-times. Returning false causes the `WP_DEBUG` and related
   371 	 * non-web run-times. Returning false causes the `WP_DEBUG` and related
   317 	 * constants to not be checked and the default php values for errors
   372 	 * constants to not be checked and the default PHP values for errors
   318 	 * will be used unless you take care to update them yourself.
   373 	 * will be used unless you take care to update them yourself.
   319 	 *
   374 	 *
   320 	 * @since 4.6.0
   375 	 * @since 4.6.0
   321 	 *
   376 	 *
   322 	 * @param bool $enable_debug_mode Whether to enable debug mode checks to occur. Default true.
   377 	 * @param bool $enable_debug_mode Whether to enable debug mode checks to occur. Default true.
   349 	} else {
   404 	} else {
   350 		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 );
   405 		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 );
   351 	}
   406 	}
   352 
   407 
   353 	if ( defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || ( defined( 'WP_INSTALLING' ) && WP_INSTALLING ) || wp_doing_ajax() || wp_is_json_request() ) {
   408 	if ( defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || ( defined( 'WP_INSTALLING' ) && WP_INSTALLING ) || wp_doing_ajax() || wp_is_json_request() ) {
   354 		@ini_set( 'display_errors', 0 );
   409 		ini_set( 'display_errors', 0 );
   355 	}
   410 	}
   356 }
   411 }
   357 
   412 
   358 /**
   413 /**
   359  * Set the location of the language directory.
   414  * Set the location of the language directory.
   403 /**
   458 /**
   404  * Load the database class file and instantiate the `$wpdb` global.
   459  * Load the database class file and instantiate the `$wpdb` global.
   405  *
   460  *
   406  * @since 2.5.0
   461  * @since 2.5.0
   407  *
   462  *
   408  * @global wpdb $wpdb The WordPress database class.
   463  * @global wpdb $wpdb WordPress database abstraction object.
   409  */
   464  */
   410 function require_wp_db() {
   465 function require_wp_db() {
   411 	global $wpdb;
   466 	global $wpdb;
   412 
   467 
   413 	require_once( ABSPATH . WPINC . '/wp-db.php' );
   468 	require_once ABSPATH . WPINC . '/wp-db.php';
   414 	if ( file_exists( WP_CONTENT_DIR . '/db.php' ) ) {
   469 	if ( file_exists( WP_CONTENT_DIR . '/db.php' ) ) {
   415 		require_once( WP_CONTENT_DIR . '/db.php' );
   470 		require_once WP_CONTENT_DIR . '/db.php';
   416 	}
   471 	}
   417 
   472 
   418 	if ( isset( $wpdb ) ) {
   473 	if ( isset( $wpdb ) ) {
   419 		return;
   474 		return;
   420 	}
   475 	}
   434  * Columns not listed here default to `%s`.
   489  * Columns not listed here default to `%s`.
   435  *
   490  *
   436  * @since 3.0.0
   491  * @since 3.0.0
   437  * @access private
   492  * @access private
   438  *
   493  *
   439  * @global wpdb   $wpdb         The WordPress database class.
   494  * @global wpdb   $wpdb         WordPress database abstraction object.
   440  * @global string $table_prefix The database table prefix.
   495  * @global string $table_prefix The database table prefix.
   441  */
   496  */
   442 function wp_set_wpdb_vars() {
   497 function wp_set_wpdb_vars() {
   443 	global $wpdb, $table_prefix;
   498 	global $wpdb, $table_prefix;
   444 	if ( ! empty( $wpdb->error ) ) {
   499 	if ( ! empty( $wpdb->error ) ) {
   470 		'post_id'          => '%d',
   525 		'post_id'          => '%d',
   471 		'user_status'      => '%d',
   526 		'user_status'      => '%d',
   472 		'umeta_id'         => '%d',
   527 		'umeta_id'         => '%d',
   473 		'comment_karma'    => '%d',
   528 		'comment_karma'    => '%d',
   474 		'comment_count'    => '%d',
   529 		'comment_count'    => '%d',
   475 		// multisite:
   530 		// Multisite:
   476 		'active'           => '%d',
   531 		'active'           => '%d',
   477 		'cat_id'           => '%d',
   532 		'cat_id'           => '%d',
   478 		'deleted'          => '%d',
   533 		'deleted'          => '%d',
   479 		'lang_id'          => '%d',
   534 		'lang_id'          => '%d',
   480 		'mature'           => '%d',
   535 		'mature'           => '%d',
   486 	$prefix = $wpdb->set_prefix( $table_prefix );
   541 	$prefix = $wpdb->set_prefix( $table_prefix );
   487 
   542 
   488 	if ( is_wp_error( $prefix ) ) {
   543 	if ( is_wp_error( $prefix ) ) {
   489 		wp_load_translations_early();
   544 		wp_load_translations_early();
   490 		wp_die(
   545 		wp_die(
   491 			/* translators: 1: $table_prefix, 2: wp-config.php */
       
   492 			sprintf(
   546 			sprintf(
   493 				__( '<strong>ERROR</strong>: %1$s in %2$s can only contain numbers, letters, and underscores.' ),
   547 				/* translators: 1: $table_prefix, 2: wp-config.php */
       
   548 				__( '<strong>Error</strong>: %1$s in %2$s can only contain numbers, letters, and underscores.' ),
   494 				'<code>$table_prefix</code>',
   549 				'<code>$table_prefix</code>',
   495 				'<code>wp-config.php</code>'
   550 				'<code>wp-config.php</code>'
   496 			)
   551 			)
   497 		);
   552 		);
   498 	}
   553 	}
   543 			 * We try to load a custom caching backend, and then, if it
   598 			 * We try to load a custom caching backend, and then, if it
   544 			 * results in a wp_cache_init() function existing, we note
   599 			 * results in a wp_cache_init() function existing, we note
   545 			 * that an external object cache is being used.
   600 			 * that an external object cache is being used.
   546 			 */
   601 			 */
   547 			if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
   602 			if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
   548 				require_once( WP_CONTENT_DIR . '/object-cache.php' );
   603 				require_once WP_CONTENT_DIR . '/object-cache.php';
   549 				if ( function_exists( 'wp_cache_init' ) ) {
   604 				if ( function_exists( 'wp_cache_init' ) ) {
   550 					wp_using_ext_object_cache( true );
   605 					wp_using_ext_object_cache( true );
   551 				}
   606 				}
   552 
   607 
   553 				// Re-initialize any hooks added manually by object-cache.php
   608 				// Re-initialize any hooks added manually by object-cache.php.
   554 				if ( $wp_filter ) {
   609 				if ( $wp_filter ) {
   555 					$wp_filter = WP_Hook::build_preinitialized_hooks( $wp_filter );
   610 					$wp_filter = WP_Hook::build_preinitialized_hooks( $wp_filter );
   556 				}
   611 				}
   557 			}
   612 			}
   558 		} elseif ( ! wp_using_ext_object_cache() && file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
   613 		} elseif ( ! wp_using_ext_object_cache() && file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
   565 			wp_using_ext_object_cache( true );
   620 			wp_using_ext_object_cache( true );
   566 		}
   621 		}
   567 	}
   622 	}
   568 
   623 
   569 	if ( ! wp_using_ext_object_cache() ) {
   624 	if ( ! wp_using_ext_object_cache() ) {
   570 		require_once( ABSPATH . WPINC . '/cache.php' );
   625 		require_once ABSPATH . WPINC . '/cache.php';
   571 	}
   626 	}
       
   627 
       
   628 	require_once ABSPATH . WPINC . '/cache-compat.php';
   572 
   629 
   573 	/*
   630 	/*
   574 	 * If cache supports reset, reset instead of init if already
   631 	 * If cache supports reset, reset instead of init if already
   575 	 * initialized. Reset signals to the cache that global IDs
   632 	 * initialized. Reset signals to the cache that global IDs
   576 	 * have changed and it may need to update keys and cleanup caches.
   633 	 * have changed and it may need to update keys and cleanup caches.
   605 			wp_die( __( 'The site you have requested is not installed properly. Please contact the system administrator.' ) );
   662 			wp_die( __( 'The site you have requested is not installed properly. Please contact the system administrator.' ) );
   606 		}
   663 		}
   607 	} elseif ( ! is_blog_installed() && ! wp_installing() ) {
   664 	} elseif ( ! is_blog_installed() && ! wp_installing() ) {
   608 		nocache_headers();
   665 		nocache_headers();
   609 
   666 
   610 		require( ABSPATH . WPINC . '/kses.php' );
   667 		require ABSPATH . WPINC . '/kses.php';
   611 		require( ABSPATH . WPINC . '/pluggable.php' );
   668 		require ABSPATH . WPINC . '/pluggable.php';
   612 
   669 
   613 		$link = wp_guess_url() . '/wp-admin/install.php';
   670 		$link = wp_guess_url() . '/wp-admin/install.php';
   614 
   671 
   615 		wp_redirect( $link );
   672 		wp_redirect( $link );
   616 		die();
   673 		die();
   625  * in wp-config.php.
   682  * in wp-config.php.
   626  *
   683  *
   627  * @since 3.0.0
   684  * @since 3.0.0
   628  * @access private
   685  * @access private
   629  *
   686  *
   630  * @return array Files to include.
   687  * @return string[] Array of absolute paths of files to include.
   631  */
   688  */
   632 function wp_get_mu_plugins() {
   689 function wp_get_mu_plugins() {
   633 	$mu_plugins = array();
   690 	$mu_plugins = array();
   634 	if ( ! is_dir( WPMU_PLUGIN_DIR ) ) {
   691 	if ( ! is_dir( WPMU_PLUGIN_DIR ) ) {
   635 		return $mu_plugins;
   692 		return $mu_plugins;
   636 	}
   693 	}
   637 	if ( ! $dh = opendir( WPMU_PLUGIN_DIR ) ) {
   694 	$dh = opendir( WPMU_PLUGIN_DIR );
       
   695 	if ( ! $dh ) {
   638 		return $mu_plugins;
   696 		return $mu_plugins;
   639 	}
   697 	}
   640 	while ( ( $plugin = readdir( $dh ) ) !== false ) {
   698 	while ( ( $plugin = readdir( $dh ) ) !== false ) {
   641 		if ( substr( $plugin, -4 ) == '.php' ) {
   699 		if ( '.php' === substr( $plugin, -4 ) ) {
   642 			$mu_plugins[] = WPMU_PLUGIN_DIR . '/' . $plugin;
   700 			$mu_plugins[] = WPMU_PLUGIN_DIR . '/' . $plugin;
   643 		}
   701 		}
   644 	}
   702 	}
   645 	closedir( $dh );
   703 	closedir( $dh );
   646 	sort( $mu_plugins );
   704 	sort( $mu_plugins );
   658  * in `wp-config.php`.
   716  * in `wp-config.php`.
   659  *
   717  *
   660  * @since 3.0.0
   718  * @since 3.0.0
   661  * @access private
   719  * @access private
   662  *
   720  *
   663  * @return string[] $plugin_file Array of paths to plugin files relative to the plugins directory.
   721  * @return string[] Array of paths to plugin files relative to the plugins directory.
   664  */
   722  */
   665 function wp_get_active_and_valid_plugins() {
   723 function wp_get_active_and_valid_plugins() {
   666 	$plugins        = array();
   724 	$plugins        = array();
   667 	$active_plugins = (array) get_option( 'active_plugins', array() );
   725 	$active_plugins = (array) get_option( 'active_plugins', array() );
   668 
   726 
   669 	// Check for hacks file if the option is enabled
   727 	// Check for hacks file if the option is enabled.
   670 	if ( get_option( 'hack_file' ) && file_exists( ABSPATH . 'my-hacks.php' ) ) {
   728 	if ( get_option( 'hack_file' ) && file_exists( ABSPATH . 'my-hacks.php' ) ) {
   671 		_deprecated_file( 'my-hacks.php', '1.5.0' );
   729 		_deprecated_file( 'my-hacks.php', '1.5.0' );
   672 		array_unshift( $plugins, ABSPATH . 'my-hacks.php' );
   730 		array_unshift( $plugins, ABSPATH . 'my-hacks.php' );
   673 	}
   731 	}
   674 
   732 
   677 	}
   735 	}
   678 
   736 
   679 	$network_plugins = is_multisite() ? wp_get_active_network_plugins() : false;
   737 	$network_plugins = is_multisite() ? wp_get_active_network_plugins() : false;
   680 
   738 
   681 	foreach ( $active_plugins as $plugin ) {
   739 	foreach ( $active_plugins as $plugin ) {
   682 		if ( ! validate_file( $plugin ) // $plugin must validate as file
   740 		if ( ! validate_file( $plugin )                     // $plugin must validate as file.
   683 			&& '.php' == substr( $plugin, -4 ) // $plugin must end with '.php'
   741 			&& '.php' === substr( $plugin, -4 )             // $plugin must end with '.php'.
   684 			&& file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist
   742 			&& file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist.
   685 			// not already included as a network plugin
   743 			// Not already included as a network plugin.
   686 			&& ( ! $network_plugins || ! in_array( WP_PLUGIN_DIR . '/' . $plugin, $network_plugins ) )
   744 			&& ( ! $network_plugins || ! in_array( WP_PLUGIN_DIR . '/' . $plugin, $network_plugins, true ) )
   687 			) {
   745 			) {
   688 			$plugins[] = WP_PLUGIN_DIR . '/' . $plugin;
   746 			$plugins[] = WP_PLUGIN_DIR . '/' . $plugin;
   689 		}
   747 		}
   690 	}
   748 	}
   691 
   749 
   703 /**
   761 /**
   704  * Filters a given list of plugins, removing any paused plugins from it.
   762  * Filters a given list of plugins, removing any paused plugins from it.
   705  *
   763  *
   706  * @since 5.2.0
   764  * @since 5.2.0
   707  *
   765  *
   708  * @param array $plugins List of absolute plugin main file paths.
   766  * @param string[] $plugins Array of absolute plugin main file paths.
   709  * @return array Filtered value of $plugins, without any paused plugins.
   767  * @return string[] Filtered array of plugins, without any paused plugins.
   710  */
   768  */
   711 function wp_skip_paused_plugins( array $plugins ) {
   769 function wp_skip_paused_plugins( array $plugins ) {
   712 	$paused_plugins = wp_paused_plugins()->get_all();
   770 	$paused_plugins = wp_paused_plugins()->get_all();
   713 
   771 
   714 	if ( empty( $paused_plugins ) ) {
   772 	if ( empty( $paused_plugins ) ) {
   735  * While upgrading or installing WordPress, no themes are returned.
   793  * While upgrading or installing WordPress, no themes are returned.
   736  *
   794  *
   737  * @since 5.1.0
   795  * @since 5.1.0
   738  * @access private
   796  * @access private
   739  *
   797  *
   740  * @return array Array of paths to theme directories.
   798  * @return string[] Array of absolute paths to theme directories.
   741  */
   799  */
   742 function wp_get_active_and_valid_themes() {
   800 function wp_get_active_and_valid_themes() {
   743 	global $pagenow;
   801 	global $pagenow;
   744 
   802 
   745 	$themes = array();
   803 	$themes = array();
   773 /**
   831 /**
   774  * Filters a given list of themes, removing any paused themes from it.
   832  * Filters a given list of themes, removing any paused themes from it.
   775  *
   833  *
   776  * @since 5.2.0
   834  * @since 5.2.0
   777  *
   835  *
   778  * @param array $themes List of absolute theme directory paths.
   836  * @param string[] $themes Array of absolute theme directory paths.
   779  * @return array Filtered value of $themes, without any paused themes.
   837  * @return string[] Filtered array of absolute paths to themes, without any paused themes.
   780  */
   838  */
   781 function wp_skip_paused_themes( array $themes ) {
   839 function wp_skip_paused_themes( array $themes ) {
   782 	$paused_themes = wp_paused_themes()->get_all();
   840 	$paused_themes = wp_paused_themes()->get_all();
   783 
   841 
   784 	if ( empty( $paused_themes ) ) {
   842 	if ( empty( $paused_themes ) ) {
   828 	// Protect the admin backend.
   886 	// Protect the admin backend.
   829 	if ( is_admin() && ! wp_doing_ajax() ) {
   887 	if ( is_admin() && ! wp_doing_ajax() ) {
   830 		return true;
   888 		return true;
   831 	}
   889 	}
   832 
   890 
   833 	// Protect AJAX actions that could help resolve a fatal error should be available.
   891 	// Protect Ajax actions that could help resolve a fatal error should be available.
   834 	if ( is_protected_ajax_action() ) {
   892 	if ( is_protected_ajax_action() ) {
   835 		return true;
   893 		return true;
   836 	}
   894 	}
   837 
   895 
   838 	/**
   896 	/**
   839 	 * Filters whether the current request is against a protected endpoint.
   897 	 * Filters whether the current request is against a protected endpoint.
   840 	 *
   898 	 *
   841 	 * This filter is only fired when an endpoint is requested which is not already protected by
   899 	 * This filter is only fired when an endpoint is requested which is not already protected by
   842 	 * WordPress core. As such, it exclusively allows providing further protected endpoints in
   900 	 * WordPress core. As such, it exclusively allows providing further protected endpoints in
   843 	 * addition to the admin backend, login pages and protected AJAX actions.
   901 	 * addition to the admin backend, login pages and protected Ajax actions.
   844 	 *
   902 	 *
   845 	 * @since 5.2.0
   903 	 * @since 5.2.0
   846 	 *
   904 	 *
   847 	 * @param bool $is_protected_endpoint Whether the currently requested endpoint is protected. Default false.
   905 	 * @param bool $is_protected_endpoint Whether the currently requested endpoint is protected.
       
   906 	 *                                    Default false.
   848 	 */
   907 	 */
   849 	return (bool) apply_filters( 'is_protected_endpoint', false );
   908 	return (bool) apply_filters( 'is_protected_endpoint', false );
   850 }
   909 }
   851 
   910 
   852 /**
   911 /**
   853  * Determines whether we are currently handling an AJAX action that should be protected against WSODs.
   912  * Determines whether we are currently handling an Ajax action that should be protected against WSODs.
   854  *
   913  *
   855  * @since 5.2.0
   914  * @since 5.2.0
   856  *
   915  *
   857  * @return bool True if the current AJAX action should be protected.
   916  * @return bool True if the current Ajax action should be protected.
   858  */
   917  */
   859 function is_protected_ajax_action() {
   918 function is_protected_ajax_action() {
   860 	if ( ! wp_doing_ajax() ) {
   919 	if ( ! wp_doing_ajax() ) {
   861 		return false;
   920 		return false;
   862 	}
   921 	}
   875 		'update-plugin',          // Update an existing plugin.
   934 		'update-plugin',          // Update an existing plugin.
   876 		'update-theme',           // Update an existing theme.
   935 		'update-theme',           // Update an existing theme.
   877 	);
   936 	);
   878 
   937 
   879 	/**
   938 	/**
   880 	 * Filters the array of protected AJAX actions.
   939 	 * Filters the array of protected Ajax actions.
   881 	 *
   940 	 *
   882 	 * This filter is only fired when doing AJAX and the AJAX request has an 'action' property.
   941 	 * This filter is only fired when doing Ajax and the Ajax request has an 'action' property.
   883 	 *
   942 	 *
   884 	 * @since 5.2.0
   943 	 * @since 5.2.0
   885 	 *
   944 	 *
   886 	 * @param array $actions_to_protect Array of strings with AJAX actions to protect.
   945 	 * @param string[] $actions_to_protect Array of strings with Ajax actions to protect.
   887 	 */
   946 	 */
   888 	$actions_to_protect = (array) apply_filters( 'wp_protected_ajax_actions', $actions_to_protect );
   947 	$actions_to_protect = (array) apply_filters( 'wp_protected_ajax_actions', $actions_to_protect );
   889 
   948 
   890 	if ( ! in_array( $_REQUEST['action'], $actions_to_protect, true ) ) {
   949 	if ( ! in_array( $_REQUEST['action'], $actions_to_protect, true ) ) {
   891 		return false;
   950 		return false;
   904  * @access private
   963  * @access private
   905  */
   964  */
   906 function wp_set_internal_encoding() {
   965 function wp_set_internal_encoding() {
   907 	if ( function_exists( 'mb_internal_encoding' ) ) {
   966 	if ( function_exists( 'mb_internal_encoding' ) ) {
   908 		$charset = get_option( 'blog_charset' );
   967 		$charset = get_option( 'blog_charset' );
       
   968 		// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
   909 		if ( ! $charset || ! @mb_internal_encoding( $charset ) ) {
   969 		if ( ! $charset || ! @mb_internal_encoding( $charset ) ) {
   910 			mb_internal_encoding( 'UTF-8' );
   970 			mb_internal_encoding( 'UTF-8' );
   911 		}
   971 		}
   912 	}
   972 	}
   913 }
   973 }
   920  *
   980  *
   921  * @since 3.0.0
   981  * @since 3.0.0
   922  * @access private
   982  * @access private
   923  */
   983  */
   924 function wp_magic_quotes() {
   984 function wp_magic_quotes() {
   925 	// If already slashed, strip.
       
   926 	if ( get_magic_quotes_gpc() ) {
       
   927 		$_GET    = stripslashes_deep( $_GET );
       
   928 		$_POST   = stripslashes_deep( $_POST );
       
   929 		$_COOKIE = stripslashes_deep( $_COOKIE );
       
   930 	}
       
   931 
       
   932 	// Escape with wpdb.
   985 	// Escape with wpdb.
   933 	$_GET    = add_magic_quotes( $_GET );
   986 	$_GET    = add_magic_quotes( $_GET );
   934 	$_POST   = add_magic_quotes( $_POST );
   987 	$_POST   = add_magic_quotes( $_POST );
   935 	$_COOKIE = add_magic_quotes( $_COOKIE );
   988 	$_COOKIE = add_magic_quotes( $_COOKIE );
   936 	$_SERVER = add_magic_quotes( $_SERVER );
   989 	$_SERVER = add_magic_quotes( $_SERVER );
   964  *
  1017  *
   965  * @param object $object The object to clone.
  1018  * @param object $object The object to clone.
   966  * @return object The cloned object.
  1019  * @return object The cloned object.
   967  */
  1020  */
   968 function wp_clone( $object ) {
  1021 function wp_clone( $object ) {
   969 	// Use parens for clone to accommodate PHP 4. See #17880
  1022 	// Use parens for clone to accommodate PHP 4. See #17880.
   970 	return clone( $object );
  1023 	return clone( $object );
   971 }
  1024 }
   972 
  1025 
   973 /**
  1026 /**
   974  * Determines whether the current request is for an administrative interface page.
  1027  * Determines whether the current request is for an administrative interface page.
   980  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
  1033  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
   981  * Conditional Tags} article in the Theme Developer Handbook.
  1034  * Conditional Tags} article in the Theme Developer Handbook.
   982  *
  1035  *
   983  * @since 1.5.1
  1036  * @since 1.5.1
   984  *
  1037  *
   985  * @global WP_Screen $current_screen
  1038  * @global WP_Screen $current_screen WordPress current screen object.
   986  *
  1039  *
   987  * @return bool True if inside WordPress administration interface, false otherwise.
  1040  * @return bool True if inside WordPress administration interface, false otherwise.
   988  */
  1041  */
   989 function is_admin() {
  1042 function is_admin() {
   990 	if ( isset( $GLOBALS['current_screen'] ) ) {
  1043 	if ( isset( $GLOBALS['current_screen'] ) ) {
   995 
  1048 
   996 	return false;
  1049 	return false;
   997 }
  1050 }
   998 
  1051 
   999 /**
  1052 /**
  1000  * Whether the current request is for a site's admininstrative interface.
  1053  * Whether the current request is for a site's administrative interface.
  1001  *
  1054  *
  1002  * e.g. `/wp-admin/`
  1055  * e.g. `/wp-admin/`
  1003  *
  1056  *
  1004  * Does not check if the user is an administrator; use current_user_can()
  1057  * Does not check if the user is an administrator; use current_user_can()
  1005  * for checking roles and capabilities.
  1058  * for checking roles and capabilities.
  1006  *
  1059  *
  1007  * @since 3.1.0
  1060  * @since 3.1.0
  1008  *
  1061  *
  1009  * @global WP_Screen $current_screen
  1062  * @global WP_Screen $current_screen WordPress current screen object.
  1010  *
  1063  *
  1011  * @return bool True if inside WordPress blog administration pages.
  1064  * @return bool True if inside WordPress blog administration pages.
  1012  */
  1065  */
  1013 function is_blog_admin() {
  1066 function is_blog_admin() {
  1014 	if ( isset( $GLOBALS['current_screen'] ) ) {
  1067 	if ( isset( $GLOBALS['current_screen'] ) ) {
  1026  * e.g. `/wp-admin/network/`
  1079  * e.g. `/wp-admin/network/`
  1027  *
  1080  *
  1028  * Does not check if the user is an administrator; use current_user_can()
  1081  * Does not check if the user is an administrator; use current_user_can()
  1029  * for checking roles and capabilities.
  1082  * for checking roles and capabilities.
  1030  *
  1083  *
       
  1084  * Does not check if the site is a Multisite network; use is_multisite()
       
  1085  * for checking if Multisite is enabled.
       
  1086  *
  1031  * @since 3.1.0
  1087  * @since 3.1.0
  1032  *
  1088  *
  1033  * @global WP_Screen $current_screen
  1089  * @global WP_Screen $current_screen WordPress current screen object.
  1034  *
  1090  *
  1035  * @return bool True if inside WordPress network administration pages.
  1091  * @return bool True if inside WordPress network administration pages.
  1036  */
  1092  */
  1037 function is_network_admin() {
  1093 function is_network_admin() {
  1038 	if ( isset( $GLOBALS['current_screen'] ) ) {
  1094 	if ( isset( $GLOBALS['current_screen'] ) ) {
  1052  * Does not check if the user is an administrator; use current_user_can()
  1108  * Does not check if the user is an administrator; use current_user_can()
  1053  * for checking roles and capabilities.
  1109  * for checking roles and capabilities.
  1054  *
  1110  *
  1055  * @since 3.1.0
  1111  * @since 3.1.0
  1056  *
  1112  *
  1057  * @global WP_Screen $current_screen
  1113  * @global WP_Screen $current_screen WordPress current screen object.
  1058  *
  1114  *
  1059  * @return bool True if inside WordPress user administration pages.
  1115  * @return bool True if inside WordPress user administration pages.
  1060  */
  1116  */
  1061 function is_user_admin() {
  1117 function is_user_admin() {
  1062 	if ( isset( $GLOBALS['current_screen'] ) ) {
  1118 	if ( isset( $GLOBALS['current_screen'] ) ) {
  1133  * that a file can be double-included.
  1189  * that a file can be double-included.
  1134  *
  1190  *
  1135  * @since 3.4.0
  1191  * @since 3.4.0
  1136  * @access private
  1192  * @access private
  1137  *
  1193  *
  1138  * @global WP_Locale $wp_locale The WordPress date and time locale object.
  1194  * @global WP_Locale $wp_locale WordPress date and time locale object.
  1139  *
       
  1140  * @staticvar bool $loaded
       
  1141  */
  1195  */
  1142 function wp_load_translations_early() {
  1196 function wp_load_translations_early() {
  1143 	global $wp_locale;
  1197 	global $wp_locale;
  1144 
  1198 
  1145 	static $loaded = false;
  1199 	static $loaded = false;
  1150 
  1204 
  1151 	if ( function_exists( 'did_action' ) && did_action( 'init' ) ) {
  1205 	if ( function_exists( 'did_action' ) && did_action( 'init' ) ) {
  1152 		return;
  1206 		return;
  1153 	}
  1207 	}
  1154 
  1208 
  1155 	// We need $wp_local_package
  1209 	// We need $wp_local_package.
  1156 	require ABSPATH . WPINC . '/version.php';
  1210 	require ABSPATH . WPINC . '/version.php';
  1157 
  1211 
  1158 	// Translation and localization
  1212 	// Translation and localization.
  1159 	require_once ABSPATH . WPINC . '/pomo/mo.php';
  1213 	require_once ABSPATH . WPINC . '/pomo/mo.php';
  1160 	require_once ABSPATH . WPINC . '/l10n.php';
  1214 	require_once ABSPATH . WPINC . '/l10n.php';
  1161 	require_once ABSPATH . WPINC . '/class-wp-locale.php';
  1215 	require_once ABSPATH . WPINC . '/class-wp-locale.php';
  1162 	require_once ABSPATH . WPINC . '/class-wp-locale-switcher.php';
  1216 	require_once ABSPATH . WPINC . '/class-wp-locale-switcher.php';
  1163 
  1217 
  1164 	// General libraries
  1218 	// General libraries.
  1165 	require_once ABSPATH . WPINC . '/plugin.php';
  1219 	require_once ABSPATH . WPINC . '/plugin.php';
  1166 
  1220 
  1167 	$locales = $locations = array();
  1221 	$locales   = array();
       
  1222 	$locations = array();
  1168 
  1223 
  1169 	while ( true ) {
  1224 	while ( true ) {
  1170 		if ( defined( 'WPLANG' ) ) {
  1225 		if ( defined( 'WPLANG' ) ) {
  1171 			if ( '' == WPLANG ) {
  1226 			if ( '' === WPLANG ) {
  1172 				break;
  1227 				break;
  1173 			}
  1228 			}
  1174 			$locales[] = WPLANG;
  1229 			$locales[] = WPLANG;
  1175 		}
  1230 		}
  1176 
  1231 
  1227  *
  1282  *
  1228  * If the `WP_INSTALLING` constant is defined during the bootstrap, `wp_installing()` will default to `true`.
  1283  * If the `WP_INSTALLING` constant is defined during the bootstrap, `wp_installing()` will default to `true`.
  1229  *
  1284  *
  1230  * @since 4.4.0
  1285  * @since 4.4.0
  1231  *
  1286  *
  1232  * @staticvar bool $installing
       
  1233  *
       
  1234  * @param bool $is_installing Optional. True to set WP into Installing mode, false to turn Installing mode off.
  1287  * @param bool $is_installing Optional. True to set WP into Installing mode, false to turn Installing mode off.
  1235  *                            Omit this parameter if you only want to fetch the current status.
  1288  *                            Omit this parameter if you only want to fetch the current status.
  1236  * @return bool True if WP is installing, otherwise false. When a `$is_installing` is passed, the function will
  1289  * @return bool True if WP is installing, otherwise false. When a `$is_installing` is passed, the function will
  1237  *              report whether WP was in installing mode prior to the change to `$is_installing`.
  1290  *              report whether WP was in installing mode prior to the change to `$is_installing`.
  1238  */
  1291  */
  1261  *
  1314  *
  1262  * @return bool True if SSL, otherwise false.
  1315  * @return bool True if SSL, otherwise false.
  1263  */
  1316  */
  1264 function is_ssl() {
  1317 function is_ssl() {
  1265 	if ( isset( $_SERVER['HTTPS'] ) ) {
  1318 	if ( isset( $_SERVER['HTTPS'] ) ) {
  1266 		if ( 'on' == strtolower( $_SERVER['HTTPS'] ) ) {
  1319 		if ( 'on' === strtolower( $_SERVER['HTTPS'] ) ) {
  1267 			return true;
  1320 			return true;
  1268 		}
  1321 		}
  1269 
  1322 
  1270 		if ( '1' == $_SERVER['HTTPS'] ) {
  1323 		if ( '1' == $_SERVER['HTTPS'] ) {
  1271 			return true;
  1324 			return true;
  1280  * Converts a shorthand byte value to an integer byte value.
  1333  * Converts a shorthand byte value to an integer byte value.
  1281  *
  1334  *
  1282  * @since 2.3.0
  1335  * @since 2.3.0
  1283  * @since 4.6.0 Moved from media.php to load.php.
  1336  * @since 4.6.0 Moved from media.php to load.php.
  1284  *
  1337  *
  1285  * @link https://secure.php.net/manual/en/function.ini-get.php
  1338  * @link https://www.php.net/manual/en/function.ini-get.php
  1286  * @link https://secure.php.net/manual/en/faq.using.php#faq.using.shorthandbytes
  1339  * @link https://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes
  1287  *
  1340  *
  1288  * @param string $value A (PHP ini) byte value, either shorthand or ordinary.
  1341  * @param string $value A (PHP ini) byte value, either shorthand or ordinary.
  1289  * @return int An integer byte value.
  1342  * @return int An integer byte value.
  1290  */
  1343  */
  1291 function wp_convert_hr_to_bytes( $value ) {
  1344 function wp_convert_hr_to_bytes( $value ) {
  1307 /**
  1360 /**
  1308  * Determines whether a PHP ini value is changeable at runtime.
  1361  * Determines whether a PHP ini value is changeable at runtime.
  1309  *
  1362  *
  1310  * @since 4.6.0
  1363  * @since 4.6.0
  1311  *
  1364  *
  1312  * @staticvar array $ini_all
  1365  * @link https://www.php.net/manual/en/function.ini-get-all.php
  1313  *
       
  1314  * @link https://secure.php.net/manual/en/function.ini-get-all.php
       
  1315  *
  1366  *
  1316  * @param string $setting The name of the ini setting to check.
  1367  * @param string $setting The name of the ini setting to check.
  1317  * @return bool True if the value is changeable at runtime. False otherwise.
  1368  * @return bool True if the value is changeable at runtime. False otherwise.
  1318  */
  1369  */
  1319 function wp_is_ini_value_changeable( $setting ) {
  1370 function wp_is_ini_value_changeable( $setting ) {
  1479 /**
  1530 /**
  1480  * Checks whether current request is a JSON request, or is expecting a JSON response.
  1531  * Checks whether current request is a JSON request, or is expecting a JSON response.
  1481  *
  1532  *
  1482  * @since 5.0.0
  1533  * @since 5.0.0
  1483  *
  1534  *
  1484  * @return bool True if Accepts or Content-Type headers contain application/json, false otherwise.
  1535  * @return bool True if `Accepts` or `Content-Type` headers contain `application/json`.
       
  1536  *              False otherwise.
  1485  */
  1537  */
  1486 function wp_is_json_request() {
  1538 function wp_is_json_request() {
  1487 
  1539 
  1488 	if ( isset( $_SERVER['HTTP_ACCEPT'] ) && false !== strpos( $_SERVER['HTTP_ACCEPT'], 'application/json' ) ) {
  1540 	if ( isset( $_SERVER['HTTP_ACCEPT'] ) && false !== strpos( $_SERVER['HTTP_ACCEPT'], 'application/json' ) ) {
  1489 		return true;
  1541 		return true;
  1528 /**
  1580 /**
  1529  * Checks whether current request is an XML request, or is expecting an XML response.
  1581  * Checks whether current request is an XML request, or is expecting an XML response.
  1530  *
  1582  *
  1531  * @since 5.2.0
  1583  * @since 5.2.0
  1532  *
  1584  *
  1533  * @return bool True if Accepts or Content-Type headers contain xml, false otherwise.
  1585  * @return bool True if `Accepts` or `Content-Type` headers contain `text/xml`
       
  1586  *              or one of the related MIME types. False otherwise.
  1534  */
  1587  */
  1535 function wp_is_xml_request() {
  1588 function wp_is_xml_request() {
  1536 	$accepted = array(
  1589 	$accepted = array(
  1537 		'text/xml',
  1590 		'text/xml',
  1538 		'application/rss+xml',
  1591 		'application/rss+xml',