|
5 | 5 | * @package Simple_Location |
6 | 6 | */ |
7 | 7 |
|
8 | | -if ( ! function_exists( 'current_datetime' ) ) { |
9 | | - /** |
10 | | - * Retrieves the current time as an object with the timezone from settings. |
11 | | - * |
12 | | - * @since 5.3.0 - Backported to Simple Location and DateTime used for pre PHP 5.5 compatibility for new |
13 | | - * |
14 | | - * @return DateTimeImmutable Date and time object. |
15 | | - */ |
16 | | - function current_datetime() { |
17 | | - return new DateTimeImmutable( 'now', wp_timezone() ); |
18 | | - } |
19 | | -} |
20 | | - |
21 | | -if ( ! function_exists( 'get_post_timestamp' ) ) { |
22 | | - /** |
23 | | - * Retrieve post published or modified time as a Unix timestamp. |
24 | | - * |
25 | | - * Note that this function returns a true Unix timestamp, not summed with timezone offset |
26 | | - * like older WP functions. |
27 | | - * |
28 | | - * @since 5.3.0 - backported to Simple Location |
29 | | - * |
30 | | - * @param int|WP_Post $post Optional. WP_Post object or ID. Default is global `$post` object. |
31 | | - * @param string $field Optional. Post field to use. Accepts 'date' or 'modified'. |
32 | | - * @return int|false Unix timestamp on success, false on failure. |
33 | | - */ |
34 | | - function get_post_timestamp( $post = null, $field = 'date' ) { |
35 | | - $datetime = get_post_datetime( $post, $field ); |
36 | | - if ( false === $datetime ) { |
37 | | - return false; |
38 | | - } |
39 | | - return $datetime->getTimestamp(); |
40 | | - } |
41 | | -} |
42 | | - |
43 | | - |
44 | | -if ( ! function_exists( 'get_post_datetime' ) ) { |
45 | | - /** |
46 | | - * Retrieve post published or modified time as a `DateTimeImmutable` object instance. |
47 | | - * |
48 | | - * The object will be set to the timezone from WordPress settings. |
49 | | - * |
50 | | - * @since 5.3.0 - backported to Simple Location |
51 | | - * |
52 | | - * @param int|WP_Post $post Optional. WP_Post object or ID. Default is global `$post` object. |
53 | | - * @param string $field Optional. Post field to use. Accepts 'date' or 'modified'. |
54 | | - * @return DateTimeImmutable|false Time object on success, false on failure. |
55 | | - */ |
56 | | - function get_post_datetime( $post = null, $field = 'date' ) { |
57 | | - $post = get_post( $post ); |
58 | | - if ( ! $post ) { |
59 | | - return false; |
60 | | - } |
61 | | - $time = ( 'modified' === $field ) ? $post->post_modified : $post->post_date; |
62 | | - if ( empty( $time ) || '0000-00-00 00:00:00' === $time ) { |
63 | | - return false; |
64 | | - } |
65 | | - return date_create_immutable_from_format( 'Y-m-d H:i:s', $time, wp_timezone() ); |
66 | | - } |
67 | | -} |
68 | | - |
69 | 8 | if ( ! function_exists( 'get_comment_datetime' ) ) { |
70 | 9 | /** |
71 | 10 | * Retrieve comment published time as a `DateTimeImmutable` object instance. |
@@ -111,147 +50,6 @@ function get_comment_timestamp( $comment = null ) { |
111 | 50 | } |
112 | 51 | } |
113 | 52 |
|
114 | | - |
115 | | - |
116 | | -if ( ! function_exists( 'wp_timezone_string' ) ) { |
117 | | - /** |
118 | | - * Retrieves the timezone from site settings as a string. |
119 | | - * |
120 | | - * Uses the `timezone_string` option to get a proper timezone if available, |
121 | | - * otherwise falls back to an offset. |
122 | | - * |
123 | | - * @since 5.3.0 - backported into Simple Location |
124 | | - * |
125 | | - * @return string PHP timezone string or a ±HH:MM offset. |
126 | | - */ |
127 | | - function wp_timezone_string() { |
128 | | - $timezone_string = get_option( 'timezone_string' ); |
129 | | - if ( $timezone_string ) { |
130 | | - return $timezone_string; |
131 | | - } |
132 | | - $offset = (float) get_option( 'gmt_offset' ); |
133 | | - $hours = (int) $offset; |
134 | | - $minutes = ( $offset - $hours ); |
135 | | - $sign = ( $offset < 0 ) ? '-' : '+'; |
136 | | - $abs_hour = abs( $hours ); |
137 | | - $abs_mins = abs( $minutes * 60 ); |
138 | | - $tz_offset = sprintf( '%s%02d:%02d', $sign, $abs_hour, $abs_mins ); |
139 | | - return $tz_offset; |
140 | | - } |
141 | | -} |
142 | | - |
143 | | -if ( ! function_exists( 'wp_timezone' ) ) { |
144 | | - /** |
145 | | - * Retrieves the timezone from site settings as a `DateTimeZone` object. |
146 | | - * |
147 | | - * Timezone can be based on a PHP timezone string or a ±HH:MM offset. |
148 | | - * |
149 | | - * @since 5.3.0 - backported into Simple Location |
150 | | - * |
151 | | - * @return DateTimeZone Timezone object. |
152 | | - */ |
153 | | - function wp_timezone() { |
154 | | - return new DateTimeZone( wp_timezone_string() ); |
155 | | - } |
156 | | -} |
157 | | - |
158 | | - |
159 | | -if ( ! function_exists( 'wp_date' ) ) { |
160 | | - /** |
161 | | - * Retrieves the date, in localized format. |
162 | | - * |
163 | | - * This is a newer function, intended to replace `date_i18n()` without legacy quirks in it. |
164 | | - * |
165 | | - * Note that, unlike `date_i18n()`, this function accepts a true Unix timestamp, not summed |
166 | | - * with timezone offset. |
167 | | - * |
168 | | - * @since 5.3.0 - backported to Simple Location |
169 | | - * |
170 | | - * @param string $format PHP date format. |
171 | | - * @param int $timestamp Optional. Unix timestamp. Defaults to current time. |
172 | | - * @param DateTimeZone $timezone Optional. Timezone to output result in. Defaults to timezone |
173 | | - * from site settings. |
174 | | - * @return string|false The date, translated if locale specifies it. False on invalid timestamp input. |
175 | | - */ |
176 | | - function wp_date( $format, $timestamp = null, $timezone = null ) { |
177 | | - global $wp_locale; |
178 | | - if ( null === $timestamp ) { |
179 | | - $timestamp = time(); |
180 | | - } elseif ( ! is_numeric( $timestamp ) ) { |
181 | | - return false; |
182 | | - } |
183 | | - if ( ! $timezone ) { |
184 | | - $timezone = wp_timezone(); |
185 | | - } |
186 | | - $datetime = date_create( '@' . $timestamp ); |
187 | | - $datetime->setTimezone( $timezone ); |
188 | | - if ( empty( $wp_locale->month ) || empty( $wp_locale->weekday ) ) { |
189 | | - $date = $datetime->format( $format ); |
190 | | - } else { |
191 | | - // We need to unpack shorthand `r` format because it has parts that might be localized. |
192 | | - $format = preg_replace( '/(?<!\\\\)r/', DATE_RFC2822, $format ); |
193 | | - $new_format = ''; |
194 | | - $format_length = strlen( $format ); |
195 | | - $month = $wp_locale->get_month( $datetime->format( 'm' ) ); |
196 | | - $weekday = $wp_locale->get_weekday( $datetime->format( 'w' ) ); |
197 | | - for ( $i = 0; $i < $format_length; $i++ ) { |
198 | | - switch ( $format[ $i ] ) { |
199 | | - case 'D': |
200 | | - $new_format .= backslashit( $wp_locale->get_weekday_abbrev( $weekday ) ); |
201 | | - break; |
202 | | - case 'F': |
203 | | - $new_format .= backslashit( $month ); |
204 | | - break; |
205 | | - case 'l': |
206 | | - $new_format .= backslashit( $weekday ); |
207 | | - break; |
208 | | - case 'M': |
209 | | - $new_format .= backslashit( $wp_locale->get_month_abbrev( $month ) ); |
210 | | - break; |
211 | | - case 'a': |
212 | | - $new_format .= backslashit( $wp_locale->get_meridiem( $datetime->format( 'a' ) ) ); |
213 | | - break; |
214 | | - case 'A': |
215 | | - $new_format .= backslashit( $wp_locale->get_meridiem( $datetime->format( 'A' ) ) ); |
216 | | - break; |
217 | | - case '\\': |
218 | | - $new_format .= $format[ $i ]; |
219 | | - // If character follows a slash, we add it without translating. |
220 | | - if ( $i < $format_length ) { |
221 | | - $new_format .= $format[ ++$i ]; |
222 | | - } |
223 | | - break; |
224 | | - default: |
225 | | - $new_format .= $format[ $i ]; |
226 | | - break; |
227 | | - } |
228 | | - } |
229 | | - $date = $datetime->format( $new_format ); |
230 | | - $date = wp_maybe_decline_date( $date ); |
231 | | - } |
232 | | - /** |
233 | | - * Filters the date formatted based on the locale. |
234 | | - * |
235 | | - * @since 5.3.0 but backported to Simple Location |
236 | | - * |
237 | | - * @param string $date Formatted date string. |
238 | | - * @param string $format Format to display the date. |
239 | | - * @param int $timestamp Unix timestamp. |
240 | | - * @param DateTimeZone $timezone Timezone. |
241 | | - */ |
242 | | - $date = apply_filters( 'wp_date', $date, $format, $timestamp, $timezone ); |
243 | | - return $date; |
244 | | - } |
245 | | -} |
246 | | - |
247 | | -if ( ! function_exists( 'array_key_last' ) ) { |
248 | | - function array_key_last( array $array ) { |
249 | | - if ( ! empty( $array ) ) { |
250 | | - return key( array_slice( $array, -1, 1, true ) ); |
251 | | - } |
252 | | - } |
253 | | -} |
254 | | - |
255 | 53 | if ( ! function_exists( 'array_key_last_index' ) ) { |
256 | 54 | function array_key_last_index( array $array, $index = -1 ) { |
257 | 55 | if ( ! empty( $array ) ) { |
|
0 commit comments