diff options
author | Sergey Biryukov <sergeybiryukov@git.wordpress.org> | 2019-11-28 15:46:45 +0000 |
---|---|---|
committer | Sergey Biryukov <sergeybiryukov@git.wordpress.org> | 2019-11-28 15:46:45 +0000 |
commit | 4b60e6a0db3e47ec018a8d9900e48cf7e70e0866 (patch) | |
tree | f755938d3d4d043b600aeda2624991001d3b6893 /src | |
parent | e720a9ddc7ff7738584dc031e56727040dca0248 (diff) | |
download | wordpress-4b60e6a0db3e47ec018a8d9900e48cf7e70e0866.tar.gz wordpress-4b60e6a0db3e47ec018a8d9900e48cf7e70e0866.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/wp-admin/includes/class-wp-site-health.php | 74 |
1 files changed, 59 insertions, 15 deletions
diff --git a/src/wp-admin/includes/class-wp-site-health.php b/src/wp-admin/includes/class-wp-site-health.php index 605f194ca3..62f089b941 100644 --- a/src/wp-admin/includes/class-wp-site-health.php +++ b/src/wp-admin/includes/class-wp-site-health.php @@ -1016,6 +1016,46 @@ class WP_Site_Health { } /** + * 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. * * @since 5.2.0 @@ -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', ), |