WordPress.org

Make WordPress Core

Ticket #24730: 24730.diff

File 24730.diff, 983 bytes (added by rmccue, 5 years ago)

Add a wp_get_timezone() function

  • wp-includes/functions.php

    diff --git wp-includes/functions.php wp-includes/functions.php
    index eb9715d..67f2231 100644
    function global_terms_enabled() { 
    32653265}
    32663266
    32673267/**
     3268 * Get the timezone object
     3269 *
     3270 * Uses timezone_string for a proper timezone if available, otherwise falls back
     3271 * to an offset.
     3272 *
     3273 * @return DateTimeZone
     3274 */
     3275function wp_get_timezone() {
     3276        $tzstring = get_option( 'timezone_string' );
     3277        if ( ! $tzstring ) {
     3278                // Create a UTC+- zone if no timezone string exists
     3279                $current_offset = get_option( 'gmt_offset' );
     3280                if ( 0 == $current_offset )
     3281                        $tzstring = 'UTC';
     3282                elseif ($current_offset < 0)
     3283                        $tzstring = 'Etc/GMT' . $current_offset;
     3284                else
     3285                        $tzstring = 'Etc/GMT+' . $current_offset;
     3286        }
     3287        $zone = new DateTimeZone( $tzstring );
     3288        return $zone;
     3289}
     3290
     3291/**
    32683292 * gmt_offset modification for smart timezone handling.
    32693293 *
    32703294 * Overrides the gmt_offset option if we have a timezone_string available.