wp/wp-includes/load.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    25  *
    25  *
    26  * @since 2.1.0
    26  * @since 2.1.0
    27  * @access private
    27  * @access private
    28  */
    28  */
    29 function wp_unregister_GLOBALS() {
    29 function wp_unregister_GLOBALS() {
    30 	if ( !ini_get( 'register_globals' ) )
    30 	if ( ! ini_get( 'register_globals' ) ) {
    31 		return;
    31 		return;
    32 
    32 	}
    33 	if ( isset( $_REQUEST['GLOBALS'] ) )
    33 
       
    34 	if ( isset( $_REQUEST['GLOBALS'] ) ) {
    34 		die( 'GLOBALS overwrite attempt detected' );
    35 		die( 'GLOBALS overwrite attempt detected' );
       
    36 	}
    35 
    37 
    36 	// Variables that shouldn't be unset
    38 	// Variables that shouldn't be unset
    37 	$no_unset = array( 'GLOBALS', '_GET', '_POST', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES', 'table_prefix' );
    39 	$no_unset = array( 'GLOBALS', '_GET', '_POST', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES', 'table_prefix' );
    38 
    40 
    39 	$input = array_merge( $_GET, $_POST, $_COOKIE, $_SERVER, $_ENV, $_FILES, isset( $_SESSION ) && is_array( $_SESSION ) ? $_SESSION : array() );
    41 	$input = array_merge( $_GET, $_POST, $_COOKIE, $_SERVER, $_ENV, $_FILES, isset( $_SESSION ) && is_array( $_SESSION ) ? $_SESSION : array() );
    40 	foreach ( $input as $k => $v )
    42 	foreach ( $input as $k => $v ) {
    41 		if ( !in_array( $k, $no_unset ) && isset( $GLOBALS[$k] ) ) {
    43 		if ( ! in_array( $k, $no_unset ) && isset( $GLOBALS[ $k ] ) ) {
    42 			unset( $GLOBALS[$k] );
    44 			unset( $GLOBALS[ $k ] );
    43 		}
    45 		}
       
    46 	}
    44 }
    47 }
    45 
    48 
    46 /**
    49 /**
    47  * Fix `$_SERVER` variables for various setups.
    50  * Fix `$_SERVER` variables for various setups.
    48  *
    51  *
    55 function wp_fix_server_vars() {
    58 function wp_fix_server_vars() {
    56 	global $PHP_SELF;
    59 	global $PHP_SELF;
    57 
    60 
    58 	$default_server_values = array(
    61 	$default_server_values = array(
    59 		'SERVER_SOFTWARE' => '',
    62 		'SERVER_SOFTWARE' => '',
    60 		'REQUEST_URI' => '',
    63 		'REQUEST_URI'     => '',
    61 	);
    64 	);
    62 
    65 
    63 	$_SERVER = array_merge( $default_server_values, $_SERVER );
    66 	$_SERVER = array_merge( $default_server_values, $_SERVER );
    64 
    67 
    65 	// Fix for IIS when running with PHP ISAPI
    68 	// Fix for IIS when running with PHP ISAPI
    66 	if ( empty( $_SERVER['REQUEST_URI'] ) || ( PHP_SAPI != 'cgi-fcgi' && preg_match( '/^Microsoft-IIS\//', $_SERVER['SERVER_SOFTWARE'] ) ) ) {
    69 	if ( empty( $_SERVER['REQUEST_URI'] ) || ( PHP_SAPI != 'cgi-fcgi' && preg_match( '/^Microsoft-IIS\//', $_SERVER['SERVER_SOFTWARE'] ) ) ) {
    67 
    70 
    68 		// IIS Mod-Rewrite
       
    69 		if ( isset( $_SERVER['HTTP_X_ORIGINAL_URL'] ) ) {
    71 		if ( isset( $_SERVER['HTTP_X_ORIGINAL_URL'] ) ) {
       
    72 			// IIS Mod-Rewrite
    70 			$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
    73 			$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
    71 		}
    74 		} elseif ( isset( $_SERVER['HTTP_X_REWRITE_URL'] ) ) {
    72 		// IIS Isapi_Rewrite
    75 			// IIS Isapi_Rewrite
    73 		elseif ( isset( $_SERVER['HTTP_X_REWRITE_URL'] ) ) {
       
    74 			$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
    76 			$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
    75 		} else {
    77 		} else {
    76 			// Use ORIG_PATH_INFO if there is no PATH_INFO
    78 			// Use ORIG_PATH_INFO if there is no PATH_INFO
    77 			if ( !isset( $_SERVER['PATH_INFO'] ) && isset( $_SERVER['ORIG_PATH_INFO'] ) )
    79 			if ( ! isset( $_SERVER['PATH_INFO'] ) && isset( $_SERVER['ORIG_PATH_INFO'] ) ) {
    78 				$_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'];
    80 				$_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'];
       
    81 			}
    79 
    82 
    80 			// Some IIS + PHP configurations puts the script-name in the path-info (No need to append it twice)
    83 			// Some IIS + PHP configurations puts the script-name in the path-info (No need to append it twice)
    81 			if ( isset( $_SERVER['PATH_INFO'] ) ) {
    84 			if ( isset( $_SERVER['PATH_INFO'] ) ) {
    82 				if ( $_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME'] )
    85 				if ( $_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME'] ) {
    83 					$_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'];
    86 					$_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'];
    84 				else
    87 				} else {
    85 					$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO'];
    88 					$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO'];
       
    89 				}
    86 			}
    90 			}
    87 
    91 
    88 			// Append the query string if it exists and isn't null
    92 			// Append the query string if it exists and isn't null
    89 			if ( ! empty( $_SERVER['QUERY_STRING'] ) ) {
    93 			if ( ! empty( $_SERVER['QUERY_STRING'] ) ) {
    90 				$_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
    94 				$_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
    91 			}
    95 			}
    92 		}
    96 		}
    93 	}
    97 	}
    94 
    98 
    95 	// Fix for PHP as CGI hosts that set SCRIPT_FILENAME to something ending in php.cgi for all requests
    99 	// Fix for PHP as CGI hosts that set SCRIPT_FILENAME to something ending in php.cgi for all requests
    96 	if ( isset( $_SERVER['SCRIPT_FILENAME'] ) && ( strpos( $_SERVER['SCRIPT_FILENAME'], 'php.cgi' ) == strlen( $_SERVER['SCRIPT_FILENAME'] ) - 7 ) )
   100 	if ( isset( $_SERVER['SCRIPT_FILENAME'] ) && ( strpos( $_SERVER['SCRIPT_FILENAME'], 'php.cgi' ) == strlen( $_SERVER['SCRIPT_FILENAME'] ) - 7 ) ) {
    97 		$_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED'];
   101 		$_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED'];
       
   102 	}
    98 
   103 
    99 	// Fix for Dreamhost and other PHP as CGI hosts
   104 	// Fix for Dreamhost and other PHP as CGI hosts
   100 	if ( strpos( $_SERVER['SCRIPT_NAME'], 'php.cgi' ) !== false )
   105 	if ( strpos( $_SERVER['SCRIPT_NAME'], 'php.cgi' ) !== false ) {
   101 		unset( $_SERVER['PATH_INFO'] );
   106 		unset( $_SERVER['PATH_INFO'] );
       
   107 	}
   102 
   108 
   103 	// Fix empty PHP_SELF
   109 	// Fix empty PHP_SELF
   104 	$PHP_SELF = $_SERVER['PHP_SELF'];
   110 	$PHP_SELF = $_SERVER['PHP_SELF'];
   105 	if ( empty( $PHP_SELF ) )
   111 	if ( empty( $PHP_SELF ) ) {
   106 		$_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace( '/(\?.*)?$/', '', $_SERVER["REQUEST_URI"] );
   112 		$_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace( '/(\?.*)?$/', '', $_SERVER['REQUEST_URI'] );
       
   113 	}
   107 }
   114 }
   108 
   115 
   109 /**
   116 /**
   110  * Check for the required PHP version, and the MySQL extension or
   117  * Check for the required PHP version, and the MySQL extension or
   111  * a database drop-in.
   118  * a database drop-in.
   127 
   134 
   128 		$protocol = wp_get_server_protocol();
   135 		$protocol = wp_get_server_protocol();
   129 		header( sprintf( '%s 500 Internal Server Error', $protocol ), true, 500 );
   136 		header( sprintf( '%s 500 Internal Server Error', $protocol ), true, 500 );
   130 		header( 'Content-Type: text/html; charset=utf-8' );
   137 		header( 'Content-Type: text/html; charset=utf-8' );
   131 		/* translators: 1: Current PHP version number, 2: WordPress version number, 3: Minimum required PHP version number */
   138 		/* translators: 1: Current PHP version number, 2: WordPress version number, 3: Minimum required PHP version number */
   132 		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 ) );
   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 );
   133 	}
   141 	}
   134 
   142 
   135 	if ( ! extension_loaded( 'mysql' ) && ! extension_loaded( 'mysqli' ) && ! extension_loaded( 'mysqlnd' ) && ! file_exists( WP_CONTENT_DIR . '/db.php' ) ) {
   143 	if ( ! extension_loaded( 'mysql' ) && ! extension_loaded( 'mysqli' ) && ! extension_loaded( 'mysqlnd' ) && ! file_exists( WP_CONTENT_DIR . '/db.php' ) ) {
       
   144 		require_once( ABSPATH . WPINC . '/functions.php' );
   136 		wp_load_translations_early();
   145 		wp_load_translations_early();
   137 
   146 		$args = array(
   138 		$protocol = wp_get_server_protocol();
   147 			'exit' => false,
   139 		header( sprintf( '%s 500 Internal Server Error', $protocol ), true, 500 );
   148 			'code' => 'mysql_not_found',
   140 		header( 'Content-Type: text/html; charset=utf-8' );
   149 		);
   141 		die( __( 'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.' ) );
   150 		wp_die(
       
   151 			__( 'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.' ),
       
   152 			__( 'Insufficient Requirements' ),
       
   153 			$args
       
   154 		);
       
   155 		exit( 1 );
   142 	}
   156 	}
   143 }
   157 }
   144 
   158 
   145 /**
   159 /**
   146  * Don't load all of WordPress when handling a favicon.ico request.
   160  * Don't load all of WordPress when handling a favicon.ico request.
   149  *
   163  *
   150  * @since 3.0.0
   164  * @since 3.0.0
   151  */
   165  */
   152 function wp_favicon_request() {
   166 function wp_favicon_request() {
   153 	if ( '/favicon.ico' == $_SERVER['REQUEST_URI'] ) {
   167 	if ( '/favicon.ico' == $_SERVER['REQUEST_URI'] ) {
   154 		header('Content-Type: image/vnd.microsoft.icon');
   168 		header( 'Content-Type: image/vnd.microsoft.icon' );
   155 		exit;
   169 		exit;
   156 	}
   170 	}
   157 }
   171 }
   158 
   172 
   159 /**
   173 /**
   171  * @access private
   185  * @access private
   172  *
   186  *
   173  * @global int $upgrading the unix timestamp marking when upgrading WordPress began.
   187  * @global int $upgrading the unix timestamp marking when upgrading WordPress began.
   174  */
   188  */
   175 function wp_maintenance() {
   189 function wp_maintenance() {
   176 	if ( ! file_exists( ABSPATH . '.maintenance' ) || wp_installing() )
   190 	if ( ! file_exists( ABSPATH . '.maintenance' ) || wp_installing() ) {
   177 		return;
   191 		return;
       
   192 	}
   178 
   193 
   179 	global $upgrading;
   194 	global $upgrading;
   180 
   195 
   181 	include( ABSPATH . '.maintenance' );
   196 	include( ABSPATH . '.maintenance' );
   182 	// If the $upgrading timestamp is older than 10 minutes, don't die.
   197 	// If the $upgrading timestamp is older than 10 minutes, don't die.
   183 	if ( ( time() - $upgrading ) >= 600 )
   198 	if ( ( time() - $upgrading ) >= 600 ) {
   184 		return;
   199 		return;
       
   200 	}
   185 
   201 
   186 	/**
   202 	/**
   187 	 * Filters whether to enable maintenance mode.
   203 	 * Filters whether to enable maintenance mode.
   188 	 *
   204 	 *
   189 	 * This filter runs before it can be used by plugins. It is designed for
   205 	 * This filter runs before it can be used by plugins. It is designed for
   203 	if ( file_exists( WP_CONTENT_DIR . '/maintenance.php' ) ) {
   219 	if ( file_exists( WP_CONTENT_DIR . '/maintenance.php' ) ) {
   204 		require_once( WP_CONTENT_DIR . '/maintenance.php' );
   220 		require_once( WP_CONTENT_DIR . '/maintenance.php' );
   205 		die();
   221 		die();
   206 	}
   222 	}
   207 
   223 
       
   224 	require_once( ABSPATH . WPINC . '/functions.php' );
   208 	wp_load_translations_early();
   225 	wp_load_translations_early();
   209 
   226 
   210 	$protocol = wp_get_server_protocol();
       
   211 	header( "$protocol 503 Service Unavailable", true, 503 );
       
   212 	header( 'Content-Type: text/html; charset=utf-8' );
       
   213 	header( 'Retry-After: 600' );
   227 	header( 'Retry-After: 600' );
   214 ?>
   228 
   215 	<!DOCTYPE html>
   229 	wp_die(
   216 	<html xmlns="http://www.w3.org/1999/xhtml"<?php if ( is_rtl() ) echo ' dir="rtl"'; ?>>
   230 		__( 'Briefly unavailable for scheduled maintenance. Check back in a minute.' ),
   217 	<head>
   231 		__( 'Maintenance' ),
   218 	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   232 		503
   219 		<title><?php _e( 'Maintenance' ); ?></title>
   233 	);
   220 
       
   221 	</head>
       
   222 	<body>
       
   223 		<h1><?php _e( 'Briefly unavailable for scheduled maintenance. Check back in a minute.' ); ?></h1>
       
   224 	</body>
       
   225 	</html>
       
   226 <?php
       
   227 	die();
       
   228 }
   234 }
   229 
   235 
   230 /**
   236 /**
   231  * Start the WordPress micro-timer.
   237  * Start the WordPress micro-timer.
   232  *
   238  *
   259  * @return string The "second.microsecond" finished time calculation. The number is formatted
   265  * @return string The "second.microsecond" finished time calculation. The number is formatted
   260  *                for human consumption, both localized and rounded.
   266  *                for human consumption, both localized and rounded.
   261  */
   267  */
   262 function timer_stop( $display = 0, $precision = 3 ) {
   268 function timer_stop( $display = 0, $precision = 3 ) {
   263 	global $timestart, $timeend;
   269 	global $timestart, $timeend;
   264 	$timeend = microtime( true );
   270 	$timeend   = microtime( true );
   265 	$timetotal = $timeend - $timestart;
   271 	$timetotal = $timeend - $timestart;
   266 	$r = ( function_exists( 'number_format_i18n' ) ) ? number_format_i18n( $timetotal, $precision ) : number_format( $timetotal, $precision );
   272 	$r         = ( function_exists( 'number_format_i18n' ) ) ? number_format_i18n( $timetotal, $precision ) : number_format( $timetotal, $precision );
   267 	if ( $display )
   273 	if ( $display ) {
   268 		echo $r;
   274 		echo $r;
       
   275 	}
   269 	return $r;
   276 	return $r;
   270 }
   277 }
   271 
   278 
   272 /**
   279 /**
   273  * Set PHP error reporting based on WordPress debug settings.
   280  * Set PHP error reporting based on WordPress debug settings.
   290  * When `WP_DEBUG_DISPLAY` is true, WordPress will force errors to be displayed.
   297  * When `WP_DEBUG_DISPLAY` is true, WordPress will force errors to be displayed.
   291  * `WP_DEBUG_DISPLAY` defaults to true. Defining it as null prevents WordPress
   298  * `WP_DEBUG_DISPLAY` defaults to true. Defining it as null prevents WordPress
   292  * from changing the global configuration setting. Defining `WP_DEBUG_DISPLAY`
   299  * from changing the global configuration setting. Defining `WP_DEBUG_DISPLAY`
   293  * as false will force errors to be hidden.
   300  * as false will force errors to be hidden.
   294  *
   301  *
   295  * When `WP_DEBUG_LOG` is true, errors will be logged to debug.log in the content
   302  * When `WP_DEBUG_LOG` is true, errors will be logged to `wp-content/debug.log`.
   296  * directory.
   303  * When `WP_DEBUG_LOG` is a valid path, errors will be logged to the specified file.
   297  *
   304  *
   298  * Errors are never displayed for XML-RPC, REST, and Ajax requests.
   305  * Errors are never displayed for XML-RPC, REST, and Ajax requests.
   299  *
   306  *
   300  * @since 3.0.0
   307  * @since 3.0.0
       
   308  * @since 5.1.0 `WP_DEBUG_LOG` can be a file path.
   301  * @access private
   309  * @access private
   302  */
   310  */
   303 function wp_debug_mode() {
   311 function wp_debug_mode() {
   304 	/**
   312 	/**
   305 	 * Filters whether to allow the debug mode check to occur.
   313 	 * Filters whether to allow the debug mode check to occur.
   311 	 *
   319 	 *
   312 	 * @since 4.6.0
   320 	 * @since 4.6.0
   313 	 *
   321 	 *
   314 	 * @param bool $enable_debug_mode Whether to enable debug mode checks to occur. Default true.
   322 	 * @param bool $enable_debug_mode Whether to enable debug mode checks to occur. Default true.
   315 	 */
   323 	 */
   316 	if ( ! apply_filters( 'enable_wp_debug_mode_checks', true ) ){
   324 	if ( ! apply_filters( 'enable_wp_debug_mode_checks', true ) ) {
   317 		return;
   325 		return;
   318 	}
   326 	}
   319 
   327 
   320 	if ( WP_DEBUG ) {
   328 	if ( WP_DEBUG ) {
   321 		error_reporting( E_ALL );
   329 		error_reporting( E_ALL );
   322 
   330 
   323 		if ( WP_DEBUG_DISPLAY )
   331 		if ( WP_DEBUG_DISPLAY ) {
   324 			ini_set( 'display_errors', 1 );
   332 			ini_set( 'display_errors', 1 );
   325 		elseif ( null !== WP_DEBUG_DISPLAY )
   333 		} elseif ( null !== WP_DEBUG_DISPLAY ) {
   326 			ini_set( 'display_errors', 0 );
   334 			ini_set( 'display_errors', 0 );
   327 
   335 		}
   328 		if ( WP_DEBUG_LOG ) {
   336 
       
   337 		if ( in_array( strtolower( (string) WP_DEBUG_LOG ), array( 'true', '1' ), true ) ) {
       
   338 			$log_path = WP_CONTENT_DIR . '/debug.log';
       
   339 		} elseif ( is_string( WP_DEBUG_LOG ) ) {
       
   340 			$log_path = WP_DEBUG_LOG;
       
   341 		} else {
       
   342 			$log_path = false;
       
   343 		}
       
   344 
       
   345 		if ( $log_path ) {
   329 			ini_set( 'log_errors', 1 );
   346 			ini_set( 'log_errors', 1 );
   330 			ini_set( 'error_log', WP_CONTENT_DIR . '/debug.log' );
   347 			ini_set( 'error_log', $log_path );
   331 		}
   348 		}
   332 	} else {
   349 	} else {
   333 		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 );
   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 );
   334 	}
   351 	}
   335 
   352 
   336 	if ( defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || ( defined( 'WP_INSTALLING' ) && WP_INSTALLING ) || wp_doing_ajax() ) {
   353 	if ( defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || ( defined( 'WP_INSTALLING' ) && WP_INSTALLING ) || wp_doing_ajax() || wp_is_json_request() ) {
   337 		@ini_set( 'display_errors', 0 );
   354 		@ini_set( 'display_errors', 0 );
   338 	}
   355 	}
   339 }
   356 }
   340 
   357 
   341 /**
   358 /**
   350  *
   367  *
   351  * @since 3.0.0
   368  * @since 3.0.0
   352  * @access private
   369  * @access private
   353  */
   370  */
   354 function wp_set_lang_dir() {
   371 function wp_set_lang_dir() {
   355 	if ( !defined( 'WP_LANG_DIR' ) ) {
   372 	if ( ! defined( 'WP_LANG_DIR' ) ) {
   356 		if ( file_exists( WP_CONTENT_DIR . '/languages' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) || !@is_dir(ABSPATH . WPINC . '/languages') ) {
   373 		if ( file_exists( WP_CONTENT_DIR . '/languages' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) || ! @is_dir( ABSPATH . WPINC . '/languages' ) ) {
   357 			/**
   374 			/**
   358 			 * Server path of the language directory.
   375 			 * Server path of the language directory.
   359 			 *
   376 			 *
   360 			 * No leading slash, no trailing slash, full path, not relative to ABSPATH
   377 			 * No leading slash, no trailing slash, full path, not relative to ABSPATH
   361 			 *
   378 			 *
   362 			 * @since 2.1.0
   379 			 * @since 2.1.0
   363 			 */
   380 			 */
   364 			define( 'WP_LANG_DIR', WP_CONTENT_DIR . '/languages' );
   381 			define( 'WP_LANG_DIR', WP_CONTENT_DIR . '/languages' );
   365 			if ( !defined( 'LANGDIR' ) ) {
   382 			if ( ! defined( 'LANGDIR' ) ) {
   366 				// Old static relative path maintained for limited backward compatibility - won't work in some cases.
   383 				// Old static relative path maintained for limited backward compatibility - won't work in some cases.
   367 				define( 'LANGDIR', 'wp-content/languages' );
   384 				define( 'LANGDIR', 'wp-content/languages' );
   368 			}
   385 			}
   369 		} else {
   386 		} else {
   370 			/**
   387 			/**
   373 			 * No leading slash, no trailing slash, full path, not relative to `ABSPATH`.
   390 			 * No leading slash, no trailing slash, full path, not relative to `ABSPATH`.
   374 			 *
   391 			 *
   375 			 * @since 2.1.0
   392 			 * @since 2.1.0
   376 			 */
   393 			 */
   377 			define( 'WP_LANG_DIR', ABSPATH . WPINC . '/languages' );
   394 			define( 'WP_LANG_DIR', ABSPATH . WPINC . '/languages' );
   378 			if ( !defined( 'LANGDIR' ) ) {
   395 			if ( ! defined( 'LANGDIR' ) ) {
   379 				// Old relative path maintained for backward compatibility.
   396 				// Old relative path maintained for backward compatibility.
   380 				define( 'LANGDIR', WPINC . '/languages' );
   397 				define( 'LANGDIR', WPINC . '/languages' );
   381 			}
   398 			}
   382 		}
   399 		}
   383 	}
   400 	}
   392  */
   409  */
   393 function require_wp_db() {
   410 function require_wp_db() {
   394 	global $wpdb;
   411 	global $wpdb;
   395 
   412 
   396 	require_once( ABSPATH . WPINC . '/wp-db.php' );
   413 	require_once( ABSPATH . WPINC . '/wp-db.php' );
   397 	if ( file_exists( WP_CONTENT_DIR . '/db.php' ) )
   414 	if ( file_exists( WP_CONTENT_DIR . '/db.php' ) ) {
   398 		require_once( WP_CONTENT_DIR . '/db.php' );
   415 		require_once( WP_CONTENT_DIR . '/db.php' );
       
   416 	}
   399 
   417 
   400 	if ( isset( $wpdb ) ) {
   418 	if ( isset( $wpdb ) ) {
   401 		return;
   419 		return;
   402 	}
   420 	}
   403 
   421 
   404 	$wpdb = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST );
   422 	$dbuser     = defined( 'DB_USER' ) ? DB_USER : '';
       
   423 	$dbpassword = defined( 'DB_PASSWORD' ) ? DB_PASSWORD : '';
       
   424 	$dbname     = defined( 'DB_NAME' ) ? DB_NAME : '';
       
   425 	$dbhost     = defined( 'DB_HOST' ) ? DB_HOST : '';
       
   426 
       
   427 	$wpdb = new wpdb( $dbuser, $dbpassword, $dbname, $dbhost );
   405 }
   428 }
   406 
   429 
   407 /**
   430 /**
   408  * Set the database table prefix and the format specifiers for database
   431  * Set the database table prefix and the format specifiers for database
   409  * table columns.
   432  * table columns.
   416  * @global wpdb   $wpdb         The WordPress database class.
   439  * @global wpdb   $wpdb         The WordPress database class.
   417  * @global string $table_prefix The database table prefix.
   440  * @global string $table_prefix The database table prefix.
   418  */
   441  */
   419 function wp_set_wpdb_vars() {
   442 function wp_set_wpdb_vars() {
   420 	global $wpdb, $table_prefix;
   443 	global $wpdb, $table_prefix;
   421 	if ( !empty( $wpdb->error ) )
   444 	if ( ! empty( $wpdb->error ) ) {
   422 		dead_db();
   445 		dead_db();
   423 
   446 	}
   424 	$wpdb->field_types = array( 'post_author' => '%d', 'post_parent' => '%d', 'menu_order' => '%d', 'term_id' => '%d', 'term_group' => '%d', 'term_taxonomy_id' => '%d',
   447 
   425 		'parent' => '%d', 'count' => '%d','object_id' => '%d', 'term_order' => '%d', 'ID' => '%d', 'comment_ID' => '%d', 'comment_post_ID' => '%d', 'comment_parent' => '%d',
   448 	$wpdb->field_types = array(
   426 		'user_id' => '%d', 'link_id' => '%d', 'link_owner' => '%d', 'link_rating' => '%d', 'option_id' => '%d', 'blog_id' => '%d', 'meta_id' => '%d', 'post_id' => '%d',
   449 		'post_author'      => '%d',
   427 		'user_status' => '%d', 'umeta_id' => '%d', 'comment_karma' => '%d', 'comment_count' => '%d',
   450 		'post_parent'      => '%d',
       
   451 		'menu_order'       => '%d',
       
   452 		'term_id'          => '%d',
       
   453 		'term_group'       => '%d',
       
   454 		'term_taxonomy_id' => '%d',
       
   455 		'parent'           => '%d',
       
   456 		'count'            => '%d',
       
   457 		'object_id'        => '%d',
       
   458 		'term_order'       => '%d',
       
   459 		'ID'               => '%d',
       
   460 		'comment_ID'       => '%d',
       
   461 		'comment_post_ID'  => '%d',
       
   462 		'comment_parent'   => '%d',
       
   463 		'user_id'          => '%d',
       
   464 		'link_id'          => '%d',
       
   465 		'link_owner'       => '%d',
       
   466 		'link_rating'      => '%d',
       
   467 		'option_id'        => '%d',
       
   468 		'blog_id'          => '%d',
       
   469 		'meta_id'          => '%d',
       
   470 		'post_id'          => '%d',
       
   471 		'user_status'      => '%d',
       
   472 		'umeta_id'         => '%d',
       
   473 		'comment_karma'    => '%d',
       
   474 		'comment_count'    => '%d',
   428 		// multisite:
   475 		// multisite:
   429 		'active' => '%d', 'cat_id' => '%d', 'deleted' => '%d', 'lang_id' => '%d', 'mature' => '%d', 'public' => '%d', 'site_id' => '%d', 'spam' => '%d',
   476 		'active'           => '%d',
       
   477 		'cat_id'           => '%d',
       
   478 		'deleted'          => '%d',
       
   479 		'lang_id'          => '%d',
       
   480 		'mature'           => '%d',
       
   481 		'public'           => '%d',
       
   482 		'site_id'          => '%d',
       
   483 		'spam'             => '%d',
   430 	);
   484 	);
   431 
   485 
   432 	$prefix = $wpdb->set_prefix( $table_prefix );
   486 	$prefix = $wpdb->set_prefix( $table_prefix );
   433 
   487 
   434 	if ( is_wp_error( $prefix ) ) {
   488 	if ( is_wp_error( $prefix ) ) {
   435 		wp_load_translations_early();
   489 		wp_load_translations_early();
   436 		wp_die(
   490 		wp_die(
   437 			/* translators: 1: $table_prefix 2: wp-config.php */
   491 			/* translators: 1: $table_prefix, 2: wp-config.php */
   438 			sprintf( __( '<strong>ERROR</strong>: %1$s in %2$s can only contain numbers, letters, and underscores.' ),
   492 			sprintf(
       
   493 				__( '<strong>ERROR</strong>: %1$s in %2$s can only contain numbers, letters, and underscores.' ),
   439 				'<code>$table_prefix</code>',
   494 				'<code>$table_prefix</code>',
   440 				'<code>wp-config.php</code>'
   495 				'<code>wp-config.php</code>'
   441 			)
   496 			)
   442 		);
   497 		);
   443 	}
   498 	}
   455  * @return bool The current 'using' setting.
   510  * @return bool The current 'using' setting.
   456  */
   511  */
   457 function wp_using_ext_object_cache( $using = null ) {
   512 function wp_using_ext_object_cache( $using = null ) {
   458 	global $_wp_using_ext_object_cache;
   513 	global $_wp_using_ext_object_cache;
   459 	$current_using = $_wp_using_ext_object_cache;
   514 	$current_using = $_wp_using_ext_object_cache;
   460 	if ( null !== $using )
   515 	if ( null !== $using ) {
   461 		$_wp_using_ext_object_cache = $using;
   516 		$_wp_using_ext_object_cache = $using;
       
   517 	}
   462 	return $current_using;
   518 	return $current_using;
   463 }
   519 }
   464 
   520 
   465 /**
   521 /**
   466  * Start the WordPress object cache.
   522  * Start the WordPress object cache.
   473  *
   529  *
   474  * @global array $wp_filter Stores all of the filters.
   530  * @global array $wp_filter Stores all of the filters.
   475  */
   531  */
   476 function wp_start_object_cache() {
   532 function wp_start_object_cache() {
   477 	global $wp_filter;
   533 	global $wp_filter;
   478 
   534 	static $first_init = true;
   479 	$first_init = false;
   535 
   480  	if ( ! function_exists( 'wp_cache_init' ) ) {
   536 	// Only perform the following checks once.
   481 		if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
   537 	if ( $first_init ) {
   482 			require_once ( WP_CONTENT_DIR . '/object-cache.php' );
   538 		if ( ! function_exists( 'wp_cache_init' ) ) {
   483 			if ( function_exists( 'wp_cache_init' ) ) {
   539 			/*
   484 				wp_using_ext_object_cache( true );
   540 			 * This is the normal situation. First-run of this function. No
       
   541 			 * caching backend has been loaded.
       
   542 			 *
       
   543 			 * We try to load a custom caching backend, and then, if it
       
   544 			 * results in a wp_cache_init() function existing, we note
       
   545 			 * that an external object cache is being used.
       
   546 			 */
       
   547 			if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
       
   548 				require_once( WP_CONTENT_DIR . '/object-cache.php' );
       
   549 				if ( function_exists( 'wp_cache_init' ) ) {
       
   550 					wp_using_ext_object_cache( true );
       
   551 				}
       
   552 
       
   553 				// Re-initialize any hooks added manually by object-cache.php
       
   554 				if ( $wp_filter ) {
       
   555 					$wp_filter = WP_Hook::build_preinitialized_hooks( $wp_filter );
       
   556 				}
   485 			}
   557 			}
   486 
   558 		} elseif ( ! wp_using_ext_object_cache() && file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
   487 			// Re-initialize any hooks added manually by object-cache.php
   559 			/*
   488 			if ( $wp_filter ) {
   560 			 * Sometimes advanced-cache.php can load object-cache.php before
   489 				$wp_filter = WP_Hook::build_preinitialized_hooks( $wp_filter );
   561 			 * this function is run. This breaks the function_exists() check
   490 			}
   562 			 * above and can result in wp_using_ext_object_cache() returning
   491 		}
   563 			 * false when actually an external cache is in use.
   492 
   564 			 */
   493 		$first_init = true;
   565 			wp_using_ext_object_cache( true );
   494 	} elseif ( ! wp_using_ext_object_cache() && file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
   566 		}
   495 		/*
       
   496 		 * Sometimes advanced-cache.php can load object-cache.php before
       
   497 		 * it is loaded here. This breaks the function_exists check above
       
   498 		 * and can result in `$_wp_using_ext_object_cache` being set
       
   499 		 * incorrectly. Double check if an external cache exists.
       
   500 		 */
       
   501 		wp_using_ext_object_cache( true );
       
   502 	}
   567 	}
   503 
   568 
   504 	if ( ! wp_using_ext_object_cache() ) {
   569 	if ( ! wp_using_ext_object_cache() ) {
   505 		require_once ( ABSPATH . WPINC . '/cache.php' );
   570 		require_once( ABSPATH . WPINC . '/cache.php' );
   506 	}
   571 	}
   507 
   572 
   508 	/*
   573 	/*
   509 	 * If cache supports reset, reset instead of init if already
   574 	 * If cache supports reset, reset instead of init if already
   510 	 * initialized. Reset signals to the cache that global IDs
   575 	 * initialized. Reset signals to the cache that global IDs
   515 	} elseif ( function_exists( 'wp_cache_init' ) ) {
   580 	} elseif ( function_exists( 'wp_cache_init' ) ) {
   516 		wp_cache_init();
   581 		wp_cache_init();
   517 	}
   582 	}
   518 
   583 
   519 	if ( function_exists( 'wp_cache_add_global_groups' ) ) {
   584 	if ( function_exists( 'wp_cache_add_global_groups' ) ) {
   520 		wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'site-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites' ) );
   585 		wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'site-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'blog_meta' ) );
   521 		wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
   586 		wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
   522 	}
   587 	}
       
   588 
       
   589 	$first_init = false;
   523 }
   590 }
   524 
   591 
   525 /**
   592 /**
   526  * Redirect to the installer if WordPress is not installed.
   593  * Redirect to the installer if WordPress is not installed.
   527  *
   594  *
   540 	} elseif ( ! is_blog_installed() && ! wp_installing() ) {
   607 	} elseif ( ! is_blog_installed() && ! wp_installing() ) {
   541 		nocache_headers();
   608 		nocache_headers();
   542 
   609 
   543 		require( ABSPATH . WPINC . '/kses.php' );
   610 		require( ABSPATH . WPINC . '/kses.php' );
   544 		require( ABSPATH . WPINC . '/pluggable.php' );
   611 		require( ABSPATH . WPINC . '/pluggable.php' );
   545 		require( ABSPATH . WPINC . '/formatting.php' );
       
   546 
   612 
   547 		$link = wp_guess_url() . '/wp-admin/install.php';
   613 		$link = wp_guess_url() . '/wp-admin/install.php';
   548 
   614 
   549 		wp_redirect( $link );
   615 		wp_redirect( $link );
   550 		die();
   616 		die();
   563  *
   629  *
   564  * @return array Files to include.
   630  * @return array Files to include.
   565  */
   631  */
   566 function wp_get_mu_plugins() {
   632 function wp_get_mu_plugins() {
   567 	$mu_plugins = array();
   633 	$mu_plugins = array();
   568 	if ( !is_dir( WPMU_PLUGIN_DIR ) )
   634 	if ( ! is_dir( WPMU_PLUGIN_DIR ) ) {
   569 		return $mu_plugins;
   635 		return $mu_plugins;
   570 	if ( ! $dh = opendir( WPMU_PLUGIN_DIR ) )
   636 	}
       
   637 	if ( ! $dh = opendir( WPMU_PLUGIN_DIR ) ) {
   571 		return $mu_plugins;
   638 		return $mu_plugins;
       
   639 	}
   572 	while ( ( $plugin = readdir( $dh ) ) !== false ) {
   640 	while ( ( $plugin = readdir( $dh ) ) !== false ) {
   573 		if ( substr( $plugin, -4 ) == '.php' )
   641 		if ( substr( $plugin, -4 ) == '.php' ) {
   574 			$mu_plugins[] = WPMU_PLUGIN_DIR . '/' . $plugin;
   642 			$mu_plugins[] = WPMU_PLUGIN_DIR . '/' . $plugin;
       
   643 		}
   575 	}
   644 	}
   576 	closedir( $dh );
   645 	closedir( $dh );
   577 	sort( $mu_plugins );
   646 	sort( $mu_plugins );
   578 
   647 
   579 	return $mu_plugins;
   648 	return $mu_plugins;
   582 /**
   651 /**
   583  * Retrieve an array of active and valid plugin files.
   652  * Retrieve an array of active and valid plugin files.
   584  *
   653  *
   585  * While upgrading or installing WordPress, no plugins are returned.
   654  * While upgrading or installing WordPress, no plugins are returned.
   586  *
   655  *
   587  * The default directory is wp-content/plugins. To change the default
   656  * The default directory is `wp-content/plugins`. To change the default
   588  * directory manually, define `WP_PLUGIN_DIR` and `WP_PLUGIN_URL`
   657  * directory manually, define `WP_PLUGIN_DIR` and `WP_PLUGIN_URL`
   589  * in wp-config.php.
   658  * in `wp-config.php`.
   590  *
   659  *
   591  * @since 3.0.0
   660  * @since 3.0.0
   592  * @access private
   661  * @access private
   593  *
   662  *
   594  * @return array Files.
   663  * @return string[] $plugin_file Array of paths to plugin files relative to the plugins directory.
   595  */
   664  */
   596 function wp_get_active_and_valid_plugins() {
   665 function wp_get_active_and_valid_plugins() {
   597 	$plugins = array();
   666 	$plugins        = array();
   598 	$active_plugins = (array) get_option( 'active_plugins', array() );
   667 	$active_plugins = (array) get_option( 'active_plugins', array() );
   599 
   668 
   600 	// Check for hacks file if the option is enabled
   669 	// Check for hacks file if the option is enabled
   601 	if ( get_option( 'hack_file' ) && file_exists( ABSPATH . 'my-hacks.php' ) ) {
   670 	if ( get_option( 'hack_file' ) && file_exists( ABSPATH . 'my-hacks.php' ) ) {
   602 		_deprecated_file( 'my-hacks.php', '1.5.0' );
   671 		_deprecated_file( 'my-hacks.php', '1.5.0' );
   603 		array_unshift( $plugins, ABSPATH . 'my-hacks.php' );
   672 		array_unshift( $plugins, ABSPATH . 'my-hacks.php' );
   604 	}
   673 	}
   605 
   674 
   606 	if ( empty( $active_plugins ) || wp_installing() )
   675 	if ( empty( $active_plugins ) || wp_installing() ) {
   607 		return $plugins;
   676 		return $plugins;
       
   677 	}
   608 
   678 
   609 	$network_plugins = is_multisite() ? wp_get_active_network_plugins() : false;
   679 	$network_plugins = is_multisite() ? wp_get_active_network_plugins() : false;
   610 
   680 
   611 	foreach ( $active_plugins as $plugin ) {
   681 	foreach ( $active_plugins as $plugin ) {
   612 		if ( ! validate_file( $plugin ) // $plugin must validate as file
   682 		if ( ! validate_file( $plugin ) // $plugin must validate as file
   613 			&& '.php' == substr( $plugin, -4 ) // $plugin must end with '.php'
   683 			&& '.php' == substr( $plugin, -4 ) // $plugin must end with '.php'
   614 			&& file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist
   684 			&& file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist
   615 			// not already included as a network plugin
   685 			// not already included as a network plugin
   616 			&& ( ! $network_plugins || ! in_array( WP_PLUGIN_DIR . '/' . $plugin, $network_plugins ) )
   686 			&& ( ! $network_plugins || ! in_array( WP_PLUGIN_DIR . '/' . $plugin, $network_plugins ) )
   617 			)
   687 			) {
   618 		$plugins[] = WP_PLUGIN_DIR . '/' . $plugin;
   688 			$plugins[] = WP_PLUGIN_DIR . '/' . $plugin;
   619 	}
   689 		}
       
   690 	}
       
   691 
       
   692 	/*
       
   693 	 * Remove plugins from the list of active plugins when we're on an endpoint
       
   694 	 * that should be protected against WSODs and the plugin is paused.
       
   695 	 */
       
   696 	if ( wp_is_recovery_mode() ) {
       
   697 		$plugins = wp_skip_paused_plugins( $plugins );
       
   698 	}
       
   699 
   620 	return $plugins;
   700 	return $plugins;
       
   701 }
       
   702 
       
   703 /**
       
   704  * Filters a given list of plugins, removing any paused plugins from it.
       
   705  *
       
   706  * @since 5.2.0
       
   707  *
       
   708  * @param array $plugins List of absolute plugin main file paths.
       
   709  * @return array Filtered value of $plugins, without any paused plugins.
       
   710  */
       
   711 function wp_skip_paused_plugins( array $plugins ) {
       
   712 	$paused_plugins = wp_paused_plugins()->get_all();
       
   713 
       
   714 	if ( empty( $paused_plugins ) ) {
       
   715 		return $plugins;
       
   716 	}
       
   717 
       
   718 	foreach ( $plugins as $index => $plugin ) {
       
   719 		list( $plugin ) = explode( '/', plugin_basename( $plugin ) );
       
   720 
       
   721 		if ( array_key_exists( $plugin, $paused_plugins ) ) {
       
   722 			unset( $plugins[ $index ] );
       
   723 
       
   724 			// Store list of paused plugins for displaying an admin notice.
       
   725 			$GLOBALS['_paused_plugins'][ $plugin ] = $paused_plugins[ $plugin ];
       
   726 		}
       
   727 	}
       
   728 
       
   729 	return $plugins;
       
   730 }
       
   731 
       
   732 /**
       
   733  * Retrieves an array of active and valid themes.
       
   734  *
       
   735  * While upgrading or installing WordPress, no themes are returned.
       
   736  *
       
   737  * @since 5.1.0
       
   738  * @access private
       
   739  *
       
   740  * @return array Array of paths to theme directories.
       
   741  */
       
   742 function wp_get_active_and_valid_themes() {
       
   743 	global $pagenow;
       
   744 
       
   745 	$themes = array();
       
   746 
       
   747 	if ( wp_installing() && 'wp-activate.php' !== $pagenow ) {
       
   748 		return $themes;
       
   749 	}
       
   750 
       
   751 	if ( TEMPLATEPATH !== STYLESHEETPATH ) {
       
   752 		$themes[] = STYLESHEETPATH;
       
   753 	}
       
   754 
       
   755 	$themes[] = TEMPLATEPATH;
       
   756 
       
   757 	/*
       
   758 	 * Remove themes from the list of active themes when we're on an endpoint
       
   759 	 * that should be protected against WSODs and the theme is paused.
       
   760 	 */
       
   761 	if ( wp_is_recovery_mode() ) {
       
   762 		$themes = wp_skip_paused_themes( $themes );
       
   763 
       
   764 		// If no active and valid themes exist, skip loading themes.
       
   765 		if ( empty( $themes ) ) {
       
   766 			add_filter( 'wp_using_themes', '__return_false' );
       
   767 		}
       
   768 	}
       
   769 
       
   770 	return $themes;
       
   771 }
       
   772 
       
   773 /**
       
   774  * Filters a given list of themes, removing any paused themes from it.
       
   775  *
       
   776  * @since 5.2.0
       
   777  *
       
   778  * @param array $themes List of absolute theme directory paths.
       
   779  * @return array Filtered value of $themes, without any paused themes.
       
   780  */
       
   781 function wp_skip_paused_themes( array $themes ) {
       
   782 	$paused_themes = wp_paused_themes()->get_all();
       
   783 
       
   784 	if ( empty( $paused_themes ) ) {
       
   785 		return $themes;
       
   786 	}
       
   787 
       
   788 	foreach ( $themes as $index => $theme ) {
       
   789 		$theme = basename( $theme );
       
   790 
       
   791 		if ( array_key_exists( $theme, $paused_themes ) ) {
       
   792 			unset( $themes[ $index ] );
       
   793 
       
   794 			// Store list of paused themes for displaying an admin notice.
       
   795 			$GLOBALS['_paused_themes'][ $theme ] = $paused_themes[ $theme ];
       
   796 		}
       
   797 	}
       
   798 
       
   799 	return $themes;
       
   800 }
       
   801 
       
   802 /**
       
   803  * Is WordPress in Recovery Mode.
       
   804  *
       
   805  * In this mode, plugins or themes that cause WSODs will be paused.
       
   806  *
       
   807  * @since 5.2.0
       
   808  *
       
   809  * @return bool
       
   810  */
       
   811 function wp_is_recovery_mode() {
       
   812 	return wp_recovery_mode()->is_active();
       
   813 }
       
   814 
       
   815 /**
       
   816  * Determines whether we are currently on an endpoint that should be protected against WSODs.
       
   817  *
       
   818  * @since 5.2.0
       
   819  *
       
   820  * @return bool True if the current endpoint should be protected.
       
   821  */
       
   822 function is_protected_endpoint() {
       
   823 	// Protect login pages.
       
   824 	if ( isset( $GLOBALS['pagenow'] ) && 'wp-login.php' === $GLOBALS['pagenow'] ) {
       
   825 		return true;
       
   826 	}
       
   827 
       
   828 	// Protect the admin backend.
       
   829 	if ( is_admin() && ! wp_doing_ajax() ) {
       
   830 		return true;
       
   831 	}
       
   832 
       
   833 	// Protect AJAX actions that could help resolve a fatal error should be available.
       
   834 	if ( is_protected_ajax_action() ) {
       
   835 		return true;
       
   836 	}
       
   837 
       
   838 	/**
       
   839 	 * Filters whether the current request is against a protected endpoint.
       
   840 	 *
       
   841 	 * 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
       
   843 	 * addition to the admin backend, login pages and protected AJAX actions.
       
   844 	 *
       
   845 	 * @since 5.2.0
       
   846 	 *
       
   847 	 * @param bool $is_protected_endpoint Whether the currently requested endpoint is protected. Default false.
       
   848 	 */
       
   849 	return (bool) apply_filters( 'is_protected_endpoint', false );
       
   850 }
       
   851 
       
   852 /**
       
   853  * Determines whether we are currently handling an AJAX action that should be protected against WSODs.
       
   854  *
       
   855  * @since 5.2.0
       
   856  *
       
   857  * @return bool True if the current AJAX action should be protected.
       
   858  */
       
   859 function is_protected_ajax_action() {
       
   860 	if ( ! wp_doing_ajax() ) {
       
   861 		return false;
       
   862 	}
       
   863 
       
   864 	if ( ! isset( $_REQUEST['action'] ) ) {
       
   865 		return false;
       
   866 	}
       
   867 
       
   868 	$actions_to_protect = array(
       
   869 		'edit-theme-plugin-file', // Saving changes in the core code editor.
       
   870 		'heartbeat',              // Keep the heart beating.
       
   871 		'install-plugin',         // Installing a new plugin.
       
   872 		'install-theme',          // Installing a new theme.
       
   873 		'search-plugins',         // Searching in the list of plugins.
       
   874 		'search-install-plugins', // Searching for a plugin in the plugin install screen.
       
   875 		'update-plugin',          // Update an existing plugin.
       
   876 		'update-theme',           // Update an existing theme.
       
   877 	);
       
   878 
       
   879 	/**
       
   880 	 * Filters the array of protected AJAX actions.
       
   881 	 *
       
   882 	 * This filter is only fired when doing AJAX and the AJAX request has an 'action' property.
       
   883 	 *
       
   884 	 * @since 5.2.0
       
   885 	 *
       
   886 	 * @param array $actions_to_protect Array of strings with AJAX actions to protect.
       
   887 	 */
       
   888 	$actions_to_protect = (array) apply_filters( 'wp_protected_ajax_actions', $actions_to_protect );
       
   889 
       
   890 	if ( ! in_array( $_REQUEST['action'], $actions_to_protect, true ) ) {
       
   891 		return false;
       
   892 	}
       
   893 
       
   894 	return true;
   621 }
   895 }
   622 
   896 
   623 /**
   897 /**
   624  * Set internal encoding.
   898  * Set internal encoding.
   625  *
   899  *
   630  * @access private
   904  * @access private
   631  */
   905  */
   632 function wp_set_internal_encoding() {
   906 function wp_set_internal_encoding() {
   633 	if ( function_exists( 'mb_internal_encoding' ) ) {
   907 	if ( function_exists( 'mb_internal_encoding' ) ) {
   634 		$charset = get_option( 'blog_charset' );
   908 		$charset = get_option( 'blog_charset' );
   635 		if ( ! $charset || ! @mb_internal_encoding( $charset ) )
   909 		if ( ! $charset || ! @mb_internal_encoding( $charset ) ) {
   636 			mb_internal_encoding( 'UTF-8' );
   910 			mb_internal_encoding( 'UTF-8' );
       
   911 		}
   637 	}
   912 	}
   638 }
   913 }
   639 
   914 
   640 /**
   915 /**
   641  * Add magic quotes to `$_GET`, `$_POST`, `$_COOKIE`, and `$_SERVER`.
   916  * Add magic quotes to `$_GET`, `$_POST`, `$_COOKIE`, and `$_SERVER`.
   647  * @access private
   922  * @access private
   648  */
   923  */
   649 function wp_magic_quotes() {
   924 function wp_magic_quotes() {
   650 	// If already slashed, strip.
   925 	// If already slashed, strip.
   651 	if ( get_magic_quotes_gpc() ) {
   926 	if ( get_magic_quotes_gpc() ) {
   652 		$_GET    = stripslashes_deep( $_GET    );
   927 		$_GET    = stripslashes_deep( $_GET );
   653 		$_POST   = stripslashes_deep( $_POST   );
   928 		$_POST   = stripslashes_deep( $_POST );
   654 		$_COOKIE = stripslashes_deep( $_COOKIE );
   929 		$_COOKIE = stripslashes_deep( $_COOKIE );
   655 	}
   930 	}
   656 
   931 
   657 	// Escape with wpdb.
   932 	// Escape with wpdb.
   658 	$_GET    = add_magic_quotes( $_GET    );
   933 	$_GET    = add_magic_quotes( $_GET );
   659 	$_POST   = add_magic_quotes( $_POST   );
   934 	$_POST   = add_magic_quotes( $_POST );
   660 	$_COOKIE = add_magic_quotes( $_COOKIE );
   935 	$_COOKIE = add_magic_quotes( $_COOKIE );
   661 	$_SERVER = add_magic_quotes( $_SERVER );
   936 	$_SERVER = add_magic_quotes( $_SERVER );
   662 
   937 
   663 	// Force REQUEST to be GET + POST.
   938 	// Force REQUEST to be GET + POST.
   664 	$_REQUEST = array_merge( $_GET, $_POST );
   939 	$_REQUEST = array_merge( $_GET, $_POST );
   694 	// Use parens for clone to accommodate PHP 4. See #17880
   969 	// Use parens for clone to accommodate PHP 4. See #17880
   695 	return clone( $object );
   970 	return clone( $object );
   696 }
   971 }
   697 
   972 
   698 /**
   973 /**
   699  * Whether the current request is for an administrative interface page.
   974  * Determines whether the current request is for an administrative interface page.
   700  *
   975  *
   701  * Does not check if the user is an administrator; current_user_can()
   976  * Does not check if the user is an administrator; use current_user_can()
   702  * for checking roles and capabilities.
   977  * for checking roles and capabilities.
   703  *
   978  *
       
   979  * For more information on this and similar theme functions, check out
       
   980  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
       
   981  * Conditional Tags} article in the Theme Developer Handbook.
       
   982  *
   704  * @since 1.5.1
   983  * @since 1.5.1
   705  *
   984  *
   706  * @global WP_Screen $current_screen
   985  * @global WP_Screen $current_screen
   707  *
   986  *
   708  * @return bool True if inside WordPress administration interface, false otherwise.
   987  * @return bool True if inside WordPress administration interface, false otherwise.
   709  */
   988  */
   710 function is_admin() {
   989 function is_admin() {
   711 	if ( isset( $GLOBALS['current_screen'] ) )
   990 	if ( isset( $GLOBALS['current_screen'] ) ) {
   712 		return $GLOBALS['current_screen']->in_admin();
   991 		return $GLOBALS['current_screen']->in_admin();
   713 	elseif ( defined( 'WP_ADMIN' ) )
   992 	} elseif ( defined( 'WP_ADMIN' ) ) {
   714 		return WP_ADMIN;
   993 		return WP_ADMIN;
       
   994 	}
   715 
   995 
   716 	return false;
   996 	return false;
   717 }
   997 }
   718 
   998 
   719 /**
   999 /**
   720  * Whether the current request is for a site's admininstrative interface.
  1000  * Whether the current request is for a site's admininstrative interface.
   721  *
  1001  *
   722  * e.g. `/wp-admin/`
  1002  * e.g. `/wp-admin/`
   723  *
  1003  *
   724  * Does not check if the user is an administrator; current_user_can()
  1004  * Does not check if the user is an administrator; use current_user_can()
   725  * for checking roles and capabilities.
  1005  * for checking roles and capabilities.
   726  *
  1006  *
   727  * @since 3.1.0
  1007  * @since 3.1.0
   728  *
  1008  *
   729  * @global WP_Screen $current_screen
  1009  * @global WP_Screen $current_screen
   730  *
  1010  *
   731  * @return bool True if inside WordPress blog administration pages.
  1011  * @return bool True if inside WordPress blog administration pages.
   732  */
  1012  */
   733 function is_blog_admin() {
  1013 function is_blog_admin() {
   734 	if ( isset( $GLOBALS['current_screen'] ) )
  1014 	if ( isset( $GLOBALS['current_screen'] ) ) {
   735 		return $GLOBALS['current_screen']->in_admin( 'site' );
  1015 		return $GLOBALS['current_screen']->in_admin( 'site' );
   736 	elseif ( defined( 'WP_BLOG_ADMIN' ) )
  1016 	} elseif ( defined( 'WP_BLOG_ADMIN' ) ) {
   737 		return WP_BLOG_ADMIN;
  1017 		return WP_BLOG_ADMIN;
       
  1018 	}
   738 
  1019 
   739 	return false;
  1020 	return false;
   740 }
  1021 }
   741 
  1022 
   742 /**
  1023 /**
   743  * Whether the current request is for the network administrative interface.
  1024  * Whether the current request is for the network administrative interface.
   744  *
  1025  *
   745  * e.g. `/wp-admin/network/`
  1026  * e.g. `/wp-admin/network/`
   746  *
  1027  *
   747  * Does not check if the user is an administrator; current_user_can()
  1028  * Does not check if the user is an administrator; use current_user_can()
   748  * for checking roles and capabilities.
  1029  * for checking roles and capabilities.
   749  *
  1030  *
   750  * @since 3.1.0
  1031  * @since 3.1.0
   751  *
  1032  *
   752  * @global WP_Screen $current_screen
  1033  * @global WP_Screen $current_screen
   753  *
  1034  *
   754  * @return bool True if inside WordPress network administration pages.
  1035  * @return bool True if inside WordPress network administration pages.
   755  */
  1036  */
   756 function is_network_admin() {
  1037 function is_network_admin() {
   757 	if ( isset( $GLOBALS['current_screen'] ) )
  1038 	if ( isset( $GLOBALS['current_screen'] ) ) {
   758 		return $GLOBALS['current_screen']->in_admin( 'network' );
  1039 		return $GLOBALS['current_screen']->in_admin( 'network' );
   759 	elseif ( defined( 'WP_NETWORK_ADMIN' ) )
  1040 	} elseif ( defined( 'WP_NETWORK_ADMIN' ) ) {
   760 		return WP_NETWORK_ADMIN;
  1041 		return WP_NETWORK_ADMIN;
       
  1042 	}
   761 
  1043 
   762 	return false;
  1044 	return false;
   763 }
  1045 }
   764 
  1046 
   765 /**
  1047 /**
   766  * Whether the current request is for a user admin screen.
  1048  * Whether the current request is for a user admin screen.
   767  *
  1049  *
   768  * e.g. `/wp-admin/user/`
  1050  * e.g. `/wp-admin/user/`
   769  *
  1051  *
   770  * Does not inform on whether the user is an admin! Use capability
  1052  * Does not check if the user is an administrator; use current_user_can()
   771  * checks to tell if the user should be accessing a section or not
  1053  * for checking roles and capabilities.
   772  * current_user_can().
       
   773  *
  1054  *
   774  * @since 3.1.0
  1055  * @since 3.1.0
   775  *
  1056  *
   776  * @global WP_Screen $current_screen
  1057  * @global WP_Screen $current_screen
   777  *
  1058  *
   778  * @return bool True if inside WordPress user administration pages.
  1059  * @return bool True if inside WordPress user administration pages.
   779  */
  1060  */
   780 function is_user_admin() {
  1061 function is_user_admin() {
   781 	if ( isset( $GLOBALS['current_screen'] ) )
  1062 	if ( isset( $GLOBALS['current_screen'] ) ) {
   782 		return $GLOBALS['current_screen']->in_admin( 'user' );
  1063 		return $GLOBALS['current_screen']->in_admin( 'user' );
   783 	elseif ( defined( 'WP_USER_ADMIN' ) )
  1064 	} elseif ( defined( 'WP_USER_ADMIN' ) ) {
   784 		return WP_USER_ADMIN;
  1065 		return WP_USER_ADMIN;
       
  1066 	}
   785 
  1067 
   786 	return false;
  1068 	return false;
   787 }
  1069 }
   788 
  1070 
   789 /**
  1071 /**
   792  * @since 3.0.0
  1074  * @since 3.0.0
   793  *
  1075  *
   794  * @return bool True if Multisite is enabled, false otherwise.
  1076  * @return bool True if Multisite is enabled, false otherwise.
   795  */
  1077  */
   796 function is_multisite() {
  1078 function is_multisite() {
   797 	if ( defined( 'MULTISITE' ) )
  1079 	if ( defined( 'MULTISITE' ) ) {
   798 		return MULTISITE;
  1080 		return MULTISITE;
   799 
  1081 	}
   800 	if ( defined( 'SUBDOMAIN_INSTALL' ) || defined( 'VHOST' ) || defined( 'SUNRISE' ) )
  1082 
       
  1083 	if ( defined( 'SUBDOMAIN_INSTALL' ) || defined( 'VHOST' ) || defined( 'SUNRISE' ) ) {
   801 		return true;
  1084 		return true;
       
  1085 	}
   802 
  1086 
   803 	return false;
  1087 	return false;
   804 }
  1088 }
   805 
  1089 
   806 /**
  1090 /**
   812  *
  1096  *
   813  * @return int Site ID.
  1097  * @return int Site ID.
   814  */
  1098  */
   815 function get_current_blog_id() {
  1099 function get_current_blog_id() {
   816 	global $blog_id;
  1100 	global $blog_id;
   817 	return absint($blog_id);
  1101 	return absint( $blog_id );
   818 }
  1102 }
   819 
  1103 
   820 /**
  1104 /**
   821  * Retrieves the current network ID.
  1105  * Retrieves the current network ID.
   822  *
  1106  *
   857  */
  1141  */
   858 function wp_load_translations_early() {
  1142 function wp_load_translations_early() {
   859 	global $wp_locale;
  1143 	global $wp_locale;
   860 
  1144 
   861 	static $loaded = false;
  1145 	static $loaded = false;
   862 	if ( $loaded )
  1146 	if ( $loaded ) {
   863 		return;
  1147 		return;
       
  1148 	}
   864 	$loaded = true;
  1149 	$loaded = true;
   865 
  1150 
   866 	if ( function_exists( 'did_action' ) && did_action( 'init' ) )
  1151 	if ( function_exists( 'did_action' ) && did_action( 'init' ) ) {
   867 		return;
  1152 		return;
       
  1153 	}
   868 
  1154 
   869 	// We need $wp_local_package
  1155 	// We need $wp_local_package
   870 	require ABSPATH . WPINC . '/version.php';
  1156 	require ABSPATH . WPINC . '/version.php';
   871 
  1157 
   872 	// Translation and localization
  1158 	// Translation and localization
   880 
  1166 
   881 	$locales = $locations = array();
  1167 	$locales = $locations = array();
   882 
  1168 
   883 	while ( true ) {
  1169 	while ( true ) {
   884 		if ( defined( 'WPLANG' ) ) {
  1170 		if ( defined( 'WPLANG' ) ) {
   885 			if ( '' == WPLANG )
  1171 			if ( '' == WPLANG ) {
   886 				break;
  1172 				break;
       
  1173 			}
   887 			$locales[] = WPLANG;
  1174 			$locales[] = WPLANG;
   888 		}
  1175 		}
   889 
  1176 
   890 		if ( isset( $wp_local_package ) )
  1177 		if ( isset( $wp_local_package ) ) {
   891 			$locales[] = $wp_local_package;
  1178 			$locales[] = $wp_local_package;
   892 
  1179 		}
   893 		if ( ! $locales )
  1180 
       
  1181 		if ( ! $locales ) {
   894 			break;
  1182 			break;
   895 
  1183 		}
   896 		if ( defined( 'WP_LANG_DIR' ) && @is_dir( WP_LANG_DIR ) )
  1184 
       
  1185 		if ( defined( 'WP_LANG_DIR' ) && @is_dir( WP_LANG_DIR ) ) {
   897 			$locations[] = WP_LANG_DIR;
  1186 			$locations[] = WP_LANG_DIR;
   898 
  1187 		}
   899 		if ( defined( 'WP_CONTENT_DIR' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) )
  1188 
       
  1189 		if ( defined( 'WP_CONTENT_DIR' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) ) {
   900 			$locations[] = WP_CONTENT_DIR . '/languages';
  1190 			$locations[] = WP_CONTENT_DIR . '/languages';
   901 
  1191 		}
   902 		if ( @is_dir( ABSPATH . 'wp-content/languages' ) )
  1192 
       
  1193 		if ( @is_dir( ABSPATH . 'wp-content/languages' ) ) {
   903 			$locations[] = ABSPATH . 'wp-content/languages';
  1194 			$locations[] = ABSPATH . 'wp-content/languages';
   904 
  1195 		}
   905 		if ( @is_dir( ABSPATH . WPINC . '/languages' ) )
  1196 
       
  1197 		if ( @is_dir( ABSPATH . WPINC . '/languages' ) ) {
   906 			$locations[] = ABSPATH . WPINC . '/languages';
  1198 			$locations[] = ABSPATH . WPINC . '/languages';
   907 
  1199 		}
   908 		if ( ! $locations )
  1200 
       
  1201 		if ( ! $locations ) {
   909 			break;
  1202 			break;
       
  1203 		}
   910 
  1204 
   911 		$locations = array_unique( $locations );
  1205 		$locations = array_unique( $locations );
   912 
  1206 
   913 		foreach ( $locales as $locale ) {
  1207 		foreach ( $locales as $locale ) {
   914 			foreach ( $locations as $location ) {
  1208 			foreach ( $locations as $location ) {
   915 				if ( file_exists( $location . '/' . $locale . '.mo' ) ) {
  1209 				if ( file_exists( $location . '/' . $locale . '.mo' ) ) {
   916 					load_textdomain( 'default', $location . '/' . $locale . '.mo' );
  1210 					load_textdomain( 'default', $location . '/' . $locale . '.mo' );
   917 					if ( defined( 'WP_SETUP_CONFIG' ) && file_exists( $location . '/admin-' . $locale . '.mo' ) )
  1211 					if ( defined( 'WP_SETUP_CONFIG' ) && file_exists( $location . '/admin-' . $locale . '.mo' ) ) {
   918 						load_textdomain( 'default', $location . '/admin-' . $locale . '.mo' );
  1212 						load_textdomain( 'default', $location . '/admin-' . $locale . '.mo' );
       
  1213 					}
   919 					break 2;
  1214 					break 2;
   920 				}
  1215 				}
   921 			}
  1216 			}
   922 		}
  1217 		}
   923 
  1218 
   949 		$installing = defined( 'WP_INSTALLING' ) && WP_INSTALLING;
  1244 		$installing = defined( 'WP_INSTALLING' ) && WP_INSTALLING;
   950 	}
  1245 	}
   951 
  1246 
   952 	if ( ! is_null( $is_installing ) ) {
  1247 	if ( ! is_null( $is_installing ) ) {
   953 		$old_installing = $installing;
  1248 		$old_installing = $installing;
   954 		$installing = $is_installing;
  1249 		$installing     = $is_installing;
   955 		return (bool) $old_installing;
  1250 		return (bool) $old_installing;
   956 	}
  1251 	}
   957 
  1252 
   958 	return (bool) $installing;
  1253 	return (bool) $installing;
   959 }
  1254 }
   973 		}
  1268 		}
   974 
  1269 
   975 		if ( '1' == $_SERVER['HTTPS'] ) {
  1270 		if ( '1' == $_SERVER['HTTPS'] ) {
   976 			return true;
  1271 			return true;
   977 		}
  1272 		}
   978 	} elseif ( isset($_SERVER['SERVER_PORT'] ) && ( '443' == $_SERVER['SERVER_PORT'] ) ) {
  1273 	} elseif ( isset( $_SERVER['SERVER_PORT'] ) && ( '443' == $_SERVER['SERVER_PORT'] ) ) {
   979 		return true;
  1274 		return true;
   980 	}
  1275 	}
   981 	return false;
  1276 	return false;
   982 }
  1277 }
   983 
  1278 
  1028 		$ini_all = false;
  1323 		$ini_all = false;
  1029 		// Sometimes `ini_get_all()` is disabled via the `disable_functions` option for "security purposes".
  1324 		// Sometimes `ini_get_all()` is disabled via the `disable_functions` option for "security purposes".
  1030 		if ( function_exists( 'ini_get_all' ) ) {
  1325 		if ( function_exists( 'ini_get_all' ) ) {
  1031 			$ini_all = ini_get_all();
  1326 			$ini_all = ini_get_all();
  1032 		}
  1327 		}
  1033  	}
  1328 	}
  1034 
  1329 
  1035 	// Bit operator to workaround https://bugs.php.net/bug.php?id=44936 which changes access level to 63 in PHP 5.2.6 - 5.2.17.
  1330 	// Bit operator to workaround https://bugs.php.net/bug.php?id=44936 which changes access level to 63 in PHP 5.2.6 - 5.2.17.
  1036 	if ( isset( $ini_all[ $setting ]['access'] ) && ( INI_ALL === ( $ini_all[ $setting ]['access'] & 7 ) || INI_USER === ( $ini_all[ $setting ]['access'] & 7 ) ) ) {
  1331 	if ( isset( $ini_all[ $setting ]['access'] ) && ( INI_ALL === ( $ini_all[ $setting ]['access'] & 7 ) || INI_USER === ( $ini_all[ $setting ]['access'] & 7 ) ) ) {
  1037 		return true;
  1332 		return true;
  1038 	}
  1333 	}
  1059 	 * @since 4.7.0
  1354 	 * @since 4.7.0
  1060 	 *
  1355 	 *
  1061 	 * @param bool $wp_doing_ajax Whether the current request is a WordPress Ajax request.
  1356 	 * @param bool $wp_doing_ajax Whether the current request is a WordPress Ajax request.
  1062 	 */
  1357 	 */
  1063 	return apply_filters( 'wp_doing_ajax', defined( 'DOING_AJAX' ) && DOING_AJAX );
  1358 	return apply_filters( 'wp_doing_ajax', defined( 'DOING_AJAX' ) && DOING_AJAX );
       
  1359 }
       
  1360 
       
  1361 /**
       
  1362  * Determines whether the current request should use themes.
       
  1363  *
       
  1364  * @since 5.1.0
       
  1365  *
       
  1366  * @return bool True if themes should be used, false otherwise.
       
  1367  */
       
  1368 function wp_using_themes() {
       
  1369 	/**
       
  1370 	 * Filters whether the current request should use themes.
       
  1371 	 *
       
  1372 	 * @since 5.1.0
       
  1373 	 *
       
  1374 	 * @param bool $wp_using_themes Whether the current request should use themes.
       
  1375 	 */
       
  1376 	return apply_filters( 'wp_using_themes', defined( 'WP_USE_THEMES' ) && WP_USE_THEMES );
  1064 }
  1377 }
  1065 
  1378 
  1066 /**
  1379 /**
  1067  * Determines whether the current request is a WordPress cron request.
  1380  * Determines whether the current request is a WordPress cron request.
  1068  *
  1381  *
  1122  */
  1435  */
  1123 function wp_start_scraping_edited_file_errors() {
  1436 function wp_start_scraping_edited_file_errors() {
  1124 	if ( ! isset( $_REQUEST['wp_scrape_key'] ) || ! isset( $_REQUEST['wp_scrape_nonce'] ) ) {
  1437 	if ( ! isset( $_REQUEST['wp_scrape_key'] ) || ! isset( $_REQUEST['wp_scrape_nonce'] ) ) {
  1125 		return;
  1438 		return;
  1126 	}
  1439 	}
  1127 	$key = substr( sanitize_key( wp_unslash( $_REQUEST['wp_scrape_key'] ) ), 0, 32 );
  1440 	$key   = substr( sanitize_key( wp_unslash( $_REQUEST['wp_scrape_key'] ) ), 0, 32 );
  1128 	$nonce = wp_unslash( $_REQUEST['wp_scrape_nonce'] );
  1441 	$nonce = wp_unslash( $_REQUEST['wp_scrape_nonce'] );
  1129 
  1442 
  1130 	if ( get_transient( 'scrape_key_' . $key ) !== $nonce ) {
  1443 	if ( get_transient( 'scrape_key_' . $key ) !== $nonce ) {
  1131 		echo "###### wp_scraping_result_start:$key ######";
  1444 		echo "###### wp_scraping_result_start:$key ######";
  1132 		echo wp_json_encode( array(
  1445 		echo wp_json_encode(
  1133 			'code' => 'scrape_nonce_failure',
  1446 			array(
  1134 			'message' => __( 'Scrape nonce check failed. Please try again.' ),
  1447 				'code'    => 'scrape_nonce_failure',
  1135 		) );
  1448 				'message' => __( 'Scrape nonce check failed. Please try again.' ),
       
  1449 			)
       
  1450 		);
  1136 		echo "###### wp_scraping_result_end:$key ######";
  1451 		echo "###### wp_scraping_result_end:$key ######";
  1137 		die();
  1452 		die();
       
  1453 	}
       
  1454 	if ( ! defined( 'WP_SANDBOX_SCRAPING' ) ) {
       
  1455 		define( 'WP_SANDBOX_SCRAPING', true );
  1138 	}
  1456 	}
  1139 	register_shutdown_function( 'wp_finalize_scraping_edited_file_errors', $key );
  1457 	register_shutdown_function( 'wp_finalize_scraping_edited_file_errors', $key );
  1140 }
  1458 }
  1141 
  1459 
  1142 /**
  1460 /**
  1155 	} else {
  1473 	} else {
  1156 		echo wp_json_encode( true );
  1474 		echo wp_json_encode( true );
  1157 	}
  1475 	}
  1158 	echo "\n###### wp_scraping_result_end:$scrape_key ######\n";
  1476 	echo "\n###### wp_scraping_result_end:$scrape_key ######\n";
  1159 }
  1477 }
       
  1478 
       
  1479 /**
       
  1480  * Checks whether current request is a JSON request, or is expecting a JSON response.
       
  1481  *
       
  1482  * @since 5.0.0
       
  1483  *
       
  1484  * @return bool True if Accepts or Content-Type headers contain application/json, false otherwise.
       
  1485  */
       
  1486 function wp_is_json_request() {
       
  1487 
       
  1488 	if ( isset( $_SERVER['HTTP_ACCEPT'] ) && false !== strpos( $_SERVER['HTTP_ACCEPT'], 'application/json' ) ) {
       
  1489 		return true;
       
  1490 	}
       
  1491 
       
  1492 	if ( isset( $_SERVER['CONTENT_TYPE'] ) && 'application/json' === $_SERVER['CONTENT_TYPE'] ) {
       
  1493 		return true;
       
  1494 	}
       
  1495 
       
  1496 	return false;
       
  1497 
       
  1498 }
       
  1499 
       
  1500 /**
       
  1501  * Checks whether current request is a JSONP request, or is expecting a JSONP response.
       
  1502  *
       
  1503  * @since 5.2.0
       
  1504  *
       
  1505  * @return bool True if JSONP request, false otherwise.
       
  1506  */
       
  1507 function wp_is_jsonp_request() {
       
  1508 	if ( ! isset( $_GET['_jsonp'] ) ) {
       
  1509 		return false;
       
  1510 	}
       
  1511 
       
  1512 	if ( ! function_exists( 'wp_check_jsonp_callback' ) ) {
       
  1513 		require_once ABSPATH . WPINC . '/functions.php';
       
  1514 	}
       
  1515 
       
  1516 	$jsonp_callback = $_GET['_jsonp'];
       
  1517 	if ( ! wp_check_jsonp_callback( $jsonp_callback ) ) {
       
  1518 		return false;
       
  1519 	}
       
  1520 
       
  1521 	/** This filter is documented in wp-includes/rest-api/class-wp-rest-server.php */
       
  1522 	$jsonp_enabled = apply_filters( 'rest_jsonp_enabled', true );
       
  1523 
       
  1524 	return $jsonp_enabled;
       
  1525 
       
  1526 }
       
  1527 
       
  1528 /**
       
  1529  * Checks whether current request is an XML request, or is expecting an XML response.
       
  1530  *
       
  1531  * @since 5.2.0
       
  1532  *
       
  1533  * @return bool True if Accepts or Content-Type headers contain xml, false otherwise.
       
  1534  */
       
  1535 function wp_is_xml_request() {
       
  1536 	$accepted = array(
       
  1537 		'text/xml',
       
  1538 		'application/rss+xml',
       
  1539 		'application/atom+xml',
       
  1540 		'application/rdf+xml',
       
  1541 		'text/xml+oembed',
       
  1542 		'application/xml+oembed',
       
  1543 	);
       
  1544 
       
  1545 	if ( isset( $_SERVER['HTTP_ACCEPT'] ) ) {
       
  1546 		foreach ( $accepted as $type ) {
       
  1547 			if ( false !== strpos( $_SERVER['HTTP_ACCEPT'], $type ) ) {
       
  1548 				return true;
       
  1549 			}
       
  1550 		}
       
  1551 	}
       
  1552 
       
  1553 	if ( isset( $_SERVER['CONTENT_TYPE'] ) && in_array( $_SERVER['CONTENT_TYPE'], $accepted, true ) ) {
       
  1554 		return true;
       
  1555 	}
       
  1556 
       
  1557 	return false;
       
  1558 }