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. Fixes #48692. git-svn-id: https://develop.svn.wordpress.org/trunk@46797 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
e720a9ddc7
commit
4b60e6a0db
@ -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.
|
||||
*
|
||||
@ -1858,14 +1898,18 @@ class WP_Site_Health {
|
||||
'label' => __( 'PHP Version' ),
|
||||
'test' => 'php_version',
|
||||
),
|
||||
'sql_server' => array(
|
||||
'label' => __( 'Database Server version' ),
|
||||
'test' => 'sql_server',
|
||||
),
|
||||
'php_extensions' => array(
|
||||
'label' => __( 'PHP Extensions' ),
|
||||
'test' => 'php_extensions',
|
||||
),
|
||||
'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',
|
||||
|
Loading…
Reference in New Issue
Block a user