Viewing 3 replies - 1 through 3 (of 3 total)
  • Gareth

    (@catapult_themes)

    Hi

    I’d like to reiterate rrhode’s statement regarding the use of ‘date_default_timezone_set’. This seems to be creating a conflict with other plugins which depend on correct timestamps. Do you have any plans to update this?

    Thanks for your response.

    Are you ever going to reply to this issue? People have been patiently waiting and I know I have a client relying on this change before we move to production.

    Thank!

    Thread Starter ryvix

    (@rrhode)

    I’ve also had issues with other plugins doing this as well. I think possibly even Yoast SEO might have been one of them if I remember correctly.

    Here are a couple examples of workarounds that I’ve used:

    class YourClassName {
    	private static $tz;
    
    	function __construct() {
    		// set timezone (gets reset in __destruct)
    		self::$tz = date_default_timezone_get();
    		date_default_timezone_set( get_option( 'timezone_string' ) );
    	}
    
    	function __destruct() {
    		// reset timezone back to old value (gets set in __construct)
    		date_default_timezone_set(self::$tz);
    	}
    
    }
    // Save original time zone.
    $original_timezone = date_default_timezone_get();
    
    // Set timezone based on WP Timezone option under Settings > General.
    date_default_timezone_set( get_option( 'timezone_string' ) );
    
    // Whatever you have to do here with the correct timezone...
    
    // Reset the timezone back to the original time zone.
    date_default_timezone_set($original_timezone);
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Usage of date_default_timezone_set breaking site’ is closed to new replies.