| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
if (!function_exists('wp_timezone_string')) { |
| 6 |
/** |
| 7 |
* Function is introduced in WP 5.3. |
| 8 |
* |
| 9 |
* @since 2.20.0 |
| 10 |
* |
| 11 |
* @see https://developer.wordpress.org/reference/functions/wp_timezone_string |
| 12 |
*/ |
| 13 |
function wp_timezone_string() |
| 14 |
{ |
| 15 |
$timezone_string = get_option('timezone_string'); |
| 16 |
|
| 17 |
if ($timezone_string) { |
| 18 |
return $timezone_string; |
| 19 |
} |
| 20 |
|
| 21 |
$offset = (float)get_option('gmt_offset'); |
| 22 |
$hours = (int)$offset; |
| 23 |
$minutes = ($offset - $hours); |
| 24 |
|
| 25 |
$sign = ($offset < 0) ? '-' : '+'; |
| 26 |
$abs_hour = abs($hours); |
| 27 |
$abs_mins = abs($minutes * 60); |
| 28 |
$tz_offset = sprintf('%s%02d:%02d', $sign, $abs_hour, $abs_mins); |
| 29 |
|
| 30 |
return $tz_offset; |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
if (!function_exists('wp_timezone')) { |
| 35 |
/** |
| 36 |
* Function is introduced in WP 5.3. |
| 37 |
* |
| 38 |
* @since 2.20.0 |
| 39 |
* |
| 40 |
* @see https://developer.wordpress.org/reference/functions/wp_timezone |
| 41 |
*/ |
| 42 |
function wp_timezone() |
| 43 |
{ |
| 44 |
return new DateTimeZone(wp_timezone_string()); |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
if (!function_exists('current_datetime')) { |
| 49 |
/** |
| 50 |
* Function is introduced in WP 5.3. |
| 51 |
* |
| 52 |
* @since 2.20.0 |
| 53 |
* |
| 54 |
* @see https://developer.wordpress.org/reference/functions/current_datetime |
| 55 |
*/ |
| 56 |
function current_datetime() |
| 57 |
{ |
| 58 |
return date_create_immutable('now', wp_timezone()); |
| 59 |
} |
| 60 |
} |
| 61 |
|