Guard against invalid (php) timezone strings in wordpress
Pulling this out from core#2122 since it's wordpress-specific and I think has a relatively easy fix.
As mentioned in that ticket the default timezone string in wordpress is 'UTC+0', which is not a valid php timezone string. Also it looks like maybe if you have an offset timezone instead of a place name string in the settings, then currently civi attempts to use null or blank which is also invalid. Offsets aren't recommended anyway, but they are valid choices in wordpress.
Looking at the code I think this can be fixed like this, I just don't have a system to test it on. The function appears to be available since wordpress 5.3.
--- a/CRM/Utils/System/WordPress.php
+++ b/CRM/Utils/System/WordPress.php
@@ -745,7 +745,7 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
else {
throw new CRM_Core_Exception("Could not find the bootstrap file for WordPress");
}
- $wpUserTimezone = get_option('timezone_string');
+ $wpUserTimezone = wp_timezone_string();
if ($wpUserTimezone) {
date_default_timezone_set($wpUserTimezone);
CRM_Core_Config::singleton()->userSystem->setMySQLTimeZone();
@@ -1128,7 +1128,7 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
* @inheritDoc
*/
public function getTimeZoneString() {
- return get_option('timezone_string');
+ return wp_timezone_string();
}
/**