Site Health: Add a test for PHP default timezone.

The test reports a failure if the default timezone was changed with `date_default_timezone_set()` to anything other than `UTC`.

WordPress historically uses `UTC` as the default timezone for calculating date and time offsets, overriding it is not recommended and can cause widespread and obscure issues.

Props Rarst, Clorith, TimothyBlynJacobs.
Merges [46797] to the 5.3 branch.
Fixes #48692.
Built from https://develop.svn.wordpress.org/branches/5.3@46798


git-svn-id: http://core.svn.wordpress.org/branches/5.3@46598 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2019-11-28 15:57:05 +00:00
parent 9156181d27
commit b7f33680dc
2 changed files with 60 additions and 16 deletions

View File

@ -1015,6 +1015,46 @@ class WP_Site_Health {
return $result;
}
/**
* Test if the PHP default timezone is set to UTC.
*
* @since 5.3.1
*
* @return array The test results.
*/
public function get_test_php_default_timezone() {
$result = array(
'label' => __( 'PHP default timezone is valid' ),
'status' => 'good',
'badge' => array(
'label' => __( 'Performance' ),
'color' => 'blue',
),
'description' => sprintf(
'<p>%s</p>',
__( 'PHP default timezone was configured by WordPress on loading. This is necessary for correct calculations of dates and times.' )
),
'test' => 'php_default_timezone',
);
if ( 'UTC' !== date_default_timezone_get() ) {
$result['status'] = 'critical';
$result['label'] = __( 'PHP default timezone is invalid' );
$result['description'] = sprintf(
'<p>%s</p>',
sprintf(
/* translators: %s: date_default_timezone_set() */
__( 'PHP default timezone was changed after WordPress loading by a %s function call. This interferes with correct calculations of dates and times.' ),
'<code>date_default_timezone_set()</code>'
)
);
}
return $result;
}
/**
* Test if the SQL server is up to date.
*
@ -1842,51 +1882,55 @@ class WP_Site_Health {
public static function get_tests() {
$tests = array(
'direct' => array(
'wordpress_version' => array(
'wordpress_version' => array(
'label' => __( 'WordPress Version' ),
'test' => 'wordpress_version',
),
'plugin_version' => array(
'plugin_version' => array(
'label' => __( 'Plugin Versions' ),
'test' => 'plugin_version',
),
'theme_version' => array(
'theme_version' => array(
'label' => __( 'Theme Versions' ),
'test' => 'theme_version',
),
'php_version' => array(
'php_version' => array(
'label' => __( 'PHP Version' ),
'test' => 'php_version',
),
'sql_server' => array(
'label' => __( 'Database Server version' ),
'test' => 'sql_server',
),
'php_extensions' => array(
'php_extensions' => array(
'label' => __( 'PHP Extensions' ),
'test' => 'php_extensions',
),
'utf8mb4_support' => array(
'php_default_timezone' => array(
'label' => __( 'PHP Default Timezone' ),
'test' => 'php_default_timezone',
),
'sql_server' => array(
'label' => __( 'Database Server version' ),
'test' => 'sql_server',
),
'utf8mb4_support' => array(
'label' => __( 'MySQL utf8mb4 support' ),
'test' => 'utf8mb4_support',
),
'https_status' => array(
'https_status' => array(
'label' => __( 'HTTPS status' ),
'test' => 'https_status',
),
'ssl_support' => array(
'ssl_support' => array(
'label' => __( 'Secure communication' ),
'test' => 'ssl_support',
),
'scheduled_events' => array(
'scheduled_events' => array(
'label' => __( 'Scheduled events' ),
'test' => 'scheduled_events',
),
'http_requests' => array(
'http_requests' => array(
'label' => __( 'HTTP Requests' ),
'test' => 'http_requests',
),
'debug_enabled' => array(
'debug_enabled' => array(
'label' => __( 'Debugging enabled' ),
'test' => 'is_in_debug_mode',
),

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.3.1-alpha-46796';
$wp_version = '5.3.1-alpha-46798';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.