Bootstrap/Load: Reorganize the initialization flow so that the check for PHP and MySQL requirements could run as early as possible.

This allows us to use PHP 5.6+ syntax in more files, and display a proper error message on older PHP versions, instead of causing a parse error.

Fixes #48059.

git-svn-id: https://develop.svn.wordpress.org/trunk@46183 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2019-09-19 12:01:03 +00:00
parent a22920743b
commit 5f1cbd7165
2 changed files with 13 additions and 16 deletions

View File

@ -131,13 +131,10 @@ function wp_check_php_mysql_versions() {
$php_version = phpversion(); $php_version = phpversion();
if ( version_compare( $required_php_version, $php_version, '>' ) ) { if ( version_compare( $required_php_version, $php_version, '>' ) ) {
wp_load_translations_early();
$protocol = wp_get_server_protocol(); $protocol = wp_get_server_protocol();
header( sprintf( '%s 500 Internal Server Error', $protocol ), true, 500 ); header( sprintf( '%s 500 Internal Server Error', $protocol ), true, 500 );
header( 'Content-Type: text/html; charset=utf-8' ); header( 'Content-Type: text/html; charset=utf-8' );
/* translators: 1: Current PHP version number, 2: WordPress version number, 3: Minimum required PHP version number. */ 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 );
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 );
exit( 1 ); exit( 1 );
} }

View File

@ -15,8 +15,19 @@
*/ */
define( 'WPINC', 'wp-includes' ); define( 'WPINC', 'wp-includes' );
// Include files required for initialization. /*
* These can't be directly globalized in version.php. When updating,
* we're including version.php from another installation and don't want
* these values to be overridden if already set.
*/
global $wp_version, $wp_db_version, $tinymce_version, $required_php_version, $required_mysql_version, $wp_local_package;
require( ABSPATH . WPINC . '/version.php' );
require( ABSPATH . WPINC . '/load.php' ); require( ABSPATH . WPINC . '/load.php' );
// Check for the required PHP version and for the MySQL extension or a database drop-in.
wp_check_php_mysql_versions();
// Include files required for initialization.
require( ABSPATH . WPINC . '/class-wp-paused-extensions-storage.php' ); require( ABSPATH . WPINC . '/class-wp-paused-extensions-storage.php' );
require( ABSPATH . WPINC . '/class-wp-fatal-error-handler.php' ); require( ABSPATH . WPINC . '/class-wp-fatal-error-handler.php' );
require( ABSPATH . WPINC . '/class-wp-recovery-mode-cookie-service.php' ); require( ABSPATH . WPINC . '/class-wp-recovery-mode-cookie-service.php' );
@ -28,14 +39,6 @@ require( ABSPATH . WPINC . '/error-protection.php' );
require( ABSPATH . WPINC . '/default-constants.php' ); require( ABSPATH . WPINC . '/default-constants.php' );
require_once( ABSPATH . WPINC . '/plugin.php' ); require_once( ABSPATH . WPINC . '/plugin.php' );
/*
* These can't be directly globalized in version.php. When updating,
* we're including version.php from another installation and don't want
* these values to be overridden if already set.
*/
global $wp_version, $wp_db_version, $tinymce_version, $required_php_version, $required_mysql_version, $wp_local_package;
require( ABSPATH . WPINC . '/version.php' );
/** /**
* If not already configured, `$blog_id` will default to 1 in a single site * If not already configured, `$blog_id` will default to 1 in a single site
* configuration. In multisite, it will be overridden by default in ms-settings.php. * configuration. In multisite, it will be overridden by default in ms-settings.php.
@ -51,9 +54,6 @@ wp_initial_constants();
// Make sure we register the shutdown handler for fatal errors as soon as possible. // Make sure we register the shutdown handler for fatal errors as soon as possible.
wp_register_fatal_error_handler(); wp_register_fatal_error_handler();
// Check for the required PHP version and for the MySQL extension or a database drop-in.
wp_check_php_mysql_versions();
// WordPress calculates offsets from UTC. // WordPress calculates offsets from UTC.
date_default_timezone_set( 'UTC' ); date_default_timezone_set( 'UTC' );