1: <?php
2: /**
3: * WordPress core functions for keeping compatibility.
4: *
5: * @package EPL
6: * @subpackage Compatibility/Shortcodes
7: * @copyright Copyright (c) 2016, Merv Barrett
8: * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9: * @since 2.1.11
10: */
11:
12: // Exit if accessed directly.
13: if ( ! defined( 'ABSPATH' ) ) {
14: exit;
15: }
16:
17: if ( ! function_exists( 'shortcode_exists' ) ) {
18: /**
19: * Whether a registered shortcode exists named $tag
20: *
21: * @since 2.1.11
22: *
23: * @global array $shortcode_tags List of shortcode tags and their callback hooks.
24: *
25: * @param string $tag Shortcode tag to check.
26: * @return bool Whether the given shortcode exists.
27: */
28: function shortcode_exists( $tag ) {
29: global $shortcode_tags;
30: return array_key_exists( $tag, $shortcode_tags );
31: }
32: }
33:
34: if ( ! function_exists( 'wp_timezone_string' ) ) {
35: /**
36: * Retrieves the timezone of the site as a string.
37: *
38: * Uses the `timezone_string` option to get a proper timezone name if available,
39: * otherwise falls back to a manual UTC ± offset.
40: *
41: * Example return values:
42: *
43: * - 'Europe/Rome'
44: * - 'America/North_Dakota/New_Salem'
45: * - 'UTC'
46: * - '-06:30'
47: * - '+00:00'
48: * - '+08:45'
49: *
50: * @since 3.5.7 Added as this function is not present before WordPress 5.3.0
51: *
52: * @return string PHP timezone name or a ±HH:MM offset.
53: */
54: function wp_timezone_string() {
55: $timezone_string = get_option( 'timezone_string' );
56:
57: if ( $timezone_string ) {
58: return $timezone_string;
59: }
60:
61: $offset = (float) get_option( 'gmt_offset' );
62: $hours = (int) $offset;
63: $minutes = ( $offset - $hours );
64:
65: $sign = ( $offset < 0 ) ? '-' : '+';
66: $abs_hour = abs( $hours );
67: $abs_mins = abs( $minutes * 60 );
68: $tz_offset = sprintf( '%s%02d:%02d', $sign, $abs_hour, $abs_mins );
69:
70: return $tz_offset;
71: }
72: }
73:
74: if ( ! function_exists( 'wp_timezone' ) ) {
75: /**
76: * Retrieves the timezone of the site as a `DateTimeZone` object.
77: *
78: * Timezone can be based on a PHP timezone string or a ±HH:MM offset.
79: *
80: * @since 3.5.7 Added as this function is not present before WordPress 5.3.0
81: *
82: * @return DateTimeZone Timezone object.
83: */
84: function wp_timezone() {
85: return new DateTimeZone( wp_timezone_string() );
86: }
87: }
88:
89: if ( ! function_exists( 'current_datetime' ) ) {
90: /**
91: * Retrieves the current time as an object using the site's timezone.
92: *
93: * @since 3.5.7 Added as this function is not present before WordPress 5.3.0
94: *
95: * @return DateTimeImmutable Date and time object.
96: */
97: function current_datetime() {
98: return new DateTimeImmutable( 'now', wp_timezone() );
99: }
100: }
101:
102: if ( ! function_exists( 'epl_array_replace_recursive' ) ) {
103: /**
104: * EPL Array Replace Recursive
105: *
106: * @param array $data The array in which elements are replaced.
107: * @param array $array1 The array from which elements will be extracted.
108: * @return array Returns an array.
109: */
110: function epl_array_replace_recursive( $data, $array1 ) {
111: if ( function_exists( 'array_replace_recursive' ) ) {
112: return call_user_func_array( 'array_replace_recursive', func_get_args() );
113: }
114:
115: // Handle infinite arguments.
116: $args = func_get_args();
117: $data = array_shift( $args );
118:
119: if ( ! is_array( $data ) ) {
120: return $data;
121: }
122:
123: if ( ! empty( $args ) ) {
124: foreach ( $args as $array1 ) {
125: if ( ! is_array( $array1 ) ) {
126: continue;
127: }
128: foreach ( $array1 as $key => $value ) {
129: if ( is_array( $value ) && isset( $data[ $key ] ) && is_array( $data[ $key ] ) ) {
130: $data[ $key ] = epl_array_replace_recursive( $data[ $key ], $value );
131: } else {
132: $data[ $key ] = $value;
133: }
134: }
135: }
136: }
137: return $data;
138: }
139: }
140: