Hi,
My WordPress install’s local time zone is GMT-0500. I verified this by visiting the general settings page, which shows the correct universal and local time.
If the current local time is Fri Dec 10 2021 13:22:00
and I put a Today after condition on an element, the element is visible when the condition’s date/time is Fri Dec 10 2021 08:20:00 GMT-0500
but hidden when the condition’s date/time is Fri Dec 10 2021 08:25:00 GMT-0500
.
It’s also visible when the condition’s date/time is Fri Dec 10 2021 13:20:00 GMT-0000
but hidden when the condition’s date/time is Fri Dec 10 2021 13:25:00 GMT-0000
.
In the global_today
function, you’re comparing current_time('timestamp')
to strtotime( $date )
. The strtotime
part is fine, I think, because strtotime
correctly uses the GMT-0500
part of the string to adjust for the time zone and return a UTC timestamp. But WordPress’s current_time
function doesn’t return a UTC timestamp unless you pass true
as its second parameter.
Without that parameter, it gets time()
, which is a UTC timestamp, and then it adds get_option( 'gmt_offset' ) * HOUR_IN_SECONDS
to it. In my case, it adds -18000 seconds to the UTC timestamp of the current time. Then, Cornerstone compares that value to the UTC timestamp of the date/time when the element is supposed to appear, so the element appears at the wrong time.
If I add true
as the second parameter of the current_time('timestamp')
function call, the condition starts behaving as expected.
PHP 7.4 (and PHP 8.0)
WordPress 5.8.2
Cornerstone 6.1.4
Thanks!