Getting wp_timezone undefined within a namespace

Question

My workaround at the moment, within a shortcode, is to just copy the WP native code to get the Timezone within my (namespaced) class:

new DateTimeZone( $this->wp_timezone_string() ));
private function wp_timezone_string() {
    $timezone_string = get_option( 'timezone_string' );

    if ( $timezone_string ) {
        return $timezone_string;
    }

    $offset  = (float) get_option( 'gmt_offset' );
    $hours   = (int) $offset;
    $minutes = ( $offset - $hours );

    $sign      = ( $offset < 0 ) ? '-' : '+';
    $abs_hour  = abs( $hours );
    $abs_mins  = abs( $minutes * 60 );
    $tz_offset = sprintf( '%s%02d:%02d', $sign, $abs_hour, $abs_mins );

    return $tz_offset;
}

But I’m wondering why I can’t just call make a call to wp_timezone() (escaped for namespace).

Is it because the file that contains that class hasn’t loaded yet?

0
MikeiLL 4 months 0 Answers 11 views 0

Leave an answer