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. git-svn-id: https://develop.svn.wordpress.org/branches/5.3@46798 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
8717becdd6
commit
861d1d6182
@ -1015,6 +1015,46 @@ class WP_Site_Health {
|
|||||||
return $result;
|
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.
|
* Test if the SQL server is up to date.
|
||||||
*
|
*
|
||||||
@ -1842,51 +1882,55 @@ class WP_Site_Health {
|
|||||||
public static function get_tests() {
|
public static function get_tests() {
|
||||||
$tests = array(
|
$tests = array(
|
||||||
'direct' => array(
|
'direct' => array(
|
||||||
'wordpress_version' => array(
|
'wordpress_version' => array(
|
||||||
'label' => __( 'WordPress Version' ),
|
'label' => __( 'WordPress Version' ),
|
||||||
'test' => 'wordpress_version',
|
'test' => 'wordpress_version',
|
||||||
),
|
),
|
||||||
'plugin_version' => array(
|
'plugin_version' => array(
|
||||||
'label' => __( 'Plugin Versions' ),
|
'label' => __( 'Plugin Versions' ),
|
||||||
'test' => 'plugin_version',
|
'test' => 'plugin_version',
|
||||||
),
|
),
|
||||||
'theme_version' => array(
|
'theme_version' => array(
|
||||||
'label' => __( 'Theme Versions' ),
|
'label' => __( 'Theme Versions' ),
|
||||||
'test' => 'theme_version',
|
'test' => 'theme_version',
|
||||||
),
|
),
|
||||||
'php_version' => array(
|
'php_version' => array(
|
||||||
'label' => __( 'PHP Version' ),
|
'label' => __( 'PHP Version' ),
|
||||||
'test' => 'php_version',
|
'test' => 'php_version',
|
||||||
),
|
),
|
||||||
'sql_server' => array(
|
'php_extensions' => array(
|
||||||
'label' => __( 'Database Server version' ),
|
|
||||||
'test' => 'sql_server',
|
|
||||||
),
|
|
||||||
'php_extensions' => array(
|
|
||||||
'label' => __( 'PHP Extensions' ),
|
'label' => __( 'PHP Extensions' ),
|
||||||
'test' => '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' ),
|
'label' => __( 'MySQL utf8mb4 support' ),
|
||||||
'test' => 'utf8mb4_support',
|
'test' => 'utf8mb4_support',
|
||||||
),
|
),
|
||||||
'https_status' => array(
|
'https_status' => array(
|
||||||
'label' => __( 'HTTPS status' ),
|
'label' => __( 'HTTPS status' ),
|
||||||
'test' => 'https_status',
|
'test' => 'https_status',
|
||||||
),
|
),
|
||||||
'ssl_support' => array(
|
'ssl_support' => array(
|
||||||
'label' => __( 'Secure communication' ),
|
'label' => __( 'Secure communication' ),
|
||||||
'test' => 'ssl_support',
|
'test' => 'ssl_support',
|
||||||
),
|
),
|
||||||
'scheduled_events' => array(
|
'scheduled_events' => array(
|
||||||
'label' => __( 'Scheduled events' ),
|
'label' => __( 'Scheduled events' ),
|
||||||
'test' => 'scheduled_events',
|
'test' => 'scheduled_events',
|
||||||
),
|
),
|
||||||
'http_requests' => array(
|
'http_requests' => array(
|
||||||
'label' => __( 'HTTP Requests' ),
|
'label' => __( 'HTTP Requests' ),
|
||||||
'test' => 'http_requests',
|
'test' => 'http_requests',
|
||||||
),
|
),
|
||||||
'debug_enabled' => array(
|
'debug_enabled' => array(
|
||||||
'label' => __( 'Debugging enabled' ),
|
'label' => __( 'Debugging enabled' ),
|
||||||
'test' => 'is_in_debug_mode',
|
'test' => 'is_in_debug_mode',
|
||||||
),
|
),
|
||||||
|
Loading…
Reference in New Issue
Block a user