# wpfunnels/3.11.1/includes/wpf-formatting-functions.php

WPFunnels – Funnel Builder for WooCommerce with Checkout &amp; One Click Upsell, version 3.11.1. 71 lines.

- Page: https://pluginprobe.com/plugins/wpfunnels/3.11.1/code/includes/wpf-formatting-functions.php
- Raw: https://pluginprobe.com/plugins/wpfunnels/3.11.1/raw/includes/wpf-formatting-functions.php
- Modified: 2024-09-30T04:26:52+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/wpfunnels/3.11.1/code/includes/wpf-formatting-functions.php#L10-L20`.

```php
<?php


/**
 * Helper to retrieve the timezone string for a site until
 * a WP core method exists.
 *
 * @return false|mixed|string|void
 * @since 3.1.7
 * @see https://github.com/woocommerce/woocommerce/blob/7a7b5137716623a7b8d13658d0a1a71228db9b0a/plugins/woocommerce/includes/wc-formatting-functions.php#L761
 */
function wpf_timezone_string() {
	// Added in WordPress 5.3 Ref https://developer.wordpress.org/reference/functions/wp_timezone_string/.
	if ( function_exists( 'wp_timezone_string' ) ) {
		return wp_timezone_string();
	}

	// If site timezone string exists, return it.
	$timezone = get_option( 'timezone_string' );
	if ( $timezone ) {
		return $timezone;
	}

	// Get UTC offset, if it isn't set then return UTC.
	$utc_offset = floatval( get_option( 'gmt_offset', 0 ) );
	if ( ! is_numeric( $utc_offset ) || 0.0 === $utc_offset ) {
		return 'UTC';
	}

	// Adjust UTC offset from hours to seconds.
	$utc_offset = (int) ( $utc_offset * 3600 );

	// Attempt to guess the timezone string from the UTC offset.
	$timezone = timezone_name_from_abbr( '', $utc_offset );
	if ( $timezone ) {
		return $timezone;
	}

	// Last try, guess timezone string manually.
	foreach ( timezone_abbreviations_list() as $abbr ) {
		foreach ( $abbr as $city ) {
			// WordPress restrict the use of date(), since it's affected by timezone settings, but in this case is just what we need to guess the correct timezone.
			if ( (bool) date( 'I' ) === (bool) $city['dst'] && $city['timezone_id'] && intval( $city['offset'] ) === $utc_offset ) { // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
				return $city['timezone_id'];
			}
		}
	}

	// Fallback to UTC.
	return 'UTC';
}


/**
 * Get timezone offset in seconds.
 *
 * @return float|int
 * @throws Exception
 * @see https://github.com/woocommerce/woocommerce/blob/7a7b5137716623a7b8d13658d0a1a71228db9b0a/plugins/woocommerce/includes/wc-formatting-functions.php#L808
 */
function wpf_timezone_offset() {
	$timezone = get_option( 'timezone_string' );

	if ( $timezone ) {
		$timezone_object = new DateTimeZone( $timezone );
		return $timezone_object->getOffset( new DateTime( 'now' ) );
	} else {
		return floatval( get_option( 'gmt_offset', 0 ) ) * HOUR_IN_SECONDS;
	}
}

```
