| author | ymh <ymh.work@gmail.com> |
| Fri, 05 Sep 2025 18:40:08 +0200 | |
| changeset 21 | 48c4eec2b7e6 |
| parent 19 | 3d72ae0968f4 |
| child 22 | 8c2e4d02f4ef |
| permissions | -rw-r--r-- |
| 0 | 1 |
<?php |
2 |
/** |
|
3 |
* Main WordPress API |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
*/ |
|
7 |
||
| 16 | 8 |
require ABSPATH . WPINC . '/option.php'; |
9 |
||
10 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
11 |
* Converts given MySQL date string into a different format. |
| 16 | 12 |
* |
| 19 | 13 |
* - `$format` should be a PHP date format string. |
14 |
* - 'U' and 'G' formats will return an integer sum of timestamp with timezone offset. |
|
15 |
* - `$date` is expected to be local time in MySQL format (`Y-m-d H:i:s`). |
|
| 16 | 16 |
* |
17 |
* Historically UTC time could be passed to the function to produce Unix timestamp. |
|
18 |
* |
|
19 |
* If `$translate` is true then the given date and format string will |
|
20 |
* be passed to `wp_date()` for translation. |
|
| 0 | 21 |
* |
22 |
* @since 0.71 |
|
23 |
* |
|
| 5 | 24 |
* @param string $format Format of the date to return. |
25 |
* @param string $date Date string to convert. |
|
26 |
* @param bool $translate Whether the return date should be translated. Default true. |
|
| 19 | 27 |
* @return string|int|false Integer if `$format` is 'U' or 'G', string otherwise. |
| 16 | 28 |
* False on failure. |
| 0 | 29 |
*/ |
30 |
function mysql2date( $format, $date, $translate = true ) {
|
|
| 9 | 31 |
if ( empty( $date ) ) {
|
| 0 | 32 |
return false; |
| 9 | 33 |
} |
34 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
35 |
$timezone = wp_timezone(); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
36 |
$datetime = date_create( $date, $timezone ); |
| 16 | 37 |
|
38 |
if ( false === $datetime ) {
|
|
39 |
return false; |
|
40 |
} |
|
41 |
||
42 |
// Returns a sum of timestamp with timezone offset. Ideally should never be used. |
|
43 |
if ( 'G' === $format || 'U' === $format ) {
|
|
44 |
return $datetime->getTimestamp() + $datetime->getOffset(); |
|
| 9 | 45 |
} |
46 |
||
47 |
if ( $translate ) {
|
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
48 |
return wp_date( $format, $datetime->getTimestamp(), $timezone ); |
| 16 | 49 |
} |
50 |
||
51 |
return $datetime->format( $format ); |
|
52 |
} |
|
53 |
||
54 |
/** |
|
55 |
* Retrieves the current time based on specified type. |
|
| 0 | 56 |
* |
| 19 | 57 |
* - The 'mysql' type will return the time in the format for MySQL DATETIME field. |
58 |
* - The 'timestamp' or 'U' types will return the current timestamp or a sum of timestamp |
|
59 |
* and timezone offset, depending on `$gmt`. |
|
60 |
* - Other strings will be interpreted as PHP date formats (e.g. 'Y-m-d'). |
|
61 |
* |
|
62 |
* If `$gmt` is a truthy value then both types will use GMT time, otherwise the |
|
63 |
* output is adjusted with the GMT offset for the site. |
|
| 0 | 64 |
* |
65 |
* @since 1.0.0 |
|
| 19 | 66 |
* @since 5.3.0 Now returns an integer if `$type` is 'U'. Previously a string was returned. |
67 |
* |
|
68 |
* @param string $type Type of time to retrieve. Accepts 'mysql', 'timestamp', 'U', |
|
| 16 | 69 |
* or PHP date format string (e.g. 'Y-m-d'). |
| 5 | 70 |
* @param int|bool $gmt Optional. Whether to use GMT timezone. Default false. |
| 19 | 71 |
* @return int|string Integer if `$type` is 'timestamp' or 'U', string otherwise. |
| 0 | 72 |
*/ |
73 |
function current_time( $type, $gmt = 0 ) {
|
|
| 16 | 74 |
// Don't use non-GMT timestamp, unless you know the difference and really need to. |
75 |
if ( 'timestamp' === $type || 'U' === $type ) {
|
|
76 |
return $gmt ? time() : time() + (int) ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); |
|
77 |
} |
|
78 |
||
79 |
if ( 'mysql' === $type ) {
|
|
80 |
$type = 'Y-m-d H:i:s'; |
|
81 |
} |
|
82 |
||
83 |
$timezone = $gmt ? new DateTimeZone( 'UTC' ) : wp_timezone(); |
|
84 |
$datetime = new DateTime( 'now', $timezone ); |
|
85 |
||
86 |
return $datetime->format( $type ); |
|
87 |
} |
|
88 |
||
89 |
/** |
|
| 19 | 90 |
* Retrieves the current time as an object using the site's timezone. |
| 16 | 91 |
* |
92 |
* @since 5.3.0 |
|
93 |
* |
|
94 |
* @return DateTimeImmutable Date and time object. |
|
95 |
*/ |
|
96 |
function current_datetime() {
|
|
97 |
return new DateTimeImmutable( 'now', wp_timezone() ); |
|
98 |
} |
|
99 |
||
100 |
/** |
|
| 19 | 101 |
* Retrieves the timezone of the site as a string. |
102 |
* |
|
103 |
* Uses the `timezone_string` option to get a proper timezone name if available, |
|
104 |
* otherwise falls back to a manual UTC ± offset. |
|
105 |
* |
|
106 |
* Example return values: |
|
107 |
* |
|
108 |
* - 'Europe/Rome' |
|
109 |
* - 'America/North_Dakota/New_Salem' |
|
110 |
* - 'UTC' |
|
111 |
* - '-06:30' |
|
112 |
* - '+00:00' |
|
113 |
* - '+08:45' |
|
| 16 | 114 |
* |
115 |
* @since 5.3.0 |
|
116 |
* |
|
| 19 | 117 |
* @return string PHP timezone name or a ±HH:MM offset. |
| 16 | 118 |
*/ |
119 |
function wp_timezone_string() {
|
|
120 |
$timezone_string = get_option( 'timezone_string' ); |
|
121 |
||
122 |
if ( $timezone_string ) {
|
|
123 |
return $timezone_string; |
|
124 |
} |
|
125 |
||
126 |
$offset = (float) get_option( 'gmt_offset' ); |
|
127 |
$hours = (int) $offset; |
|
128 |
$minutes = ( $offset - $hours ); |
|
129 |
||
130 |
$sign = ( $offset < 0 ) ? '-' : '+'; |
|
131 |
$abs_hour = abs( $hours ); |
|
132 |
$abs_mins = abs( $minutes * 60 ); |
|
133 |
$tz_offset = sprintf( '%s%02d:%02d', $sign, $abs_hour, $abs_mins ); |
|
134 |
||
135 |
return $tz_offset; |
|
136 |
} |
|
137 |
||
138 |
/** |
|
| 19 | 139 |
* Retrieves the timezone of the site as a `DateTimeZone` object. |
| 16 | 140 |
* |
141 |
* Timezone can be based on a PHP timezone string or a ±HH:MM offset. |
|
142 |
* |
|
143 |
* @since 5.3.0 |
|
144 |
* |
|
145 |
* @return DateTimeZone Timezone object. |
|
146 |
*/ |
|
147 |
function wp_timezone() {
|
|
148 |
return new DateTimeZone( wp_timezone_string() ); |
|
149 |
} |
|
150 |
||
151 |
/** |
|
152 |
* Retrieves the date in localized format, based on a sum of Unix timestamp and |
|
| 9 | 153 |
* timezone offset in seconds. |
| 0 | 154 |
* |
155 |
* If the locale specifies the locale month and weekday, then the locale will |
|
156 |
* take over the format for the date. If it isn't, then the date format string |
|
157 |
* will be used instead. |
|
158 |
* |
|
| 16 | 159 |
* Note that due to the way WP typically generates a sum of timestamp and offset |
160 |
* with `strtotime()`, it implies offset added at a _current_ time, not at the time |
|
161 |
* the timestamp represents. Storing such timestamps or calculating them differently |
|
162 |
* will lead to invalid output. |
|
163 |
* |
|
| 0 | 164 |
* @since 0.71 |
| 16 | 165 |
* @since 5.3.0 Converted into a wrapper for wp_date(). |
166 |
* |
|
167 |
* @param string $format Format to display the date. |
|
168 |
* @param int|bool $timestamp_with_offset Optional. A sum of Unix timestamp and timezone offset |
|
169 |
* in seconds. Default false. |
|
170 |
* @param bool $gmt Optional. Whether to use GMT timezone. Only applies |
|
171 |
* if timestamp is not provided. Default false. |
|
| 0 | 172 |
* @return string The date, translated if locale specifies it. |
173 |
*/ |
|
| 16 | 174 |
function date_i18n( $format, $timestamp_with_offset = false, $gmt = false ) {
|
175 |
$timestamp = $timestamp_with_offset; |
|
176 |
||
177 |
// If timestamp is omitted it should be current time (summed with offset, unless `$gmt` is true). |
|
178 |
if ( ! is_numeric( $timestamp ) ) {
|
|
| 19 | 179 |
// phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested |
| 16 | 180 |
$timestamp = current_time( 'timestamp', $gmt ); |
| 0 | 181 |
} |
182 |
||
| 5 | 183 |
/* |
| 16 | 184 |
* This is a legacy implementation quirk that the returned timestamp is also with offset. |
185 |
* Ideally this function should never be used to produce a timestamp. |
|
| 5 | 186 |
*/ |
| 16 | 187 |
if ( 'U' === $format ) {
|
188 |
$date = $timestamp; |
|
189 |
} elseif ( $gmt && false === $timestamp_with_offset ) { // Current time in UTC.
|
|
190 |
$date = wp_date( $format, null, new DateTimeZone( 'UTC' ) ); |
|
191 |
} elseif ( false === $timestamp_with_offset ) { // Current time in site's timezone.
|
|
192 |
$date = wp_date( $format ); |
|
193 |
} else {
|
|
194 |
/* |
|
195 |
* Timestamp with offset is typically produced by a UTC `strtotime()` call on an input without timezone. |
|
196 |
* This is the best attempt to reverse that operation into a local time to use. |
|
197 |
*/ |
|
198 |
$local_time = gmdate( 'Y-m-d H:i:s', $timestamp ); |
|
199 |
$timezone = wp_timezone(); |
|
200 |
$datetime = date_create( $local_time, $timezone ); |
|
201 |
$date = wp_date( $format, $datetime->getTimestamp(), $timezone ); |
|
202 |
} |
|
| 5 | 203 |
|
204 |
/** |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
205 |
* Filters the date formatted based on the locale. |
| 5 | 206 |
* |
207 |
* @since 2.8.0 |
|
208 |
* |
|
| 16 | 209 |
* @param string $date Formatted date string. |
210 |
* @param string $format Format to display the date. |
|
211 |
* @param int $timestamp A sum of Unix timestamp and timezone offset in seconds. |
|
212 |
* Might be without offset if input omitted timestamp but requested GMT. |
|
213 |
* @param bool $gmt Whether to use GMT timezone. Only applies if timestamp was not provided. |
|
214 |
* Default false. |
|
| 5 | 215 |
*/ |
| 16 | 216 |
$date = apply_filters( 'date_i18n', $date, $format, $timestamp, $gmt ); |
217 |
||
218 |
return $date; |
|
219 |
} |
|
220 |
||
221 |
/** |
|
222 |
* Retrieves the date, in localized format. |
|
223 |
* |
|
224 |
* This is a newer function, intended to replace `date_i18n()` without legacy quirks in it. |
|
225 |
* |
|
226 |
* Note that, unlike `date_i18n()`, this function accepts a true Unix timestamp, not summed |
|
227 |
* with timezone offset. |
|
228 |
* |
|
229 |
* @since 5.3.0 |
|
230 |
* |
|
| 19 | 231 |
* @global WP_Locale $wp_locale WordPress date and time locale object. |
232 |
* |
|
| 16 | 233 |
* @param string $format PHP date format. |
234 |
* @param int $timestamp Optional. Unix timestamp. Defaults to current time. |
|
235 |
* @param DateTimeZone $timezone Optional. Timezone to output result in. Defaults to timezone |
|
236 |
* from site settings. |
|
237 |
* @return string|false The date, translated if locale specifies it. False on invalid timestamp input. |
|
238 |
*/ |
|
239 |
function wp_date( $format, $timestamp = null, $timezone = null ) {
|
|
240 |
global $wp_locale; |
|
241 |
||
242 |
if ( null === $timestamp ) {
|
|
243 |
$timestamp = time(); |
|
244 |
} elseif ( ! is_numeric( $timestamp ) ) {
|
|
245 |
return false; |
|
246 |
} |
|
247 |
||
248 |
if ( ! $timezone ) {
|
|
249 |
$timezone = wp_timezone(); |
|
250 |
} |
|
251 |
||
252 |
$datetime = date_create( '@' . $timestamp ); |
|
253 |
$datetime->setTimezone( $timezone ); |
|
254 |
||
255 |
if ( empty( $wp_locale->month ) || empty( $wp_locale->weekday ) ) {
|
|
256 |
$date = $datetime->format( $format ); |
|
257 |
} else {
|
|
258 |
// We need to unpack shorthand `r` format because it has parts that might be localized. |
|
259 |
$format = preg_replace( '/(?<!\\\\)r/', DATE_RFC2822, $format ); |
|
260 |
||
261 |
$new_format = ''; |
|
262 |
$format_length = strlen( $format ); |
|
263 |
$month = $wp_locale->get_month( $datetime->format( 'm' ) ); |
|
264 |
$weekday = $wp_locale->get_weekday( $datetime->format( 'w' ) ); |
|
265 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
266 |
for ( $i = 0; $i < $format_length; $i++ ) {
|
| 16 | 267 |
switch ( $format[ $i ] ) {
|
268 |
case 'D': |
|
269 |
$new_format .= addcslashes( $wp_locale->get_weekday_abbrev( $weekday ), '\\A..Za..z' ); |
|
270 |
break; |
|
271 |
case 'F': |
|
272 |
$new_format .= addcslashes( $month, '\\A..Za..z' ); |
|
273 |
break; |
|
274 |
case 'l': |
|
275 |
$new_format .= addcslashes( $weekday, '\\A..Za..z' ); |
|
276 |
break; |
|
277 |
case 'M': |
|
278 |
$new_format .= addcslashes( $wp_locale->get_month_abbrev( $month ), '\\A..Za..z' ); |
|
279 |
break; |
|
280 |
case 'a': |
|
281 |
$new_format .= addcslashes( $wp_locale->get_meridiem( $datetime->format( 'a' ) ), '\\A..Za..z' ); |
|
282 |
break; |
|
283 |
case 'A': |
|
284 |
$new_format .= addcslashes( $wp_locale->get_meridiem( $datetime->format( 'A' ) ), '\\A..Za..z' ); |
|
285 |
break; |
|
286 |
case '\\': |
|
287 |
$new_format .= $format[ $i ]; |
|
288 |
||
289 |
// If character follows a slash, we add it without translating. |
|
290 |
if ( $i < $format_length ) {
|
|
291 |
$new_format .= $format[ ++$i ]; |
|
292 |
} |
|
293 |
break; |
|
294 |
default: |
|
295 |
$new_format .= $format[ $i ]; |
|
296 |
break; |
|
297 |
} |
|
298 |
} |
|
299 |
||
300 |
$date = $datetime->format( $new_format ); |
|
301 |
$date = wp_maybe_decline_date( $date, $format ); |
|
302 |
} |
|
303 |
||
304 |
/** |
|
305 |
* Filters the date formatted based on the locale. |
|
306 |
* |
|
307 |
* @since 5.3.0 |
|
308 |
* |
|
309 |
* @param string $date Formatted date string. |
|
310 |
* @param string $format Format to display the date. |
|
311 |
* @param int $timestamp Unix timestamp. |
|
312 |
* @param DateTimeZone $timezone Timezone. |
|
313 |
*/ |
|
314 |
$date = apply_filters( 'wp_date', $date, $format, $timestamp, $timezone ); |
|
315 |
||
316 |
return $date; |
|
| 0 | 317 |
} |
318 |
||
319 |
/** |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
320 |
* Determines if the date should be declined. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
321 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
322 |
* If the locale specifies that month names require a genitive case in certain |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
323 |
* formats (like 'j F Y'), the month name will be replaced with a correct form. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
324 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
325 |
* @since 4.4.0 |
| 16 | 326 |
* @since 5.4.0 The `$format` parameter was added. |
327 |
* |
|
328 |
* @global WP_Locale $wp_locale WordPress date and time locale object. |
|
329 |
* |
|
330 |
* @param string $date Formatted date string. |
|
331 |
* @param string $format Optional. Date format to check. Default empty string. |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
332 |
* @return string The date, declined if locale specifies it. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
333 |
*/ |
| 16 | 334 |
function wp_maybe_decline_date( $date, $format = '' ) {
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
335 |
global $wp_locale; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
336 |
|
| 16 | 337 |
// i18n functions are not available in SHORTINIT mode. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
338 |
if ( ! function_exists( '_x' ) ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
339 |
return $date; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
340 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
341 |
|
| 16 | 342 |
/* |
343 |
* translators: If months in your language require a genitive case, |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
344 |
* translate this to 'on'. Do not translate into your own language. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
345 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
346 |
if ( 'on' === _x( 'off', 'decline months names: on or off' ) ) {
|
| 16 | 347 |
|
348 |
$months = $wp_locale->month; |
|
349 |
$months_genitive = $wp_locale->month_genitive; |
|
350 |
||
351 |
/* |
|
352 |
* Match a format like 'j F Y' or 'j. F' (day of the month, followed by month name) |
|
353 |
* and decline the month. |
|
354 |
*/ |
|
355 |
if ( $format ) {
|
|
356 |
$decline = preg_match( '#[dj]\.? F#', $format ); |
|
357 |
} else {
|
|
358 |
// If the format is not passed, try to guess it from the date string. |
|
359 |
$decline = preg_match( '#\b\d{1,2}\.? [^\d ]+\b#u', $date );
|
|
360 |
} |
|
361 |
||
362 |
if ( $decline ) {
|
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
363 |
foreach ( $months as $key => $month ) {
|
| 16 | 364 |
$months[ $key ] = '# ' . preg_quote( $month, '#' ) . '\b#u'; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
365 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
366 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
367 |
foreach ( $months_genitive as $key => $month ) {
|
| 16 | 368 |
$months_genitive[ $key ] = ' ' . $month; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
369 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
370 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
371 |
$date = preg_replace( $months, $months_genitive, $date ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
372 |
} |
| 16 | 373 |
|
374 |
/* |
|
375 |
* Match a format like 'F jS' or 'F j' (month name, followed by day with an optional ordinal suffix) |
|
376 |
* and change it to declined 'j F'. |
|
377 |
*/ |
|
378 |
if ( $format ) {
|
|
379 |
$decline = preg_match( '#F [dj]#', $format ); |
|
380 |
} else {
|
|
381 |
// If the format is not passed, try to guess it from the date string. |
|
382 |
$decline = preg_match( '#\b[^\d ]+ \d{1,2}(st|nd|rd|th)?\b#u', trim( $date ) );
|
|
383 |
} |
|
384 |
||
385 |
if ( $decline ) {
|
|
386 |
foreach ( $months as $key => $month ) {
|
|
387 |
$months[ $key ] = '#\b' . preg_quote( $month, '#' ) . ' (\d{1,2})(st|nd|rd|th)?([-–]\d{1,2})?(st|nd|rd|th)?\b#u';
|
|
388 |
} |
|
389 |
||
390 |
foreach ( $months_genitive as $key => $month ) {
|
|
391 |
$months_genitive[ $key ] = '$1$3 ' . $month; |
|
392 |
} |
|
393 |
||
394 |
$date = preg_replace( $months, $months_genitive, $date ); |
|
395 |
} |
|
396 |
} |
|
397 |
||
398 |
// Used for locale-specific rules. |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
399 |
$locale = get_locale(); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
400 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
401 |
if ( 'ca' === $locale ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
402 |
// " de abril| de agost| de octubre..." -> " d'abril| d'agost| d'octubre..." |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
403 |
$date = preg_replace( '# de ([ao])#i', " d'\\1", $date ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
404 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
405 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
406 |
return $date; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
407 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
408 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
409 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
410 |
* Converts float number to format based on the locale. |
| 0 | 411 |
* |
412 |
* @since 2.3.0 |
|
413 |
* |
|
| 16 | 414 |
* @global WP_Locale $wp_locale WordPress date and time locale object. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
415 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
416 |
* @param float $number The number to convert based on locale. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
417 |
* @param int $decimals Optional. Precision of the number of decimal places. Default 0. |
| 0 | 418 |
* @return string Converted number in string format. |
419 |
*/ |
|
420 |
function number_format_i18n( $number, $decimals = 0 ) {
|
|
421 |
global $wp_locale; |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
422 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
423 |
if ( isset( $wp_locale ) ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
424 |
$formatted = number_format( $number, absint( $decimals ), $wp_locale->number_format['decimal_point'], $wp_locale->number_format['thousands_sep'] ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
425 |
} else {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
426 |
$formatted = number_format( $number, absint( $decimals ) ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
427 |
} |
| 5 | 428 |
|
429 |
/** |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
430 |
* Filters the number formatted based on the locale. |
| 5 | 431 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
432 |
* @since 2.8.0 |
| 9 | 433 |
* @since 4.9.0 The `$number` and `$decimals` parameters were added. |
| 5 | 434 |
* |
435 |
* @param string $formatted Converted number in string format. |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
436 |
* @param float $number The number to convert based on locale. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
437 |
* @param int $decimals Precision of the number of decimal places. |
| 5 | 438 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
439 |
return apply_filters( 'number_format_i18n', $formatted, $number, $decimals ); |
| 0 | 440 |
} |
441 |
||
442 |
/** |
|
| 19 | 443 |
* Converts a number of bytes to the largest unit the bytes will fit into. |
| 0 | 444 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
445 |
* It is easier to read 1 KB than 1024 bytes and 1 MB than 1048576 bytes. Converts |
| 0 | 446 |
* number of bytes to human readable number by taking the number of that unit |
| 19 | 447 |
* that the bytes will go into it. Supports YB value. |
| 0 | 448 |
* |
449 |
* Please note that integers in PHP are limited to 32 bits, unless they are on |
|
450 |
* 64 bit architecture, then they have 64 bit size. If you need to place the |
|
451 |
* larger size then what PHP integer type will hold, then use a string. It will |
|
452 |
* be converted to a double, which should always have 64 bit length. |
|
453 |
* |
|
454 |
* Technically the correct unit names for powers of 1024 are KiB, MiB etc. |
|
455 |
* |
|
456 |
* @since 2.3.0 |
|
| 19 | 457 |
* @since 6.0.0 Support for PB, EB, ZB, and YB was added. |
| 0 | 458 |
* |
| 5 | 459 |
* @param int|string $bytes Number of bytes. Note max integer size for integers. |
460 |
* @param int $decimals Optional. Precision of number of decimal places. Default 0. |
|
| 16 | 461 |
* @return string|false Number string on success, false on failure. |
| 0 | 462 |
*/ |
463 |
function size_format( $bytes, $decimals = 0 ) {
|
|
464 |
$quant = array( |
|
| 19 | 465 |
/* translators: Unit symbol for yottabyte. */ |
466 |
_x( 'YB', 'unit symbol' ) => YB_IN_BYTES, |
|
467 |
/* translators: Unit symbol for zettabyte. */ |
|
468 |
_x( 'ZB', 'unit symbol' ) => ZB_IN_BYTES, |
|
469 |
/* translators: Unit symbol for exabyte. */ |
|
470 |
_x( 'EB', 'unit symbol' ) => EB_IN_BYTES, |
|
471 |
/* translators: Unit symbol for petabyte. */ |
|
472 |
_x( 'PB', 'unit symbol' ) => PB_IN_BYTES, |
|
| 16 | 473 |
/* translators: Unit symbol for terabyte. */ |
474 |
_x( 'TB', 'unit symbol' ) => TB_IN_BYTES, |
|
475 |
/* translators: Unit symbol for gigabyte. */ |
|
476 |
_x( 'GB', 'unit symbol' ) => GB_IN_BYTES, |
|
477 |
/* translators: Unit symbol for megabyte. */ |
|
478 |
_x( 'MB', 'unit symbol' ) => MB_IN_BYTES, |
|
479 |
/* translators: Unit symbol for kilobyte. */ |
|
480 |
_x( 'KB', 'unit symbol' ) => KB_IN_BYTES, |
|
481 |
/* translators: Unit symbol for byte. */ |
|
482 |
_x( 'B', 'unit symbol' ) => 1, |
|
| 0 | 483 |
); |
| 5 | 484 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
485 |
if ( 0 === $bytes ) {
|
| 16 | 486 |
/* translators: Unit symbol for byte. */ |
487 |
return number_format_i18n( 0, $decimals ) . ' ' . _x( 'B', 'unit symbol' ); |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
488 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
489 |
|
| 5 | 490 |
foreach ( $quant as $unit => $mag ) {
|
| 18 | 491 |
if ( (float) $bytes >= $mag ) {
|
| 0 | 492 |
return number_format_i18n( $bytes / $mag, $decimals ) . ' ' . $unit; |
| 5 | 493 |
} |
494 |
} |
|
| 0 | 495 |
|
496 |
return false; |
|
497 |
} |
|
498 |
||
499 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
500 |
* Converts a duration to human readable format. |
| 9 | 501 |
* |
502 |
* @since 5.1.0 |
|
503 |
* |
|
504 |
* @param string $duration Duration will be in string format (HH:ii:ss) OR (ii:ss), |
|
505 |
* with a possible prepended negative sign (-). |
|
506 |
* @return string|false A human readable duration string, false on failure. |
|
507 |
*/ |
|
508 |
function human_readable_duration( $duration = '' ) {
|
|
509 |
if ( ( empty( $duration ) || ! is_string( $duration ) ) ) {
|
|
510 |
return false; |
|
511 |
} |
|
512 |
||
513 |
$duration = trim( $duration ); |
|
514 |
||
515 |
// Remove prepended negative sign. |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
516 |
if ( str_starts_with( $duration, '-' ) ) {
|
| 9 | 517 |
$duration = substr( $duration, 1 ); |
518 |
} |
|
519 |
||
520 |
// Extract duration parts. |
|
521 |
$duration_parts = array_reverse( explode( ':', $duration ) ); |
|
522 |
$duration_count = count( $duration_parts ); |
|
523 |
||
524 |
$hour = null; |
|
525 |
$minute = null; |
|
526 |
$second = null; |
|
527 |
||
528 |
if ( 3 === $duration_count ) {
|
|
529 |
// Validate HH:ii:ss duration format. |
|
530 |
if ( ! ( (bool) preg_match( '/^([0-9]+):([0-5]?[0-9]):([0-5]?[0-9])$/', $duration ) ) ) {
|
|
531 |
return false; |
|
532 |
} |
|
533 |
// Three parts: hours, minutes & seconds. |
|
534 |
list( $second, $minute, $hour ) = $duration_parts; |
|
535 |
} elseif ( 2 === $duration_count ) {
|
|
536 |
// Validate ii:ss duration format. |
|
537 |
if ( ! ( (bool) preg_match( '/^([0-5]?[0-9]):([0-5]?[0-9])$/', $duration ) ) ) {
|
|
538 |
return false; |
|
539 |
} |
|
540 |
// Two parts: minutes & seconds. |
|
541 |
list( $second, $minute ) = $duration_parts; |
|
542 |
} else {
|
|
543 |
return false; |
|
544 |
} |
|
545 |
||
546 |
$human_readable_duration = array(); |
|
547 |
||
548 |
// Add the hour part to the string. |
|
549 |
if ( is_numeric( $hour ) ) {
|
|
| 16 | 550 |
/* translators: %s: Time duration in hour or hours. */ |
| 9 | 551 |
$human_readable_duration[] = sprintf( _n( '%s hour', '%s hours', $hour ), (int) $hour ); |
552 |
} |
|
553 |
||
554 |
// Add the minute part to the string. |
|
555 |
if ( is_numeric( $minute ) ) {
|
|
| 16 | 556 |
/* translators: %s: Time duration in minute or minutes. */ |
| 9 | 557 |
$human_readable_duration[] = sprintf( _n( '%s minute', '%s minutes', $minute ), (int) $minute ); |
558 |
} |
|
559 |
||
560 |
// Add the second part to the string. |
|
561 |
if ( is_numeric( $second ) ) {
|
|
| 16 | 562 |
/* translators: %s: Time duration in second or seconds. */ |
| 9 | 563 |
$human_readable_duration[] = sprintf( _n( '%s second', '%s seconds', $second ), (int) $second ); |
564 |
} |
|
565 |
||
566 |
return implode( ', ', $human_readable_duration ); |
|
567 |
} |
|
568 |
||
569 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
570 |
* Gets the week start and end from the datetime or date string from MySQL. |
| 0 | 571 |
* |
572 |
* @since 0.71 |
|
573 |
* |
|
| 5 | 574 |
* @param string $mysqlstring Date or datetime field type from MySQL. |
575 |
* @param int|string $start_of_week Optional. Start of the week as an integer. Default empty string. |
|
| 19 | 576 |
* @return int[] {
|
577 |
* Week start and end dates as Unix timestamps. |
|
578 |
* |
|
579 |
* @type int $start The week start date as a Unix timestamp. |
|
580 |
* @type int $end The week end date as a Unix timestamp. |
|
581 |
* } |
|
| 0 | 582 |
*/ |
583 |
function get_weekstartend( $mysqlstring, $start_of_week = '' ) {
|
|
| 5 | 584 |
// MySQL string year. |
585 |
$my = substr( $mysqlstring, 0, 4 ); |
|
586 |
||
587 |
// MySQL string month. |
|
588 |
$mm = substr( $mysqlstring, 8, 2 ); |
|
589 |
||
590 |
// MySQL string day. |
|
591 |
$md = substr( $mysqlstring, 5, 2 ); |
|
592 |
||
593 |
// The timestamp for MySQL string day. |
|
594 |
$day = mktime( 0, 0, 0, $md, $mm, $my ); |
|
595 |
||
596 |
// The day of the week from the timestamp. |
|
| 16 | 597 |
$weekday = gmdate( 'w', $day ); |
| 5 | 598 |
|
| 9 | 599 |
if ( ! is_numeric( $start_of_week ) ) {
|
| 0 | 600 |
$start_of_week = get_option( 'start_of_week' ); |
| 9 | 601 |
} |
602 |
||
603 |
if ( $weekday < $start_of_week ) {
|
|
| 0 | 604 |
$weekday += 7; |
| 9 | 605 |
} |
| 0 | 606 |
|
| 5 | 607 |
// The most recent week start day on or before $day. |
608 |
$start = $day - DAY_IN_SECONDS * ( $weekday - $start_of_week ); |
|
609 |
||
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
610 |
// $start + 1 week - 1 second. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
611 |
$end = $start + WEEK_IN_SECONDS - 1; |
| 0 | 612 |
return compact( 'start', 'end' ); |
613 |
} |
|
614 |
||
615 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
616 |
* Serializes data, if needed. |
| 16 | 617 |
* |
618 |
* @since 2.0.5 |
|
619 |
* |
|
620 |
* @param string|array|object $data Data that might be serialized. |
|
621 |
* @return mixed A scalar data. |
|
622 |
*/ |
|
623 |
function maybe_serialize( $data ) {
|
|
624 |
if ( is_array( $data ) || is_object( $data ) ) {
|
|
625 |
return serialize( $data ); |
|
626 |
} |
|
627 |
||
628 |
/* |
|
629 |
* Double serialization is required for backward compatibility. |
|
630 |
* See https://core.trac.wordpress.org/ticket/12930 |
|
631 |
* Also the world will end. See WP 3.6.1. |
|
632 |
*/ |
|
633 |
if ( is_serialized( $data, false ) ) {
|
|
634 |
return serialize( $data ); |
|
635 |
} |
|
636 |
||
637 |
return $data; |
|
638 |
} |
|
639 |
||
640 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
641 |
* Unserializes data only if it was serialized. |
| 0 | 642 |
* |
643 |
* @since 2.0.0 |
|
644 |
* |
|
| 16 | 645 |
* @param string $data Data that might be unserialized. |
| 0 | 646 |
* @return mixed Unserialized data can be any type. |
647 |
*/ |
|
| 16 | 648 |
function maybe_unserialize( $data ) {
|
649 |
if ( is_serialized( $data ) ) { // Don't attempt to unserialize data that wasn't serialized going in.
|
|
650 |
return @unserialize( trim( $data ) ); |
|
651 |
} |
|
652 |
||
653 |
return $data; |
|
| 0 | 654 |
} |
655 |
||
656 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
657 |
* Checks value to find if it was serialized. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
658 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
659 |
* If $data is not a string, then returned value will always be false. |
| 0 | 660 |
* Serialized data is always a string. |
661 |
* |
|
662 |
* @since 2.0.5 |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
663 |
* @since 6.1.0 Added Enum support. |
| 0 | 664 |
* |
| 5 | 665 |
* @param string $data Value to check to see if was serialized. |
666 |
* @param bool $strict Optional. Whether to be strict about the end of the string. Default true. |
|
| 0 | 667 |
* @return bool False if not serialized and true if it was. |
668 |
*/ |
|
669 |
function is_serialized( $data, $strict = true ) {
|
|
| 16 | 670 |
// If it isn't a string, it isn't serialized. |
| 5 | 671 |
if ( ! is_string( $data ) ) {
|
| 0 | 672 |
return false; |
| 5 | 673 |
} |
| 0 | 674 |
$data = trim( $data ); |
| 16 | 675 |
if ( 'N;' === $data ) {
|
| 0 | 676 |
return true; |
| 5 | 677 |
} |
678 |
if ( strlen( $data ) < 4 ) {
|
|
| 0 | 679 |
return false; |
| 5 | 680 |
} |
681 |
if ( ':' !== $data[1] ) {
|
|
| 0 | 682 |
return false; |
| 5 | 683 |
} |
| 0 | 684 |
if ( $strict ) {
|
| 5 | 685 |
$lastc = substr( $data, -1 ); |
686 |
if ( ';' !== $lastc && '}' !== $lastc ) {
|
|
| 0 | 687 |
return false; |
| 5 | 688 |
} |
| 0 | 689 |
} else {
|
690 |
$semicolon = strpos( $data, ';' ); |
|
691 |
$brace = strpos( $data, '}' ); |
|
692 |
// Either ; or } must exist. |
|
| 9 | 693 |
if ( false === $semicolon && false === $brace ) {
|
| 0 | 694 |
return false; |
| 9 | 695 |
} |
| 0 | 696 |
// But neither must be in the first X characters. |
| 9 | 697 |
if ( false !== $semicolon && $semicolon < 3 ) {
|
| 0 | 698 |
return false; |
| 9 | 699 |
} |
700 |
if ( false !== $brace && $brace < 4 ) {
|
|
| 0 | 701 |
return false; |
| 9 | 702 |
} |
| 0 | 703 |
} |
704 |
$token = $data[0]; |
|
705 |
switch ( $token ) {
|
|
| 9 | 706 |
case 's': |
| 0 | 707 |
if ( $strict ) {
|
| 5 | 708 |
if ( '"' !== substr( $data, -2, 1 ) ) {
|
| 0 | 709 |
return false; |
| 5 | 710 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
711 |
} elseif ( ! str_contains( $data, '"' ) ) {
|
| 0 | 712 |
return false; |
713 |
} |
|
| 16 | 714 |
// Or else fall through. |
| 9 | 715 |
case 'a': |
716 |
case 'O': |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
717 |
case 'E': |
| 0 | 718 |
return (bool) preg_match( "/^{$token}:[0-9]+:/s", $data );
|
| 9 | 719 |
case 'b': |
720 |
case 'i': |
|
721 |
case 'd': |
|
| 0 | 722 |
$end = $strict ? '$' : ''; |
| 16 | 723 |
return (bool) preg_match( "/^{$token}:[0-9.E+-]+;$end/", $data );
|
| 0 | 724 |
} |
725 |
return false; |
|
726 |
} |
|
727 |
||
728 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
729 |
* Checks whether serialized data is of string type. |
| 0 | 730 |
* |
731 |
* @since 2.0.5 |
|
732 |
* |
|
| 5 | 733 |
* @param string $data Serialized data. |
| 0 | 734 |
* @return bool False if not a serialized string, true if it is. |
735 |
*/ |
|
736 |
function is_serialized_string( $data ) {
|
|
| 5 | 737 |
// if it isn't a string, it isn't a serialized string. |
738 |
if ( ! is_string( $data ) ) {
|
|
| 0 | 739 |
return false; |
| 5 | 740 |
} |
| 0 | 741 |
$data = trim( $data ); |
| 5 | 742 |
if ( strlen( $data ) < 4 ) {
|
| 0 | 743 |
return false; |
| 5 | 744 |
} elseif ( ':' !== $data[1] ) {
|
| 0 | 745 |
return false; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
746 |
} elseif ( ! str_ends_with( $data, ';' ) ) {
|
| 0 | 747 |
return false; |
| 16 | 748 |
} elseif ( 's' !== $data[0] ) {
|
| 0 | 749 |
return false; |
| 5 | 750 |
} elseif ( '"' !== substr( $data, -2, 1 ) ) {
|
| 0 | 751 |
return false; |
| 5 | 752 |
} else {
|
| 0 | 753 |
return true; |
| 5 | 754 |
} |
| 0 | 755 |
} |
756 |
||
757 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
758 |
* Retrieves post title from XMLRPC XML. |
| 0 | 759 |
* |
760 |
* If the title element is not part of the XML, then the default post title from |
|
761 |
* the $post_default_title will be used instead. |
|
762 |
* |
|
763 |
* @since 0.71 |
|
764 |
* |
|
| 5 | 765 |
* @global string $post_default_title Default XML-RPC post title. |
| 0 | 766 |
* |
767 |
* @param string $content XMLRPC XML Request content |
|
768 |
* @return string Post title |
|
769 |
*/ |
|
770 |
function xmlrpc_getposttitle( $content ) {
|
|
771 |
global $post_default_title; |
|
772 |
if ( preg_match( '/<title>(.+?)<\/title>/is', $content, $matchtitle ) ) {
|
|
773 |
$post_title = $matchtitle[1]; |
|
774 |
} else {
|
|
775 |
$post_title = $post_default_title; |
|
776 |
} |
|
777 |
return $post_title; |
|
778 |
} |
|
779 |
||
780 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
781 |
* Retrieves the post category or categories from XMLRPC XML. |
| 0 | 782 |
* |
783 |
* If the category element is not found, then the default post category will be |
|
784 |
* used. The return type then would be what $post_default_category. If the |
|
785 |
* category is found, then it will always be an array. |
|
786 |
* |
|
787 |
* @since 0.71 |
|
788 |
* |
|
| 5 | 789 |
* @global string $post_default_category Default XML-RPC post category. |
| 0 | 790 |
* |
791 |
* @param string $content XMLRPC XML Request content |
|
792 |
* @return string|array List of categories or category name. |
|
793 |
*/ |
|
794 |
function xmlrpc_getpostcategory( $content ) {
|
|
795 |
global $post_default_category; |
|
796 |
if ( preg_match( '/<category>(.+?)<\/category>/is', $content, $matchcat ) ) {
|
|
797 |
$post_category = trim( $matchcat[1], ',' ); |
|
798 |
$post_category = explode( ',', $post_category ); |
|
799 |
} else {
|
|
800 |
$post_category = $post_default_category; |
|
801 |
} |
|
802 |
return $post_category; |
|
803 |
} |
|
804 |
||
805 |
/** |
|
806 |
* XMLRPC XML content without title and category elements. |
|
807 |
* |
|
808 |
* @since 0.71 |
|
809 |
* |
|
| 5 | 810 |
* @param string $content XML-RPC XML Request content. |
| 0 | 811 |
* @return string XMLRPC XML Request content without title and category elements. |
812 |
*/ |
|
813 |
function xmlrpc_removepostdata( $content ) {
|
|
814 |
$content = preg_replace( '/<title>(.+?)<\/title>/si', '', $content ); |
|
815 |
$content = preg_replace( '/<category>(.+?)<\/category>/si', '', $content ); |
|
816 |
$content = trim( $content ); |
|
817 |
return $content; |
|
818 |
} |
|
819 |
||
820 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
821 |
* Uses RegEx to extract URLs from arbitrary content. |
| 0 | 822 |
* |
823 |
* @since 3.7.0 |
|
| 19 | 824 |
* @since 6.0.0 Fixes support for HTML entities (Trac 30580). |
| 0 | 825 |
* |
| 5 | 826 |
* @param string $content Content to extract URLs from. |
| 16 | 827 |
* @return string[] Array of URLs found in passed string. |
| 0 | 828 |
*/ |
829 |
function wp_extract_urls( $content ) {
|
|
830 |
preg_match_all( |
|
| 5 | 831 |
"#([\"']?)("
|
| 9 | 832 |
. '(?:([\w-]+:)?//?)' |
833 |
. '[^\s()<>]+' |
|
834 |
. '[.]' |
|
835 |
. '(?:' |
|
836 |
. '\([\w\d]+\)|' |
|
837 |
. '(?:' |
|
| 19 | 838 |
. "[^`!()\[\]{}:'\".,<>«»“”‘’\s]|"
|
| 9 | 839 |
. '(?:[:]\d+)?/?' |
840 |
. ')+' |
|
841 |
. ')' |
|
| 5 | 842 |
. ")\\1#", |
| 0 | 843 |
$content, |
844 |
$post_links |
|
845 |
); |
|
846 |
||
| 19 | 847 |
$post_links = array_unique( |
848 |
array_map( |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
849 |
static function ( $link ) {
|
| 19 | 850 |
// Decode to replace valid entities, like &. |
851 |
$link = html_entity_decode( $link ); |
|
852 |
// Maintain backward compatibility by removing extraneous semi-colons (`;`). |
|
853 |
return str_replace( ';', '', $link ); |
|
854 |
}, |
|
855 |
$post_links[2] |
|
856 |
) |
|
857 |
); |
|
| 0 | 858 |
|
859 |
return array_values( $post_links ); |
|
860 |
} |
|
861 |
||
862 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
863 |
* Checks content for video and audio links to add as enclosures. |
| 0 | 864 |
* |
865 |
* Will not add enclosures that have already been added and will |
|
866 |
* remove enclosures that are no longer in the post. This is called as |
|
867 |
* pingbacks and trackbacks. |
|
868 |
* |
|
869 |
* @since 1.5.0 |
|
| 16 | 870 |
* @since 5.3.0 The `$content` parameter was made optional, and the `$post` parameter was |
871 |
* updated to accept a post ID or a WP_Post object. |
|
| 18 | 872 |
* @since 5.6.0 The `$content` parameter is no longer optional, but passing `null` to skip it |
873 |
* is still supported. |
|
| 0 | 874 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
875 |
* @global wpdb $wpdb WordPress database abstraction object. |
| 5 | 876 |
* |
| 18 | 877 |
* @param string|null $content Post content. If `null`, the `post_content` field from `$post` is used. |
| 16 | 878 |
* @param int|WP_Post $post Post ID or post object. |
| 18 | 879 |
* @return void|false Void on success, false if the post is not found. |
880 |
*/ |
|
881 |
function do_enclose( $content, $post ) {
|
|
| 0 | 882 |
global $wpdb; |
883 |
||
| 16 | 884 |
// @todo Tidy this code and make the debug code optional. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
885 |
require_once ABSPATH . WPINC . '/class-IXR.php'; |
| 16 | 886 |
|
887 |
$post = get_post( $post ); |
|
888 |
if ( ! $post ) {
|
|
889 |
return false; |
|
890 |
} |
|
891 |
||
892 |
if ( null === $content ) {
|
|
893 |
$content = $post->post_content; |
|
894 |
} |
|
| 0 | 895 |
|
896 |
$post_links = array(); |
|
897 |
||
| 16 | 898 |
$pung = get_enclosed( $post->ID ); |
| 0 | 899 |
|
900 |
$post_links_temp = wp_extract_urls( $content ); |
|
901 |
||
902 |
foreach ( $pung as $link_test ) {
|
|
| 16 | 903 |
// Link is no longer in post. |
904 |
if ( ! in_array( $link_test, $post_links_temp, true ) ) {
|
|
905 |
$mids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE %s", $post->ID, $wpdb->esc_like( $link_test ) . '%' ) ); |
|
| 9 | 906 |
foreach ( $mids as $mid ) {
|
| 0 | 907 |
delete_metadata_by_mid( 'post', $mid ); |
| 9 | 908 |
} |
| 0 | 909 |
} |
910 |
} |
|
911 |
||
912 |
foreach ( (array) $post_links_temp as $link_test ) {
|
|
| 16 | 913 |
// If we haven't pung it already. |
914 |
if ( ! in_array( $link_test, $pung, true ) ) {
|
|
915 |
$test = parse_url( $link_test ); |
|
| 9 | 916 |
if ( false === $test ) {
|
| 0 | 917 |
continue; |
| 9 | 918 |
} |
919 |
if ( isset( $test['query'] ) ) {
|
|
| 0 | 920 |
$post_links[] = $link_test; |
| 16 | 921 |
} elseif ( isset( $test['path'] ) && ( '/' !== $test['path'] ) && ( '' !== $test['path'] ) ) {
|
| 0 | 922 |
$post_links[] = $link_test; |
| 9 | 923 |
} |
| 0 | 924 |
} |
925 |
} |
|
926 |
||
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
927 |
/** |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
928 |
* Filters the list of enclosure links before querying the database. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
929 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
930 |
* Allows for the addition and/or removal of potential enclosures to save |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
931 |
* to postmeta before checking the database for existing enclosures. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
932 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
933 |
* @since 4.4.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
934 |
* |
| 16 | 935 |
* @param string[] $post_links An array of enclosure links. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
936 |
* @param int $post_id Post ID. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
937 |
*/ |
| 16 | 938 |
$post_links = apply_filters( 'enclosure_links', $post_links, $post->ID ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
939 |
|
| 0 | 940 |
foreach ( (array) $post_links as $url ) {
|
| 18 | 941 |
$url = strip_fragment_from_url( $url ); |
942 |
||
| 16 | 943 |
if ( '' !== $url && ! $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE %s", $post->ID, $wpdb->esc_like( $url ) . '%' ) ) ) {
|
944 |
||
945 |
$headers = wp_get_http_headers( $url ); |
|
946 |
if ( $headers ) {
|
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
947 |
$len = isset( $headers['Content-Length'] ) ? (int) $headers['Content-Length'] : 0; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
948 |
$type = isset( $headers['Content-Type'] ) ? $headers['Content-Type'] : ''; |
| 0 | 949 |
$allowed_types = array( 'video', 'audio' ); |
950 |
||
| 16 | 951 |
// Check to see if we can figure out the mime type from the extension. |
952 |
$url_parts = parse_url( $url ); |
|
953 |
if ( false !== $url_parts && ! empty( $url_parts['path'] ) ) {
|
|
| 0 | 954 |
$extension = pathinfo( $url_parts['path'], PATHINFO_EXTENSION ); |
| 9 | 955 |
if ( ! empty( $extension ) ) {
|
| 0 | 956 |
foreach ( wp_get_mime_types() as $exts => $mime ) {
|
957 |
if ( preg_match( '!^(' . $exts . ')$!i', $extension ) ) {
|
|
958 |
$type = $mime; |
|
959 |
break; |
|
960 |
} |
|
961 |
} |
|
962 |
} |
|
963 |
} |
|
964 |
||
| 16 | 965 |
if ( in_array( substr( $type, 0, strpos( $type, '/' ) ), $allowed_types, true ) ) {
|
966 |
add_post_meta( $post->ID, 'enclosure', "$url\n$len\n$mime\n" ); |
|
| 0 | 967 |
} |
968 |
} |
|
969 |
} |
|
970 |
} |
|
971 |
} |
|
972 |
||
973 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
974 |
* Retrieves HTTP Headers from URL. |
| 0 | 975 |
* |
976 |
* @since 1.5.1 |
|
977 |
* |
|
| 5 | 978 |
* @param string $url URL to retrieve HTTP headers from. |
979 |
* @param bool $deprecated Not Used. |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
980 |
* @return \WpOrg\Requests\Utility\CaseInsensitiveDictionary|false Headers on success, false on failure. |
| 0 | 981 |
*/ |
982 |
function wp_get_http_headers( $url, $deprecated = false ) {
|
|
| 9 | 983 |
if ( ! empty( $deprecated ) ) {
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
984 |
_deprecated_argument( __FUNCTION__, '2.7.0' ); |
| 9 | 985 |
} |
| 0 | 986 |
|
987 |
$response = wp_safe_remote_head( $url ); |
|
988 |
||
| 9 | 989 |
if ( is_wp_error( $response ) ) {
|
| 0 | 990 |
return false; |
| 9 | 991 |
} |
| 0 | 992 |
|
993 |
return wp_remote_retrieve_headers( $response ); |
|
994 |
} |
|
995 |
||
996 |
/** |
|
| 9 | 997 |
* Determines whether the publish date of the current post in the loop is different |
998 |
* from the publish date of the previous post in the loop. |
|
999 |
* |
|
1000 |
* For more information on this and similar theme functions, check out |
|
1001 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
|
|
1002 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
| 0 | 1003 |
* |
1004 |
* @since 0.71 |
|
| 5 | 1005 |
* |
1006 |
* @global string $currentday The day of the current post in the loop. |
|
1007 |
* @global string $previousday The day of the previous post in the loop. |
|
| 0 | 1008 |
* |
1009 |
* @return int 1 when new day, 0 if not a new day. |
|
1010 |
*/ |
|
1011 |
function is_new_day() {
|
|
1012 |
global $currentday, $previousday; |
|
| 16 | 1013 |
|
1014 |
if ( $currentday !== $previousday ) {
|
|
| 0 | 1015 |
return 1; |
| 9 | 1016 |
} else {
|
| 0 | 1017 |
return 0; |
| 9 | 1018 |
} |
| 0 | 1019 |
} |
1020 |
||
1021 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1022 |
* Builds URL query based on an associative and, or indexed array. |
| 0 | 1023 |
* |
1024 |
* This is a convenient function for easily building url queries. It sets the |
|
1025 |
* separator to '&' and uses _http_build_query() function. |
|
1026 |
* |
|
| 5 | 1027 |
* @since 2.3.0 |
1028 |
* |
|
| 0 | 1029 |
* @see _http_build_query() Used to build the query |
| 16 | 1030 |
* @link https://www.php.net/manual/en/function.http-build-query.php for more on what |
| 9 | 1031 |
* http_build_query() does. |
| 0 | 1032 |
* |
1033 |
* @param array $data URL-encode key/value pairs. |
|
| 5 | 1034 |
* @return string URL-encoded string. |
| 0 | 1035 |
*/ |
1036 |
function build_query( $data ) {
|
|
1037 |
return _http_build_query( $data, null, '&', '', false ); |
|
1038 |
} |
|
1039 |
||
| 5 | 1040 |
/** |
1041 |
* From php.net (modified by Mark Jaquith to behave like the native PHP5 function). |
|
1042 |
* |
|
1043 |
* @since 3.2.0 |
|
1044 |
* @access private |
|
1045 |
* |
|
| 16 | 1046 |
* @see https://www.php.net/manual/en/function.http-build-query.php |
1047 |
* |
|
1048 |
* @param array|object $data An array or object of data. Converted to array. |
|
1049 |
* @param string $prefix Optional. Numeric index. If set, start parameter numbering with it. |
|
1050 |
* Default null. |
|
1051 |
* @param string $sep Optional. Argument separator; defaults to 'arg_separator.output'. |
|
1052 |
* Default null. |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1053 |
* @param string $key Optional. Used to prefix key name. Default empty string. |
| 16 | 1054 |
* @param bool $urlencode Optional. Whether to use urlencode() in the result. Default true. |
| 5 | 1055 |
* @return string The query string. |
1056 |
*/ |
|
1057 |
function _http_build_query( $data, $prefix = null, $sep = null, $key = '', $urlencode = true ) {
|
|
| 0 | 1058 |
$ret = array(); |
1059 |
||
1060 |
foreach ( (array) $data as $k => $v ) {
|
|
| 9 | 1061 |
if ( $urlencode ) {
|
1062 |
$k = urlencode( $k ); |
|
1063 |
} |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1064 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1065 |
if ( is_int( $k ) && null !== $prefix ) {
|
| 9 | 1066 |
$k = $prefix . $k; |
1067 |
} |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1068 |
|
| 9 | 1069 |
if ( ! empty( $key ) ) {
|
| 0 | 1070 |
$k = $key . '%5B' . $k . '%5D'; |
| 9 | 1071 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1072 |
|
| 16 | 1073 |
if ( null === $v ) {
|
| 0 | 1074 |
continue; |
| 16 | 1075 |
} elseif ( false === $v ) {
|
| 0 | 1076 |
$v = '0'; |
| 9 | 1077 |
} |
1078 |
||
1079 |
if ( is_array( $v ) || is_object( $v ) ) {
|
|
1080 |
array_push( $ret, _http_build_query( $v, '', $sep, $k, $urlencode ) ); |
|
1081 |
} elseif ( $urlencode ) {
|
|
1082 |
array_push( $ret, $k . '=' . urlencode( $v ) ); |
|
1083 |
} else {
|
|
1084 |
array_push( $ret, $k . '=' . $v ); |
|
1085 |
} |
|
1086 |
} |
|
1087 |
||
1088 |
if ( null === $sep ) {
|
|
1089 |
$sep = ini_get( 'arg_separator.output' ); |
|
1090 |
} |
|
1091 |
||
1092 |
return implode( $sep, $ret ); |
|
| 0 | 1093 |
} |
1094 |
||
1095 |
/** |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1096 |
* Retrieves a modified URL query string. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1097 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1098 |
* You can rebuild the URL and append query variables to the URL query by using this function. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1099 |
* There are two ways to use this function; either a single key and value, or an associative array. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1100 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1101 |
* Using a single key and value: |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1102 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1103 |
* add_query_arg( 'key', 'value', 'http://example.com' ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1104 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1105 |
* Using an associative array: |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1106 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1107 |
* add_query_arg( array( |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1108 |
* 'key1' => 'value1', |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1109 |
* 'key2' => 'value2', |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1110 |
* ), 'http://example.com' ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1111 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1112 |
* Omitting the URL from either use results in the current URL being used |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1113 |
* (the value of `$_SERVER['REQUEST_URI']`). |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1114 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1115 |
* Values are expected to be encoded appropriately with urlencode() or rawurlencode(). |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1116 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1117 |
* Setting any query variable's value to boolean false removes the key (see remove_query_arg()). |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1118 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1119 |
* Important: The return value of add_query_arg() is not escaped by default. Output should be |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1120 |
* late-escaped with esc_url() or similar to help prevent vulnerability to cross-site scripting |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1121 |
* (XSS) attacks. |
| 0 | 1122 |
* |
1123 |
* @since 1.5.0 |
|
| 16 | 1124 |
* @since 5.3.0 Formalized the existing and already documented parameters |
1125 |
* by adding `...$args` to the function signature. |
|
| 0 | 1126 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1127 |
* @param string|array $key Either a query variable key, or an associative array of query variables. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1128 |
* @param string $value Optional. Either a query variable value, or a URL to act upon. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1129 |
* @param string $url Optional. A URL to act upon. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1130 |
* @return string New URL query string (unescaped). |
| 0 | 1131 |
*/ |
| 16 | 1132 |
function add_query_arg( ...$args ) {
|
| 0 | 1133 |
if ( is_array( $args[0] ) ) {
|
| 9 | 1134 |
if ( count( $args ) < 2 || false === $args[1] ) {
|
| 0 | 1135 |
$uri = $_SERVER['REQUEST_URI']; |
| 9 | 1136 |
} else {
|
| 0 | 1137 |
$uri = $args[1]; |
| 9 | 1138 |
} |
| 0 | 1139 |
} else {
|
| 9 | 1140 |
if ( count( $args ) < 3 || false === $args[2] ) {
|
| 0 | 1141 |
$uri = $_SERVER['REQUEST_URI']; |
| 9 | 1142 |
} else {
|
| 0 | 1143 |
$uri = $args[2]; |
| 9 | 1144 |
} |
1145 |
} |
|
1146 |
||
| 16 | 1147 |
$frag = strstr( $uri, '#' ); |
1148 |
if ( $frag ) {
|
|
| 0 | 1149 |
$uri = substr( $uri, 0, -strlen( $frag ) ); |
| 9 | 1150 |
} else {
|
| 0 | 1151 |
$frag = ''; |
| 9 | 1152 |
} |
| 0 | 1153 |
|
1154 |
if ( 0 === stripos( $uri, 'http://' ) ) {
|
|
1155 |
$protocol = 'http://'; |
|
| 9 | 1156 |
$uri = substr( $uri, 7 ); |
| 0 | 1157 |
} elseif ( 0 === stripos( $uri, 'https://' ) ) {
|
1158 |
$protocol = 'https://'; |
|
| 9 | 1159 |
$uri = substr( $uri, 8 ); |
| 0 | 1160 |
} else {
|
1161 |
$protocol = ''; |
|
1162 |
} |
|
1163 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1164 |
if ( str_contains( $uri, '?' ) ) {
|
| 0 | 1165 |
list( $base, $query ) = explode( '?', $uri, 2 ); |
| 9 | 1166 |
$base .= '?'; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1167 |
} elseif ( $protocol || ! str_contains( $uri, '=' ) ) {
|
| 9 | 1168 |
$base = $uri . '?'; |
| 0 | 1169 |
$query = ''; |
1170 |
} else {
|
|
| 9 | 1171 |
$base = ''; |
| 0 | 1172 |
$query = $uri; |
1173 |
} |
|
1174 |
||
1175 |
wp_parse_str( $query, $qs ); |
|
| 16 | 1176 |
$qs = urlencode_deep( $qs ); // This re-URL-encodes things that were already in the query string. |
| 0 | 1177 |
if ( is_array( $args[0] ) ) {
|
| 5 | 1178 |
foreach ( $args[0] as $k => $v ) {
|
1179 |
$qs[ $k ] = $v; |
|
1180 |
} |
|
| 0 | 1181 |
} else {
|
1182 |
$qs[ $args[0] ] = $args[1]; |
|
1183 |
} |
|
1184 |
||
1185 |
foreach ( $qs as $k => $v ) {
|
|
| 16 | 1186 |
if ( false === $v ) {
|
| 9 | 1187 |
unset( $qs[ $k ] ); |
1188 |
} |
|
| 0 | 1189 |
} |
1190 |
||
1191 |
$ret = build_query( $qs ); |
|
1192 |
$ret = trim( $ret, '?' ); |
|
1193 |
$ret = preg_replace( '#=(&|$)#', '$1', $ret ); |
|
1194 |
$ret = $protocol . $base . $ret . $frag; |
|
1195 |
$ret = rtrim( $ret, '?' ); |
|
| 19 | 1196 |
$ret = str_replace( '?#', '#', $ret ); |
| 0 | 1197 |
return $ret; |
1198 |
} |
|
1199 |
||
1200 |
/** |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1201 |
* Removes an item or items from a query string. |
| 0 | 1202 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1203 |
* Important: The return value of remove_query_arg() is not escaped by default. Output should be |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1204 |
* late-escaped with esc_url() or similar to help prevent vulnerability to cross-site scripting |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1205 |
* (XSS) attacks. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1206 |
* |
| 0 | 1207 |
* @since 1.5.0 |
1208 |
* |
|
| 18 | 1209 |
* @param string|string[] $key Query key or keys to remove. |
1210 |
* @param false|string $query Optional. When false uses the current URL. Default false. |
|
| 0 | 1211 |
* @return string New URL query string. |
1212 |
*/ |
|
| 5 | 1213 |
function remove_query_arg( $key, $query = false ) {
|
| 16 | 1214 |
if ( is_array( $key ) ) { // Removing multiple keys.
|
| 9 | 1215 |
foreach ( $key as $k ) {
|
| 0 | 1216 |
$query = add_query_arg( $k, false, $query ); |
| 9 | 1217 |
} |
| 0 | 1218 |
return $query; |
1219 |
} |
|
1220 |
return add_query_arg( $key, false, $query ); |
|
1221 |
} |
|
1222 |
||
1223 |
/** |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1224 |
* Returns an array of single-use query variable names that can be removed from a URL. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1225 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1226 |
* @since 4.4.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1227 |
* |
| 18 | 1228 |
* @return string[] An array of query variable names to remove from the URL. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1229 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1230 |
function wp_removable_query_args() {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1231 |
$removable_query_args = array( |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1232 |
'activate', |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1233 |
'activated', |
| 16 | 1234 |
'admin_email_remind_later', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1235 |
'approved', |
| 18 | 1236 |
'core-major-auto-updates-saved', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1237 |
'deactivate', |
| 16 | 1238 |
'delete_count', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1239 |
'deleted', |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1240 |
'disabled', |
| 16 | 1241 |
'doing_wp_cron', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1242 |
'enabled', |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1243 |
'error', |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1244 |
'hotkeys_highlight_first', |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1245 |
'hotkeys_highlight_last', |
| 18 | 1246 |
'ids', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1247 |
'locked', |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1248 |
'message', |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1249 |
'same', |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1250 |
'saved', |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1251 |
'settings-updated', |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1252 |
'skipped', |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1253 |
'spammed', |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1254 |
'trashed', |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1255 |
'unspammed', |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1256 |
'untrashed', |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1257 |
'update', |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1258 |
'updated', |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1259 |
'wp-post-new-reload', |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1260 |
); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1261 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1262 |
/** |
| 18 | 1263 |
* Filters the list of query variable names to remove. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1264 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1265 |
* @since 4.2.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1266 |
* |
| 18 | 1267 |
* @param string[] $removable_query_args An array of query variable names to remove from a URL. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1268 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1269 |
return apply_filters( 'removable_query_args', $removable_query_args ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1270 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1271 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1272 |
/** |
| 0 | 1273 |
* Walks the array while sanitizing the contents. |
1274 |
* |
|
1275 |
* @since 0.71 |
|
| 16 | 1276 |
* @since 5.5.0 Non-string values are left untouched. |
| 0 | 1277 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1278 |
* @param array $input_array Array to walk while sanitizing contents. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1279 |
* @return array Sanitized $input_array. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1280 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1281 |
function add_magic_quotes( $input_array ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1282 |
foreach ( (array) $input_array as $k => $v ) {
|
| 0 | 1283 |
if ( is_array( $v ) ) {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1284 |
$input_array[ $k ] = add_magic_quotes( $v ); |
| 16 | 1285 |
} elseif ( is_string( $v ) ) {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1286 |
$input_array[ $k ] = addslashes( $v ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1287 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1288 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1289 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1290 |
return $input_array; |
| 0 | 1291 |
} |
1292 |
||
1293 |
/** |
|
1294 |
* HTTP request for URI to retrieve content. |
|
1295 |
* |
|
1296 |
* @since 1.5.1 |
|
| 5 | 1297 |
* |
1298 |
* @see wp_safe_remote_get() |
|
| 0 | 1299 |
* |
1300 |
* @param string $uri URI/URL of web page to retrieve. |
|
| 16 | 1301 |
* @return string|false HTTP content. False on failure. |
| 0 | 1302 |
*/ |
1303 |
function wp_remote_fopen( $uri ) {
|
|
| 16 | 1304 |
$parsed_url = parse_url( $uri ); |
| 0 | 1305 |
|
| 9 | 1306 |
if ( ! $parsed_url || ! is_array( $parsed_url ) ) {
|
| 0 | 1307 |
return false; |
| 9 | 1308 |
} |
1309 |
||
1310 |
$options = array(); |
|
| 0 | 1311 |
$options['timeout'] = 10; |
1312 |
||
1313 |
$response = wp_safe_remote_get( $uri, $options ); |
|
1314 |
||
| 9 | 1315 |
if ( is_wp_error( $response ) ) {
|
| 0 | 1316 |
return false; |
| 9 | 1317 |
} |
| 0 | 1318 |
|
1319 |
return wp_remote_retrieve_body( $response ); |
|
1320 |
} |
|
1321 |
||
1322 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1323 |
* Sets up the WordPress query. |
| 0 | 1324 |
* |
1325 |
* @since 2.0.0 |
|
1326 |
* |
|
| 16 | 1327 |
* @global WP $wp Current WordPress environment instance. |
1328 |
* @global WP_Query $wp_query WordPress Query object. |
|
1329 |
* @global WP_Query $wp_the_query Copy of the WordPress Query object. |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1330 |
* |
| 5 | 1331 |
* @param string|array $query_vars Default WP_Query arguments. |
| 0 | 1332 |
*/ |
1333 |
function wp( $query_vars = '' ) {
|
|
1334 |
global $wp, $wp_query, $wp_the_query; |
|
| 16 | 1335 |
|
| 0 | 1336 |
$wp->main( $query_vars ); |
1337 |
||
| 9 | 1338 |
if ( ! isset( $wp_the_query ) ) {
|
| 0 | 1339 |
$wp_the_query = $wp_query; |
| 9 | 1340 |
} |
| 0 | 1341 |
} |
1342 |
||
1343 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1344 |
* Retrieves the description for the HTTP status. |
| 0 | 1345 |
* |
1346 |
* @since 2.3.0 |
|
| 9 | 1347 |
* @since 3.9.0 Added status codes 418, 428, 429, 431, and 511. |
1348 |
* @since 4.5.0 Added status codes 308, 421, and 451. |
|
1349 |
* @since 5.1.0 Added status code 103. |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1350 |
* @since 6.6.0 Added status code 425. |
| 0 | 1351 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1352 |
* @global array $wp_header_to_desc |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1353 |
* |
| 0 | 1354 |
* @param int $code HTTP status code. |
| 16 | 1355 |
* @return string Status description if found, an empty string otherwise. |
| 0 | 1356 |
*/ |
1357 |
function get_status_header_desc( $code ) {
|
|
1358 |
global $wp_header_to_desc; |
|
1359 |
||
1360 |
$code = absint( $code ); |
|
1361 |
||
| 9 | 1362 |
if ( ! isset( $wp_header_to_desc ) ) {
|
| 0 | 1363 |
$wp_header_to_desc = array( |
1364 |
100 => 'Continue', |
|
1365 |
101 => 'Switching Protocols', |
|
1366 |
102 => 'Processing', |
|
| 9 | 1367 |
103 => 'Early Hints', |
| 0 | 1368 |
|
1369 |
200 => 'OK', |
|
1370 |
201 => 'Created', |
|
1371 |
202 => 'Accepted', |
|
1372 |
203 => 'Non-Authoritative Information', |
|
1373 |
204 => 'No Content', |
|
1374 |
205 => 'Reset Content', |
|
1375 |
206 => 'Partial Content', |
|
1376 |
207 => 'Multi-Status', |
|
1377 |
226 => 'IM Used', |
|
1378 |
||
1379 |
300 => 'Multiple Choices', |
|
1380 |
301 => 'Moved Permanently', |
|
1381 |
302 => 'Found', |
|
1382 |
303 => 'See Other', |
|
1383 |
304 => 'Not Modified', |
|
1384 |
305 => 'Use Proxy', |
|
1385 |
306 => 'Reserved', |
|
1386 |
307 => 'Temporary Redirect', |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1387 |
308 => 'Permanent Redirect', |
| 0 | 1388 |
|
1389 |
400 => 'Bad Request', |
|
1390 |
401 => 'Unauthorized', |
|
1391 |
402 => 'Payment Required', |
|
1392 |
403 => 'Forbidden', |
|
1393 |
404 => 'Not Found', |
|
1394 |
405 => 'Method Not Allowed', |
|
1395 |
406 => 'Not Acceptable', |
|
1396 |
407 => 'Proxy Authentication Required', |
|
1397 |
408 => 'Request Timeout', |
|
1398 |
409 => 'Conflict', |
|
1399 |
410 => 'Gone', |
|
1400 |
411 => 'Length Required', |
|
1401 |
412 => 'Precondition Failed', |
|
1402 |
413 => 'Request Entity Too Large', |
|
1403 |
414 => 'Request-URI Too Long', |
|
1404 |
415 => 'Unsupported Media Type', |
|
1405 |
416 => 'Requested Range Not Satisfiable', |
|
1406 |
417 => 'Expectation Failed', |
|
| 5 | 1407 |
418 => 'I\'m a teapot', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1408 |
421 => 'Misdirected Request', |
| 0 | 1409 |
422 => 'Unprocessable Entity', |
1410 |
423 => 'Locked', |
|
1411 |
424 => 'Failed Dependency', |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1412 |
425 => 'Too Early', |
| 0 | 1413 |
426 => 'Upgrade Required', |
| 5 | 1414 |
428 => 'Precondition Required', |
1415 |
429 => 'Too Many Requests', |
|
1416 |
431 => 'Request Header Fields Too Large', |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1417 |
451 => 'Unavailable For Legal Reasons', |
| 0 | 1418 |
|
1419 |
500 => 'Internal Server Error', |
|
1420 |
501 => 'Not Implemented', |
|
1421 |
502 => 'Bad Gateway', |
|
1422 |
503 => 'Service Unavailable', |
|
1423 |
504 => 'Gateway Timeout', |
|
1424 |
505 => 'HTTP Version Not Supported', |
|
1425 |
506 => 'Variant Also Negotiates', |
|
1426 |
507 => 'Insufficient Storage', |
|
| 5 | 1427 |
510 => 'Not Extended', |
1428 |
511 => 'Network Authentication Required', |
|
| 0 | 1429 |
); |
1430 |
} |
|
1431 |
||
| 9 | 1432 |
if ( isset( $wp_header_to_desc[ $code ] ) ) {
|
1433 |
return $wp_header_to_desc[ $code ]; |
|
1434 |
} else {
|
|
| 0 | 1435 |
return ''; |
| 9 | 1436 |
} |
| 0 | 1437 |
} |
1438 |
||
1439 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1440 |
* Sets HTTP status header. |
| 0 | 1441 |
* |
1442 |
* @since 2.0.0 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1443 |
* @since 4.4.0 Added the `$description` parameter. |
| 5 | 1444 |
* |
1445 |
* @see get_status_header_desc() |
|
1446 |
* |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1447 |
* @param int $code HTTP status code. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1448 |
* @param string $description Optional. A custom description for the HTTP status. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1449 |
* Defaults to the result of get_status_header_desc() for the given code. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1450 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1451 |
function status_header( $code, $description = '' ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1452 |
if ( ! $description ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1453 |
$description = get_status_header_desc( $code ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1454 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1455 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1456 |
if ( empty( $description ) ) {
|
| 5 | 1457 |
return; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1458 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1459 |
|
| 9 | 1460 |
$protocol = wp_get_server_protocol(); |
| 5 | 1461 |
$status_header = "$protocol $code $description"; |
| 9 | 1462 |
if ( function_exists( 'apply_filters' ) ) {
|
| 5 | 1463 |
|
1464 |
/** |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1465 |
* Filters an HTTP status header. |
| 5 | 1466 |
* |
1467 |
* @since 2.2.0 |
|
1468 |
* |
|
1469 |
* @param string $status_header HTTP status header. |
|
1470 |
* @param int $code HTTP status code. |
|
1471 |
* @param string $description Description for the status code. |
|
1472 |
* @param string $protocol Server protocol. |
|
1473 |
*/ |
|
1474 |
$status_header = apply_filters( 'status_header', $status_header, $code, $description, $protocol ); |
|
| 9 | 1475 |
} |
| 5 | 1476 |
|
| 16 | 1477 |
if ( ! headers_sent() ) {
|
1478 |
header( $status_header, true, $code ); |
|
1479 |
} |
|
| 0 | 1480 |
} |
1481 |
||
1482 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1483 |
* Gets the HTTP header information to prevent caching. |
| 5 | 1484 |
* |
1485 |
* The several different headers cover the different ways cache prevention |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1486 |
* is handled by different browsers. |
| 0 | 1487 |
* |
1488 |
* @since 2.8.0 |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1489 |
* @since 6.3.0 The `Cache-Control` header for logged in users now includes the |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1490 |
* `no-store` and `private` directives. |
| 0 | 1491 |
* |
1492 |
* @return array The associative array of header names and field values. |
|
1493 |
*/ |
|
1494 |
function wp_get_nocache_headers() {
|
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1495 |
$cache_control = ( function_exists( 'is_user_logged_in' ) && is_user_logged_in() ) |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1496 |
? 'no-cache, must-revalidate, max-age=0, no-store, private' |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1497 |
: 'no-cache, must-revalidate, max-age=0'; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1498 |
|
| 0 | 1499 |
$headers = array( |
| 9 | 1500 |
'Expires' => 'Wed, 11 Jan 1984 05:00:00 GMT', |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1501 |
'Cache-Control' => $cache_control, |
| 0 | 1502 |
); |
1503 |
||
| 9 | 1504 |
if ( function_exists( 'apply_filters' ) ) {
|
| 5 | 1505 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1506 |
* Filters the cache-controlling HTTP headers that are used to prevent caching. |
| 5 | 1507 |
* |
1508 |
* @since 2.8.0 |
|
1509 |
* |
|
1510 |
* @see wp_get_nocache_headers() |
|
1511 |
* |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1512 |
* @param array $headers Header names and field values. |
| 5 | 1513 |
*/ |
1514 |
$headers = (array) apply_filters( 'nocache_headers', $headers ); |
|
| 0 | 1515 |
} |
1516 |
$headers['Last-Modified'] = false; |
|
1517 |
return $headers; |
|
1518 |
} |
|
1519 |
||
1520 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1521 |
* Sets the HTTP headers to prevent caching for the different browsers. |
| 5 | 1522 |
* |
1523 |
* Different browsers support different nocache headers, so several |
|
1524 |
* headers must be sent so that all of them get the point that no |
|
1525 |
* caching should occur. |
|
| 0 | 1526 |
* |
1527 |
* @since 2.0.0 |
|
| 5 | 1528 |
* |
1529 |
* @see wp_get_nocache_headers() |
|
| 0 | 1530 |
*/ |
1531 |
function nocache_headers() {
|
|
| 16 | 1532 |
if ( headers_sent() ) {
|
1533 |
return; |
|
1534 |
} |
|
1535 |
||
| 0 | 1536 |
$headers = wp_get_nocache_headers(); |
1537 |
||
1538 |
unset( $headers['Last-Modified'] ); |
|
1539 |
||
| 16 | 1540 |
header_remove( 'Last-Modified' ); |
| 0 | 1541 |
|
| 9 | 1542 |
foreach ( $headers as $name => $field_value ) {
|
| 16 | 1543 |
header( "{$name}: {$field_value}" );
|
| 9 | 1544 |
} |
| 0 | 1545 |
} |
1546 |
||
1547 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1548 |
* Sets the HTTP headers for caching for 10 days with JavaScript content type. |
| 0 | 1549 |
* |
1550 |
* @since 2.1.0 |
|
1551 |
*/ |
|
1552 |
function cache_javascript_headers() {
|
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1553 |
$expires_offset = 10 * DAY_IN_SECONDS; |
| 5 | 1554 |
|
| 9 | 1555 |
header( 'Content-Type: text/javascript; charset=' . get_bloginfo( 'charset' ) ); |
| 16 | 1556 |
header( 'Vary: Accept-Encoding' ); // Handle proxies. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1557 |
header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expires_offset ) . ' GMT' ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1558 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1559 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1560 |
/** |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1561 |
* Retrieves the number of database queries during the WordPress execution. |
| 0 | 1562 |
* |
1563 |
* @since 2.0.0 |
|
1564 |
* |
|
| 5 | 1565 |
* @global wpdb $wpdb WordPress database abstraction object. |
1566 |
* |
|
1567 |
* @return int Number of database queries. |
|
| 0 | 1568 |
*/ |
1569 |
function get_num_queries() {
|
|
1570 |
global $wpdb; |
|
1571 |
return $wpdb->num_queries; |
|
1572 |
} |
|
1573 |
||
1574 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1575 |
* Determines whether input is yes or no. |
| 5 | 1576 |
* |
1577 |
* Must be 'y' to be true. |
|
| 0 | 1578 |
* |
1579 |
* @since 1.0.0 |
|
1580 |
* |
|
| 5 | 1581 |
* @param string $yn Character string containing either 'y' (yes) or 'n' (no). |
| 19 | 1582 |
* @return bool True if 'y', false on anything else. |
| 0 | 1583 |
*/ |
1584 |
function bool_from_yn( $yn ) {
|
|
| 16 | 1585 |
return ( 'y' === strtolower( $yn ) ); |
| 0 | 1586 |
} |
1587 |
||
1588 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1589 |
* Loads the feed template from the use of an action hook. |
| 0 | 1590 |
* |
1591 |
* If the feed action does not have a hook, then the function will die with a |
|
1592 |
* message telling the visitor that the feed is not valid. |
|
1593 |
* |
|
1594 |
* It is better to only have one hook for each feed. |
|
1595 |
* |
|
1596 |
* @since 2.1.0 |
|
| 5 | 1597 |
* |
| 16 | 1598 |
* @global WP_Query $wp_query WordPress Query object. |
| 0 | 1599 |
*/ |
1600 |
function do_feed() {
|
|
1601 |
global $wp_query; |
|
1602 |
||
1603 |
$feed = get_query_var( 'feed' ); |
|
1604 |
||
1605 |
// Remove the pad, if present. |
|
1606 |
$feed = preg_replace( '/^_+/', '', $feed ); |
|
1607 |
||
| 16 | 1608 |
if ( '' === $feed || 'feed' === $feed ) {
|
| 0 | 1609 |
$feed = get_default_feed(); |
| 9 | 1610 |
} |
| 0 | 1611 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1612 |
if ( ! has_action( "do_feed_{$feed}" ) ) {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1613 |
wp_die( __( '<strong>Error:</strong> This is not a valid feed template.' ), '', array( 'response' => 404 ) ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1614 |
} |
| 0 | 1615 |
|
| 5 | 1616 |
/** |
1617 |
* Fires once the given feed is loaded. |
|
1618 |
* |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1619 |
* The dynamic portion of the hook name, `$feed`, refers to the feed template name. |
| 18 | 1620 |
* |
1621 |
* Possible hook names include: |
|
1622 |
* |
|
1623 |
* - `do_feed_atom` |
|
1624 |
* - `do_feed_rdf` |
|
1625 |
* - `do_feed_rss` |
|
1626 |
* - `do_feed_rss2` |
|
| 5 | 1627 |
* |
1628 |
* @since 2.1.0 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1629 |
* @since 4.4.0 The `$feed` parameter was added. |
| 5 | 1630 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1631 |
* @param bool $is_comment_feed Whether the feed is a comment feed. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1632 |
* @param string $feed The feed name. |
| 5 | 1633 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1634 |
do_action( "do_feed_{$feed}", $wp_query->is_comment_feed, $feed );
|
| 0 | 1635 |
} |
1636 |
||
1637 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1638 |
* Loads the RDF RSS 0.91 Feed template. |
| 0 | 1639 |
* |
1640 |
* @since 2.1.0 |
|
| 5 | 1641 |
* |
1642 |
* @see load_template() |
|
| 0 | 1643 |
*/ |
1644 |
function do_feed_rdf() {
|
|
1645 |
load_template( ABSPATH . WPINC . '/feed-rdf.php' ); |
|
1646 |
} |
|
1647 |
||
1648 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1649 |
* Loads the RSS 1.0 Feed Template. |
| 0 | 1650 |
* |
1651 |
* @since 2.1.0 |
|
| 5 | 1652 |
* |
1653 |
* @see load_template() |
|
| 0 | 1654 |
*/ |
1655 |
function do_feed_rss() {
|
|
1656 |
load_template( ABSPATH . WPINC . '/feed-rss.php' ); |
|
1657 |
} |
|
1658 |
||
1659 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1660 |
* Loads either the RSS2 comment feed or the RSS2 posts feed. |
| 0 | 1661 |
* |
1662 |
* @since 2.1.0 |
|
1663 |
* |
|
| 5 | 1664 |
* @see load_template() |
1665 |
* |
|
| 0 | 1666 |
* @param bool $for_comments True for the comment feed, false for normal feed. |
1667 |
*/ |
|
1668 |
function do_feed_rss2( $for_comments ) {
|
|
| 9 | 1669 |
if ( $for_comments ) {
|
| 0 | 1670 |
load_template( ABSPATH . WPINC . '/feed-rss2-comments.php' ); |
| 9 | 1671 |
} else {
|
| 0 | 1672 |
load_template( ABSPATH . WPINC . '/feed-rss2.php' ); |
| 9 | 1673 |
} |
| 0 | 1674 |
} |
1675 |
||
1676 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1677 |
* Loads either Atom comment feed or Atom posts feed. |
| 0 | 1678 |
* |
1679 |
* @since 2.1.0 |
|
1680 |
* |
|
| 5 | 1681 |
* @see load_template() |
1682 |
* |
|
| 0 | 1683 |
* @param bool $for_comments True for the comment feed, false for normal feed. |
1684 |
*/ |
|
1685 |
function do_feed_atom( $for_comments ) {
|
|
| 9 | 1686 |
if ( $for_comments ) {
|
1687 |
load_template( ABSPATH . WPINC . '/feed-atom-comments.php' ); |
|
1688 |
} else {
|
|
| 0 | 1689 |
load_template( ABSPATH . WPINC . '/feed-atom.php' ); |
| 9 | 1690 |
} |
| 0 | 1691 |
} |
1692 |
||
1693 |
/** |
|
| 16 | 1694 |
* Displays the default robots.txt file content. |
| 0 | 1695 |
* |
1696 |
* @since 2.1.0 |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1697 |
* @since 5.3.0 Remove the "Disallow: /" output if search engine visibility is |
| 18 | 1698 |
* discouraged in favor of robots meta HTML tag via wp_robots_no_robots() |
1699 |
* filter callback. |
|
| 0 | 1700 |
*/ |
1701 |
function do_robots() {
|
|
1702 |
header( 'Content-Type: text/plain; charset=utf-8' ); |
|
1703 |
||
| 5 | 1704 |
/** |
1705 |
* Fires when displaying the robots.txt file. |
|
1706 |
* |
|
1707 |
* @since 2.1.0 |
|
1708 |
*/ |
|
| 0 | 1709 |
do_action( 'do_robotstxt' ); |
1710 |
||
1711 |
$output = "User-agent: *\n"; |
|
1712 |
$public = get_option( 'blog_public' ); |
|
| 16 | 1713 |
|
1714 |
$site_url = parse_url( site_url() ); |
|
1715 |
$path = ( ! empty( $site_url['path'] ) ) ? $site_url['path'] : ''; |
|
1716 |
$output .= "Disallow: $path/wp-admin/\n"; |
|
1717 |
$output .= "Allow: $path/wp-admin/admin-ajax.php\n"; |
|
| 0 | 1718 |
|
| 5 | 1719 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1720 |
* Filters the robots.txt output. |
| 5 | 1721 |
* |
1722 |
* @since 3.0.0 |
|
1723 |
* |
|
| 16 | 1724 |
* @param string $output The robots.txt output. |
| 5 | 1725 |
* @param bool $public Whether the site is considered "public". |
1726 |
*/ |
|
1727 |
echo apply_filters( 'robots_txt', $output, $public ); |
|
| 0 | 1728 |
} |
1729 |
||
1730 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1731 |
* Displays the favicon.ico file content. |
| 16 | 1732 |
* |
1733 |
* @since 5.4.0 |
|
1734 |
*/ |
|
1735 |
function do_favicon() {
|
|
1736 |
/** |
|
1737 |
* Fires when serving the favicon.ico file. |
|
1738 |
* |
|
1739 |
* @since 5.4.0 |
|
1740 |
*/ |
|
1741 |
do_action( 'do_faviconico' ); |
|
1742 |
||
1743 |
wp_redirect( get_site_icon_url( 32, includes_url( 'images/w-logo-blue-white-bg.png' ) ) ); |
|
1744 |
exit; |
|
1745 |
} |
|
1746 |
||
1747 |
/** |
|
| 9 | 1748 |
* Determines whether WordPress is already installed. |
| 0 | 1749 |
* |
| 5 | 1750 |
* The cache will be checked first. If you have a cache plugin, which saves |
1751 |
* the cache values, then this will work. If you use the default WordPress |
|
1752 |
* cache, and the database goes away, then you might have problems. |
|
1753 |
* |
|
1754 |
* Checks for the 'siteurl' option for whether WordPress is installed. |
|
| 0 | 1755 |
* |
| 9 | 1756 |
* For more information on this and similar theme functions, check out |
1757 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
|
|
1758 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
1759 |
* |
|
| 0 | 1760 |
* @since 2.1.0 |
| 5 | 1761 |
* |
1762 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
1763 |
* |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1764 |
* @return bool Whether the site is already installed. |
| 0 | 1765 |
*/ |
1766 |
function is_blog_installed() {
|
|
1767 |
global $wpdb; |
|
1768 |
||
| 5 | 1769 |
/* |
1770 |
* Check cache first. If options table goes away and we have true |
|
1771 |
* cached, oh well. |
|
1772 |
*/ |
|
| 9 | 1773 |
if ( wp_cache_get( 'is_blog_installed' ) ) {
|
| 0 | 1774 |
return true; |
| 9 | 1775 |
} |
| 0 | 1776 |
|
1777 |
$suppress = $wpdb->suppress_errors(); |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1778 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1779 |
if ( ! wp_installing() ) {
|
| 0 | 1780 |
$alloptions = wp_load_alloptions(); |
1781 |
} |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1782 |
|
| 16 | 1783 |
// If siteurl is not set to autoload, check it specifically. |
| 9 | 1784 |
if ( ! isset( $alloptions['siteurl'] ) ) {
|
| 0 | 1785 |
$installed = $wpdb->get_var( "SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'" ); |
| 9 | 1786 |
} else {
|
| 0 | 1787 |
$installed = $alloptions['siteurl']; |
| 9 | 1788 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1789 |
|
| 0 | 1790 |
$wpdb->suppress_errors( $suppress ); |
1791 |
||
| 9 | 1792 |
$installed = ! empty( $installed ); |
| 0 | 1793 |
wp_cache_set( 'is_blog_installed', $installed ); |
1794 |
||
| 9 | 1795 |
if ( $installed ) {
|
| 0 | 1796 |
return true; |
| 9 | 1797 |
} |
| 0 | 1798 |
|
1799 |
// If visiting repair.php, return true and let it take over. |
|
| 9 | 1800 |
if ( defined( 'WP_REPAIRING' ) ) {
|
| 0 | 1801 |
return true; |
| 9 | 1802 |
} |
| 0 | 1803 |
|
1804 |
$suppress = $wpdb->suppress_errors(); |
|
1805 |
||
| 5 | 1806 |
/* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1807 |
* Loop over the WP tables. If none exist, then scratch installation is allowed. |
| 5 | 1808 |
* If one or more exist, suggest table repair since we got here because the |
1809 |
* options table could not be accessed. |
|
1810 |
*/ |
|
| 0 | 1811 |
$wp_tables = $wpdb->tables(); |
1812 |
foreach ( $wp_tables as $table ) {
|
|
| 18 | 1813 |
// The existence of custom user tables shouldn't suggest an unwise state or prevent a clean installation. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1814 |
if ( defined( 'CUSTOM_USER_TABLE' ) && CUSTOM_USER_TABLE === $table ) {
|
| 0 | 1815 |
continue; |
| 9 | 1816 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1817 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1818 |
if ( defined( 'CUSTOM_USER_META_TABLE' ) && CUSTOM_USER_META_TABLE === $table ) {
|
| 0 | 1819 |
continue; |
| 9 | 1820 |
} |
1821 |
||
| 18 | 1822 |
$described_table = $wpdb->get_results( "DESCRIBE $table;" ); |
1823 |
if ( |
|
1824 |
( ! $described_table && empty( $wpdb->last_error ) ) || |
|
1825 |
( is_array( $described_table ) && 0 === count( $described_table ) ) |
|
1826 |
) {
|
|
| 0 | 1827 |
continue; |
| 9 | 1828 |
} |
| 0 | 1829 |
|
| 18 | 1830 |
// One or more tables exist. This is not good. |
| 0 | 1831 |
|
1832 |
wp_load_translations_early(); |
|
1833 |
||
1834 |
// Die with a DB error. |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1835 |
$wpdb->error = sprintf( |
| 16 | 1836 |
/* translators: %s: Database repair URL. */ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1837 |
__( 'One or more database tables are unavailable. The database may need to be <a href="%s">repaired</a>.' ), |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1838 |
'maint/repair.php?referrer=is_blog_installed' |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1839 |
); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1840 |
|
| 0 | 1841 |
dead_db(); |
1842 |
} |
|
1843 |
||
1844 |
$wpdb->suppress_errors( $suppress ); |
|
1845 |
||
1846 |
wp_cache_set( 'is_blog_installed', false ); |
|
1847 |
||
1848 |
return false; |
|
1849 |
} |
|
1850 |
||
1851 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1852 |
* Retrieves URL with nonce added to URL query. |
| 0 | 1853 |
* |
1854 |
* @since 2.0.4 |
|
1855 |
* |
|
| 5 | 1856 |
* @param string $actionurl URL to add nonce action. |
1857 |
* @param int|string $action Optional. Nonce action name. Default -1. |
|
1858 |
* @param string $name Optional. Nonce name. Default '_wpnonce'. |
|
1859 |
* @return string Escaped URL with nonce action added. |
|
| 0 | 1860 |
*/ |
1861 |
function wp_nonce_url( $actionurl, $action = -1, $name = '_wpnonce' ) {
|
|
1862 |
$actionurl = str_replace( '&', '&', $actionurl ); |
|
1863 |
return esc_html( add_query_arg( $name, wp_create_nonce( $action ), $actionurl ) ); |
|
1864 |
} |
|
1865 |
||
1866 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1867 |
* Retrieves or display nonce hidden field for forms. |
| 0 | 1868 |
* |
1869 |
* The nonce field is used to validate that the contents of the form came from |
|
1870 |
* the location on the current site and not somewhere else. The nonce does not |
|
1871 |
* offer absolute protection, but should protect against most cases. It is very |
|
1872 |
* important to use nonce field in forms. |
|
1873 |
* |
|
1874 |
* The $action and $name are optional, but if you want to have better security, |
|
1875 |
* it is strongly suggested to set those two parameters. It is easier to just |
|
1876 |
* call the function without any parameters, because validation of the nonce |
|
1877 |
* doesn't require any parameters, but since crackers know what the default is |
|
1878 |
* it won't be difficult for them to find a way around your nonce and cause |
|
1879 |
* damage. |
|
1880 |
* |
|
1881 |
* The input name will be whatever $name value you gave. The input value will be |
|
1882 |
* the nonce creation value. |
|
1883 |
* |
|
1884 |
* @since 2.0.4 |
|
1885 |
* |
|
| 5 | 1886 |
* @param int|string $action Optional. Action name. Default -1. |
1887 |
* @param string $name Optional. Nonce name. Default '_wpnonce'. |
|
1888 |
* @param bool $referer Optional. Whether to set the referer field for validation. Default true. |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1889 |
* @param bool $display Optional. Whether to display or return hidden form field. Default true. |
| 5 | 1890 |
* @return string Nonce field HTML markup. |
| 0 | 1891 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1892 |
function wp_nonce_field( $action = -1, $name = '_wpnonce', $referer = true, $display = true ) {
|
| 9 | 1893 |
$name = esc_attr( $name ); |
| 0 | 1894 |
$nonce_field = '<input type="hidden" id="' . $name . '" name="' . $name . '" value="' . wp_create_nonce( $action ) . '" />'; |
1895 |
||
| 9 | 1896 |
if ( $referer ) {
|
| 0 | 1897 |
$nonce_field .= wp_referer_field( false ); |
| 9 | 1898 |
} |
1899 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1900 |
if ( $display ) {
|
| 0 | 1901 |
echo $nonce_field; |
| 9 | 1902 |
} |
| 0 | 1903 |
|
1904 |
return $nonce_field; |
|
1905 |
} |
|
1906 |
||
1907 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1908 |
* Retrieves or displays referer hidden field for forms. |
| 0 | 1909 |
* |
1910 |
* The referer link is the current Request URI from the server super global. The |
|
1911 |
* input name is '_wp_http_referer', in case you wanted to check manually. |
|
1912 |
* |
|
1913 |
* @since 2.0.4 |
|
1914 |
* |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1915 |
* @param bool $display Optional. Whether to echo or return the referer field. Default true. |
| 5 | 1916 |
* @return string Referer field HTML markup. |
| 0 | 1917 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1918 |
function wp_referer_field( $display = true ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1919 |
$request_url = remove_query_arg( '_wp_http_referer' ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1920 |
$referer_field = '<input type="hidden" name="_wp_http_referer" value="' . esc_url( $request_url ) . '" />'; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1921 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1922 |
if ( $display ) {
|
| 0 | 1923 |
echo $referer_field; |
| 9 | 1924 |
} |
| 16 | 1925 |
|
| 0 | 1926 |
return $referer_field; |
1927 |
} |
|
1928 |
||
1929 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1930 |
* Retrieves or displays original referer hidden field for forms. |
| 0 | 1931 |
* |
1932 |
* The input name is '_wp_original_http_referer' and will be either the same |
|
| 5 | 1933 |
* value of wp_referer_field(), if that was posted already or it will be the |
1934 |
* current page, if it doesn't exist. |
|
1935 |
* |
|
| 0 | 1936 |
* @since 2.0.4 |
1937 |
* |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1938 |
* @param bool $display Optional. Whether to echo the original http referer. Default true. |
| 5 | 1939 |
* @param string $jump_back_to Optional. Can be 'previous' or page you want to jump back to. |
1940 |
* Default 'current'. |
|
| 0 | 1941 |
* @return string Original referer field. |
1942 |
*/ |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1943 |
function wp_original_referer_field( $display = true, $jump_back_to = 'current' ) {
|
| 16 | 1944 |
$ref = wp_get_original_referer(); |
1945 |
||
1946 |
if ( ! $ref ) {
|
|
1947 |
$ref = ( 'previous' === $jump_back_to ) ? wp_get_referer() : wp_unslash( $_SERVER['REQUEST_URI'] ); |
|
1948 |
} |
|
1949 |
||
| 0 | 1950 |
$orig_referer_field = '<input type="hidden" name="_wp_original_http_referer" value="' . esc_attr( $ref ) . '" />'; |
| 16 | 1951 |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1952 |
if ( $display ) {
|
| 0 | 1953 |
echo $orig_referer_field; |
| 9 | 1954 |
} |
| 16 | 1955 |
|
| 0 | 1956 |
return $orig_referer_field; |
1957 |
} |
|
1958 |
||
1959 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1960 |
* Retrieves referer from '_wp_http_referer' or HTTP referer. |
| 5 | 1961 |
* |
1962 |
* If it's the same as the current request URL, will return false. |
|
1963 |
* |
|
| 0 | 1964 |
* @since 2.0.4 |
1965 |
* |
|
| 16 | 1966 |
* @return string|false Referer URL on success, false on failure. |
| 0 | 1967 |
*/ |
1968 |
function wp_get_referer() {
|
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1969 |
// Return early if called before wp_validate_redirect() is defined. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1970 |
if ( ! function_exists( 'wp_validate_redirect' ) ) {
|
| 0 | 1971 |
return false; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1972 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1973 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1974 |
$ref = wp_get_raw_referer(); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1975 |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1976 |
if ( $ref && wp_unslash( $_SERVER['REQUEST_URI'] ) !== $ref |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1977 |
&& home_url() . wp_unslash( $_SERVER['REQUEST_URI'] ) !== $ref |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1978 |
) {
|
| 0 | 1979 |
return wp_validate_redirect( $ref, false ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1980 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1981 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1982 |
return false; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1983 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1984 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1985 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1986 |
* Retrieves unvalidated referer from the '_wp_http_referer' URL query variable or the HTTP referer. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1987 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1988 |
* If the value of the '_wp_http_referer' URL query variable is not a string then it will be ignored. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1989 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1990 |
* Do not use for redirects, use wp_get_referer() instead. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1991 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1992 |
* @since 4.5.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1993 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1994 |
* @return string|false Referer URL on success, false on failure. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1995 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1996 |
function wp_get_raw_referer() {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1997 |
if ( ! empty( $_REQUEST['_wp_http_referer'] ) && is_string( $_REQUEST['_wp_http_referer'] ) ) {
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1998 |
return wp_unslash( $_REQUEST['_wp_http_referer'] ); |
| 9 | 1999 |
} elseif ( ! empty( $_SERVER['HTTP_REFERER'] ) ) {
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2000 |
return wp_unslash( $_SERVER['HTTP_REFERER'] ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2001 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2002 |
|
| 0 | 2003 |
return false; |
2004 |
} |
|
2005 |
||
2006 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2007 |
* Retrieves original referer that was posted, if it exists. |
| 0 | 2008 |
* |
2009 |
* @since 2.0.4 |
|
2010 |
* |
|
| 16 | 2011 |
* @return string|false Original referer URL on success, false on failure. |
| 0 | 2012 |
*/ |
2013 |
function wp_get_original_referer() {
|
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2014 |
// Return early if called before wp_validate_redirect() is defined. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2015 |
if ( ! function_exists( 'wp_validate_redirect' ) ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2016 |
return false; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2017 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2018 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2019 |
if ( ! empty( $_REQUEST['_wp_original_http_referer'] ) ) {
|
| 0 | 2020 |
return wp_validate_redirect( wp_unslash( $_REQUEST['_wp_original_http_referer'] ), false ); |
| 9 | 2021 |
} |
| 16 | 2022 |
|
| 0 | 2023 |
return false; |
2024 |
} |
|
2025 |
||
2026 |
/** |
|
2027 |
* Recursive directory creation based on full path. |
|
2028 |
* |
|
2029 |
* Will attempt to set permissions on folders. |
|
2030 |
* |
|
2031 |
* @since 2.0.1 |
|
2032 |
* |
|
2033 |
* @param string $target Full path to attempt to create. |
|
2034 |
* @return bool Whether the path was created. True if path already exists. |
|
2035 |
*/ |
|
2036 |
function wp_mkdir_p( $target ) {
|
|
2037 |
$wrapper = null; |
|
2038 |
||
| 5 | 2039 |
// Strip the protocol. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2040 |
if ( wp_is_stream( $target ) ) {
|
| 0 | 2041 |
list( $wrapper, $target ) = explode( '://', $target, 2 ); |
2042 |
} |
|
2043 |
||
| 5 | 2044 |
// From php.net/mkdir user contributed notes. |
| 0 | 2045 |
$target = str_replace( '//', '/', $target ); |
2046 |
||
| 5 | 2047 |
// Put the wrapper back on the target. |
| 16 | 2048 |
if ( null !== $wrapper ) {
|
| 0 | 2049 |
$target = $wrapper . '://' . $target; |
2050 |
} |
|
2051 |
||
| 5 | 2052 |
/* |
2053 |
* Safe mode fails with a trailing slash under certain PHP versions. |
|
2054 |
* Use rtrim() instead of untrailingslashit to avoid formatting.php dependency. |
|
2055 |
*/ |
|
| 9 | 2056 |
$target = rtrim( $target, '/' ); |
2057 |
if ( empty( $target ) ) {
|
|
| 0 | 2058 |
$target = '/'; |
| 9 | 2059 |
} |
2060 |
||
2061 |
if ( file_exists( $target ) ) {
|
|
| 0 | 2062 |
return @is_dir( $target ); |
| 9 | 2063 |
} |
| 0 | 2064 |
|
| 13 | 2065 |
// Do not allow path traversals. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2066 |
if ( str_contains( $target, '../' ) || str_contains( $target, '..' . DIRECTORY_SEPARATOR ) ) {
|
| 13 | 2067 |
return false; |
2068 |
} |
|
2069 |
||
| 0 | 2070 |
// We need to find the permissions of the parent folder that exists and inherit that. |
2071 |
$target_parent = dirname( $target ); |
|
| 16 | 2072 |
while ( '.' !== $target_parent && ! is_dir( $target_parent ) && dirname( $target_parent ) !== $target_parent ) {
|
| 0 | 2073 |
$target_parent = dirname( $target_parent ); |
2074 |
} |
|
2075 |
||
2076 |
// Get the permission bits. |
|
| 16 | 2077 |
$stat = @stat( $target_parent ); |
2078 |
if ( $stat ) {
|
|
| 0 | 2079 |
$dir_perms = $stat['mode'] & 0007777; |
2080 |
} else {
|
|
2081 |
$dir_perms = 0777; |
|
2082 |
} |
|
2083 |
||
2084 |
if ( @mkdir( $target, $dir_perms, true ) ) {
|
|
| 5 | 2085 |
|
2086 |
/* |
|
2087 |
* If a umask is set that modifies $dir_perms, we'll have to re-set |
|
2088 |
* the $dir_perms correctly with chmod() |
|
2089 |
*/ |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2090 |
if ( ( $dir_perms & ~umask() ) !== $dir_perms ) {
|
| 5 | 2091 |
$folder_parts = explode( '/', substr( $target, strlen( $target_parent ) + 1 ) ); |
2092 |
for ( $i = 1, $c = count( $folder_parts ); $i <= $c; $i++ ) {
|
|
| 16 | 2093 |
chmod( $target_parent . '/' . implode( '/', array_slice( $folder_parts, 0, $i ) ), $dir_perms ); |
| 5 | 2094 |
} |
2095 |
} |
|
2096 |
||
| 0 | 2097 |
return true; |
2098 |
} |
|
2099 |
||
2100 |
return false; |
|
2101 |
} |
|
2102 |
||
2103 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2104 |
* Tests if a given filesystem path is absolute. |
| 5 | 2105 |
* |
2106 |
* For example, '/foo/bar', or 'c:\windows'. |
|
| 0 | 2107 |
* |
2108 |
* @since 2.5.0 |
|
2109 |
* |
|
| 5 | 2110 |
* @param string $path File path. |
| 0 | 2111 |
* @return bool True if path is absolute, false is not absolute. |
2112 |
*/ |
|
2113 |
function path_is_absolute( $path ) {
|
|
| 5 | 2114 |
/* |
| 9 | 2115 |
* Check to see if the path is a stream and check to see if its an actual |
2116 |
* path or file as realpath() does not support stream wrappers. |
|
2117 |
*/ |
|
2118 |
if ( wp_is_stream( $path ) && ( is_dir( $path ) || is_file( $path ) ) ) {
|
|
2119 |
return true; |
|
2120 |
} |
|
2121 |
||
2122 |
/* |
|
| 5 | 2123 |
* This is definitive if true but fails if $path does not exist or contains |
2124 |
* a symbolic link. |
|
2125 |
*/ |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2126 |
if ( realpath( $path ) === $path ) {
|
| 0 | 2127 |
return true; |
| 9 | 2128 |
} |
2129 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2130 |
if ( strlen( $path ) === 0 || '.' === $path[0] ) {
|
| 0 | 2131 |
return false; |
| 9 | 2132 |
} |
| 0 | 2133 |
|
| 5 | 2134 |
// Windows allows absolute paths like this. |
| 9 | 2135 |
if ( preg_match( '#^[a-zA-Z]:\\\\#', $path ) ) {
|
| 0 | 2136 |
return true; |
| 9 | 2137 |
} |
| 0 | 2138 |
|
| 5 | 2139 |
// A path starting with / or \ is absolute; anything else is relative. |
| 16 | 2140 |
return ( '/' === $path[0] || '\\' === $path[0] ); |
| 0 | 2141 |
} |
2142 |
||
2143 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2144 |
* Joins two filesystem paths together. |
| 5 | 2145 |
* |
2146 |
* For example, 'give me $path relative to $base'. If the $path is absolute, |
|
2147 |
* then it the full path is returned. |
|
| 0 | 2148 |
* |
2149 |
* @since 2.5.0 |
|
2150 |
* |
|
| 5 | 2151 |
* @param string $base Base path. |
2152 |
* @param string $path Path relative to $base. |
|
| 0 | 2153 |
* @return string The path with the base or absolute path. |
2154 |
*/ |
|
2155 |
function path_join( $base, $path ) {
|
|
| 9 | 2156 |
if ( path_is_absolute( $path ) ) {
|
| 0 | 2157 |
return $path; |
| 9 | 2158 |
} |
2159 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2160 |
return rtrim( $base, '/' ) . '/' . $path; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2161 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2162 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2163 |
/** |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2164 |
* Normalizes a filesystem path. |
| 5 | 2165 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2166 |
* On windows systems, replaces backslashes with forward slashes |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2167 |
* and forces upper-case drive letters. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2168 |
* Allows for two leading slashes for Windows network shares, but |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2169 |
* ensures that all other duplicate slashes are reduced to a single. |
| 5 | 2170 |
* |
2171 |
* @since 3.9.0 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2172 |
* @since 4.4.0 Ensures upper-case drive letters on Windows systems. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2173 |
* @since 4.5.0 Allows for Windows network shares. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2174 |
* @since 4.9.7 Allows for PHP file wrappers. |
| 5 | 2175 |
* |
2176 |
* @param string $path Path to normalize. |
|
2177 |
* @return string Normalized path. |
|
2178 |
*/ |
|
2179 |
function wp_normalize_path( $path ) {
|
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2180 |
$wrapper = ''; |
| 16 | 2181 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2182 |
if ( wp_is_stream( $path ) ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2183 |
list( $wrapper, $path ) = explode( '://', $path, 2 ); |
| 16 | 2184 |
|
2185 |
$wrapper .= '://'; |
|
2186 |
} |
|
2187 |
||
| 19 | 2188 |
// Standardize all paths to use '/'. |
| 5 | 2189 |
$path = str_replace( '\\', '/', $path ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2190 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2191 |
// Replace multiple slashes down to a singular, allowing for network shares having two slashes. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2192 |
$path = preg_replace( '|(?<=.)/+|', '/', $path ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2193 |
|
| 16 | 2194 |
// Windows paths should uppercase the drive letter. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2195 |
if ( ':' === substr( $path, 1, 1 ) ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2196 |
$path = ucfirst( $path ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2197 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2198 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2199 |
return $wrapper . $path; |
| 5 | 2200 |
} |
2201 |
||
2202 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2203 |
* Determines a writable directory for temporary files. |
| 5 | 2204 |
* |
2205 |
* Function's preference is the return value of sys_get_temp_dir(), |
|
| 0 | 2206 |
* followed by your PHP temporary upload directory, followed by WP_CONTENT_DIR, |
2207 |
* before finally defaulting to /tmp/ |
|
2208 |
* |
|
2209 |
* In the event that this function does not find a writable location, |
|
| 5 | 2210 |
* It may be overridden by the WP_TEMP_DIR constant in your wp-config.php file. |
| 0 | 2211 |
* |
2212 |
* @since 2.5.0 |
|
2213 |
* |
|
| 5 | 2214 |
* @return string Writable temporary directory. |
| 0 | 2215 |
*/ |
2216 |
function get_temp_dir() {
|
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2217 |
static $temp = ''; |
| 9 | 2218 |
if ( defined( 'WP_TEMP_DIR' ) ) {
|
2219 |
return trailingslashit( WP_TEMP_DIR ); |
|
2220 |
} |
|
2221 |
||
2222 |
if ( $temp ) {
|
|
| 5 | 2223 |
return trailingslashit( $temp ); |
| 9 | 2224 |
} |
2225 |
||
2226 |
if ( function_exists( 'sys_get_temp_dir' ) ) {
|
|
| 0 | 2227 |
$temp = sys_get_temp_dir(); |
| 9 | 2228 |
if ( @is_dir( $temp ) && wp_is_writable( $temp ) ) {
|
| 5 | 2229 |
return trailingslashit( $temp ); |
| 9 | 2230 |
} |
2231 |
} |
|
2232 |
||
2233 |
$temp = ini_get( 'upload_tmp_dir' ); |
|
2234 |
if ( @is_dir( $temp ) && wp_is_writable( $temp ) ) {
|
|
| 5 | 2235 |
return trailingslashit( $temp ); |
| 9 | 2236 |
} |
| 0 | 2237 |
|
2238 |
$temp = WP_CONTENT_DIR . '/'; |
|
| 9 | 2239 |
if ( is_dir( $temp ) && wp_is_writable( $temp ) ) {
|
| 0 | 2240 |
return $temp; |
| 9 | 2241 |
} |
| 0 | 2242 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2243 |
return '/tmp/'; |
| 0 | 2244 |
} |
2245 |
||
2246 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2247 |
* Determines if a directory is writable. |
| 0 | 2248 |
* |
| 5 | 2249 |
* This function is used to work around certain ACL issues in PHP primarily |
2250 |
* affecting Windows Servers. |
|
2251 |
* |
|
2252 |
* @since 3.6.0 |
|
| 0 | 2253 |
* |
2254 |
* @see win_is_writable() |
|
2255 |
* |
|
| 5 | 2256 |
* @param string $path Path to check for write-ability. |
2257 |
* @return bool Whether the path is writable. |
|
| 0 | 2258 |
*/ |
2259 |
function wp_is_writable( $path ) {
|
|
| 9 | 2260 |
if ( 'WIN' === strtoupper( substr( PHP_OS, 0, 3 ) ) ) {
|
| 0 | 2261 |
return win_is_writable( $path ); |
| 9 | 2262 |
} else {
|
| 0 | 2263 |
return @is_writable( $path ); |
| 9 | 2264 |
} |
| 0 | 2265 |
} |
2266 |
||
2267 |
/** |
|
2268 |
* Workaround for Windows bug in is_writable() function |
|
2269 |
* |
|
2270 |
* PHP has issues with Windows ACL's for determine if a |
|
2271 |
* directory is writable or not, this works around them by |
|
2272 |
* checking the ability to open files rather than relying |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2273 |
* upon PHP to interpret the OS ACL. |
| 0 | 2274 |
* |
2275 |
* @since 2.8.0 |
|
2276 |
* |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2277 |
* @see https://bugs.php.net/bug.php?id=27609 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2278 |
* @see https://bugs.php.net/bug.php?id=30931 |
| 5 | 2279 |
* |
2280 |
* @param string $path Windows path to check for write-ability. |
|
2281 |
* @return bool Whether the path is writable. |
|
| 0 | 2282 |
*/ |
2283 |
function win_is_writable( $path ) {
|
|
| 16 | 2284 |
if ( '/' === $path[ strlen( $path ) - 1 ] ) {
|
2285 |
// If it looks like a directory, check a random file within the directory. |
|
| 9 | 2286 |
return win_is_writable( $path . uniqid( mt_rand() ) . '.tmp' ); |
| 16 | 2287 |
} elseif ( is_dir( $path ) ) {
|
2288 |
// If it's a directory (and not a file), check a random file within the directory. |
|
| 0 | 2289 |
return win_is_writable( $path . '/' . uniqid( mt_rand() ) . '.tmp' ); |
| 5 | 2290 |
} |
| 16 | 2291 |
|
2292 |
// Check tmp file for read/write capabilities. |
|
| 9 | 2293 |
$should_delete_tmp_file = ! file_exists( $path ); |
| 16 | 2294 |
|
2295 |
$f = @fopen( $path, 'a' ); |
|
2296 |
if ( false === $f ) {
|
|
| 0 | 2297 |
return false; |
| 9 | 2298 |
} |
| 0 | 2299 |
fclose( $f ); |
| 16 | 2300 |
|
| 9 | 2301 |
if ( $should_delete_tmp_file ) {
|
| 0 | 2302 |
unlink( $path ); |
| 9 | 2303 |
} |
| 16 | 2304 |
|
| 0 | 2305 |
return true; |
2306 |
} |
|
2307 |
||
2308 |
/** |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2309 |
* Retrieves uploads directory information. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2310 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2311 |
* Same as wp_upload_dir() but "light weight" as it doesn't attempt to create the uploads directory. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2312 |
* Intended for use in themes, when only 'basedir' and 'baseurl' are needed, generally in all cases |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2313 |
* when not uploading files. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2314 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2315 |
* @since 4.5.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2316 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2317 |
* @see wp_upload_dir() |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2318 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2319 |
* @return array See wp_upload_dir() for description. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2320 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2321 |
function wp_get_upload_dir() {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2322 |
return wp_upload_dir( null, false ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2323 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2324 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2325 |
/** |
| 16 | 2326 |
* Returns an array containing the current upload directory's path and URL. |
| 0 | 2327 |
* |
2328 |
* Checks the 'upload_path' option, which should be from the web root folder, |
|
2329 |
* and if it isn't empty it will be used. If it is empty, then the path will be |
|
2330 |
* 'WP_CONTENT_DIR/uploads'. If the 'UPLOADS' constant is defined, then it will |
|
2331 |
* override the 'upload_path' option and 'WP_CONTENT_DIR/uploads' path. |
|
2332 |
* |
|
2333 |
* The upload URL path is set either by the 'upload_url_path' option or by using |
|
2334 |
* the 'WP_CONTENT_URL' constant and appending '/uploads' to the path. |
|
2335 |
* |
|
2336 |
* If the 'uploads_use_yearmonth_folders' is set to true (checkbox if checked in |
|
2337 |
* the administration settings panel), then the time will be used. The format |
|
2338 |
* will be year first and then month. |
|
2339 |
* |
|
2340 |
* If the path couldn't be created, then an error will be returned with the key |
|
2341 |
* 'error' containing the error message. The error suggests that the parent |
|
2342 |
* directory is not writable by the server. |
|
2343 |
* |
|
2344 |
* @since 2.0.0 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2345 |
* @uses _wp_upload_dir() |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2346 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2347 |
* @param string|null $time Optional. Time formatted in 'yyyy/mm'. Default null. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2348 |
* @param bool $create_dir Optional. Whether to check and create the uploads directory. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2349 |
* Default true for backward compatibility. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2350 |
* @param bool $refresh_cache Optional. Whether to refresh the cache. Default false. |
| 16 | 2351 |
* @return array {
|
2352 |
* Array of information about the upload directory. |
|
2353 |
* |
|
2354 |
* @type string $path Base directory and subdirectory or full path to upload directory. |
|
2355 |
* @type string $url Base URL and subdirectory or absolute URL to upload directory. |
|
2356 |
* @type string $subdir Subdirectory if uploads use year/month folders option is on. |
|
2357 |
* @type string $basedir Path without subdir. |
|
2358 |
* @type string $baseurl URL path without subdir. |
|
2359 |
* @type string|false $error False or error message. |
|
2360 |
* } |
|
| 0 | 2361 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2362 |
function wp_upload_dir( $time = null, $create_dir = true, $refresh_cache = false ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2363 |
static $cache = array(), $tested_paths = array(); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2364 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2365 |
$key = sprintf( '%d-%s', get_current_blog_id(), (string) $time ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2366 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2367 |
if ( $refresh_cache || empty( $cache[ $key ] ) ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2368 |
$cache[ $key ] = _wp_upload_dir( $time ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2369 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2370 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2371 |
/** |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2372 |
* Filters the uploads directory data. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2373 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2374 |
* @since 2.0.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2375 |
* |
| 16 | 2376 |
* @param array $uploads {
|
2377 |
* Array of information about the upload directory. |
|
2378 |
* |
|
2379 |
* @type string $path Base directory and subdirectory or full path to upload directory. |
|
2380 |
* @type string $url Base URL and subdirectory or absolute URL to upload directory. |
|
2381 |
* @type string $subdir Subdirectory if uploads use year/month folders option is on. |
|
2382 |
* @type string $basedir Path without subdir. |
|
2383 |
* @type string $baseurl URL path without subdir. |
|
2384 |
* @type string|false $error False or error message. |
|
2385 |
* } |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2386 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2387 |
$uploads = apply_filters( 'upload_dir', $cache[ $key ] ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2388 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2389 |
if ( $create_dir ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2390 |
$path = $uploads['path']; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2391 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2392 |
if ( array_key_exists( $path, $tested_paths ) ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2393 |
$uploads['error'] = $tested_paths[ $path ]; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2394 |
} else {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2395 |
if ( ! wp_mkdir_p( $path ) ) {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2396 |
if ( str_starts_with( $uploads['basedir'], ABSPATH ) ) {
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2397 |
$error_path = str_replace( ABSPATH, '', $uploads['basedir'] ) . $uploads['subdir']; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2398 |
} else {
|
| 9 | 2399 |
$error_path = wp_basename( $uploads['basedir'] ) . $uploads['subdir']; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2400 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2401 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2402 |
$uploads['error'] = sprintf( |
| 16 | 2403 |
/* translators: %s: Directory path. */ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2404 |
__( 'Unable to create directory %s. Is its parent directory writable by the server?' ), |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2405 |
esc_html( $error_path ) |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2406 |
); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2407 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2408 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2409 |
$tested_paths[ $path ] = $uploads['error']; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2410 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2411 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2412 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2413 |
return $uploads; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2414 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2415 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2416 |
/** |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2417 |
* A non-filtered, non-cached version of wp_upload_dir() that doesn't check the path. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2418 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2419 |
* @since 4.5.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2420 |
* @access private |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2421 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2422 |
* @param string|null $time Optional. Time formatted in 'yyyy/mm'. Default null. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2423 |
* @return array See wp_upload_dir() |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2424 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2425 |
function _wp_upload_dir( $time = null ) {
|
| 9 | 2426 |
$siteurl = get_option( 'siteurl' ); |
| 0 | 2427 |
$upload_path = trim( get_option( 'upload_path' ) ); |
2428 |
||
| 16 | 2429 |
if ( empty( $upload_path ) || 'wp-content/uploads' === $upload_path ) {
|
| 0 | 2430 |
$dir = WP_CONTENT_DIR . '/uploads'; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2431 |
} elseif ( ! str_starts_with( $upload_path, ABSPATH ) ) {
|
| 16 | 2432 |
// $dir is absolute, $upload_path is (maybe) relative to ABSPATH. |
| 0 | 2433 |
$dir = path_join( ABSPATH, $upload_path ); |
2434 |
} else {
|
|
2435 |
$dir = $upload_path; |
|
2436 |
} |
|
2437 |
||
| 16 | 2438 |
$url = get_option( 'upload_url_path' ); |
2439 |
if ( ! $url ) {
|
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2440 |
if ( empty( $upload_path ) || ( 'wp-content/uploads' === $upload_path ) || ( $upload_path === $dir ) ) {
|
| 0 | 2441 |
$url = WP_CONTENT_URL . '/uploads'; |
| 9 | 2442 |
} else {
|
| 0 | 2443 |
$url = trailingslashit( $siteurl ) . $upload_path; |
| 9 | 2444 |
} |
| 0 | 2445 |
} |
2446 |
||
| 5 | 2447 |
/* |
2448 |
* Honor the value of UPLOADS. This happens as long as ms-files rewriting is disabled. |
|
2449 |
* We also sometimes obey UPLOADS when rewriting is enabled -- see the next block. |
|
2450 |
*/ |
|
| 0 | 2451 |
if ( defined( 'UPLOADS' ) && ! ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) ) {
|
2452 |
$dir = ABSPATH . UPLOADS; |
|
2453 |
$url = trailingslashit( $siteurl ) . UPLOADS; |
|
2454 |
} |
|
2455 |
||
| 16 | 2456 |
// If multisite (and if not the main site in a post-MU network). |
| 0 | 2457 |
if ( is_multisite() && ! ( is_main_network() && is_main_site() && defined( 'MULTISITE' ) ) ) {
|
2458 |
||
2459 |
if ( ! get_site_option( 'ms_files_rewriting' ) ) {
|
|
| 5 | 2460 |
/* |
2461 |
* If ms-files rewriting is disabled (networks created post-3.5), it is fairly |
|
2462 |
* straightforward: Append sites/%d if we're not on the main site (for post-MU |
|
2463 |
* networks). (The extra directory prevents a four-digit ID from conflicting with |
|
2464 |
* a year-based directory for the main site. But if a MU-era network has disabled |
|
2465 |
* ms-files rewriting manually, they don't need the extra directory, as they never |
|
2466 |
* had wp-content/uploads for the main site.) |
|
2467 |
*/ |
|
| 0 | 2468 |
|
| 9 | 2469 |
if ( defined( 'MULTISITE' ) ) {
|
| 0 | 2470 |
$ms_dir = '/sites/' . get_current_blog_id(); |
| 9 | 2471 |
} else {
|
| 0 | 2472 |
$ms_dir = '/' . get_current_blog_id(); |
| 9 | 2473 |
} |
| 0 | 2474 |
|
2475 |
$dir .= $ms_dir; |
|
2476 |
$url .= $ms_dir; |
|
2477 |
||
2478 |
} elseif ( defined( 'UPLOADS' ) && ! ms_is_switched() ) {
|
|
| 5 | 2479 |
/* |
2480 |
* Handle the old-form ms-files.php rewriting if the network still has that enabled. |
|
2481 |
* When ms-files rewriting is enabled, then we only listen to UPLOADS when: |
|
2482 |
* 1) We are not on the main site in a post-MU network, as wp-content/uploads is used |
|
2483 |
* there, and |
|
2484 |
* 2) We are not switched, as ms_upload_constants() hardcodes these constants to reflect |
|
2485 |
* the original blog ID. |
|
2486 |
* |
|
2487 |
* Rather than UPLOADS, we actually use BLOGUPLOADDIR if it is set, as it is absolute. |
|
2488 |
* (And it will be set, see ms_upload_constants().) Otherwise, UPLOADS can be used, as |
|
2489 |
* as it is relative to ABSPATH. For the final piece: when UPLOADS is used with ms-files |
|
2490 |
* rewriting in multisite, the resulting URL is /files. (#WP22702 for background.) |
|
2491 |
*/ |
|
| 0 | 2492 |
|
| 9 | 2493 |
if ( defined( 'BLOGUPLOADDIR' ) ) {
|
| 0 | 2494 |
$dir = untrailingslashit( BLOGUPLOADDIR ); |
| 9 | 2495 |
} else {
|
| 0 | 2496 |
$dir = ABSPATH . UPLOADS; |
| 9 | 2497 |
} |
| 0 | 2498 |
$url = trailingslashit( $siteurl ) . 'files'; |
2499 |
} |
|
2500 |
} |
|
2501 |
||
2502 |
$basedir = $dir; |
|
2503 |
$baseurl = $url; |
|
2504 |
||
2505 |
$subdir = ''; |
|
2506 |
if ( get_option( 'uploads_use_yearmonth_folders' ) ) {
|
|
| 16 | 2507 |
// Generate the yearly and monthly directories. |
| 9 | 2508 |
if ( ! $time ) {
|
| 0 | 2509 |
$time = current_time( 'mysql' ); |
| 9 | 2510 |
} |
2511 |
$y = substr( $time, 0, 4 ); |
|
2512 |
$m = substr( $time, 5, 2 ); |
|
| 0 | 2513 |
$subdir = "/$y/$m"; |
2514 |
} |
|
2515 |
||
2516 |
$dir .= $subdir; |
|
2517 |
$url .= $subdir; |
|
2518 |
||
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2519 |
return array( |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2520 |
'path' => $dir, |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2521 |
'url' => $url, |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2522 |
'subdir' => $subdir, |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2523 |
'basedir' => $basedir, |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2524 |
'baseurl' => $baseurl, |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2525 |
'error' => false, |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2526 |
); |
| 0 | 2527 |
} |
2528 |
||
2529 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2530 |
* Gets a filename that is sanitized and unique for the given directory. |
| 0 | 2531 |
* |
2532 |
* If the filename is not unique, then a number will be added to the filename |
|
| 16 | 2533 |
* before the extension, and will continue adding numbers until the filename |
2534 |
* is unique. |
|
2535 |
* |
|
2536 |
* The callback function allows the caller to use their own method to create |
|
2537 |
* unique file names. If defined, the callback should take three arguments: |
|
2538 |
* - directory, base filename, and extension - and return a unique filename. |
|
| 0 | 2539 |
* |
2540 |
* @since 2.5.0 |
|
2541 |
* |
|
| 5 | 2542 |
* @param string $dir Directory. |
2543 |
* @param string $filename File name. |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2544 |
* @param callable $unique_filename_callback Callback. Default null. |
| 0 | 2545 |
* @return string New filename, if given wasn't unique. |
2546 |
*/ |
|
2547 |
function wp_unique_filename( $dir, $filename, $unique_filename_callback = null ) {
|
|
| 5 | 2548 |
// Sanitize the file name before we begin processing. |
| 9 | 2549 |
$filename = sanitize_file_name( $filename ); |
| 16 | 2550 |
$ext2 = null; |
| 0 | 2551 |
|
| 18 | 2552 |
// Initialize vars used in the wp_unique_filename filter. |
2553 |
$number = ''; |
|
2554 |
$alt_filenames = array(); |
|
2555 |
||
| 5 | 2556 |
// Separate the filename into a name and extension. |
| 9 | 2557 |
$ext = pathinfo( $filename, PATHINFO_EXTENSION ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2558 |
$name = pathinfo( $filename, PATHINFO_BASENAME ); |
| 16 | 2559 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2560 |
if ( $ext ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2561 |
$ext = '.' . $ext; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2562 |
} |
| 0 | 2563 |
|
| 5 | 2564 |
// Edge case: if file is named '.ext', treat as an empty name. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2565 |
if ( $name === $ext ) {
|
| 0 | 2566 |
$name = ''; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2567 |
} |
| 0 | 2568 |
|
| 5 | 2569 |
/* |
2570 |
* Increment the file number until we have a unique file to save in $dir. |
|
2571 |
* Use callback if supplied. |
|
2572 |
*/ |
|
| 0 | 2573 |
if ( $unique_filename_callback && is_callable( $unique_filename_callback ) ) {
|
2574 |
$filename = call_user_func( $unique_filename_callback, $dir, $name, $ext ); |
|
2575 |
} else {
|
|
| 18 | 2576 |
$fname = pathinfo( $filename, PATHINFO_FILENAME ); |
| 16 | 2577 |
|
2578 |
// Always append a number to file names that can potentially match image sub-size file names. |
|
2579 |
if ( $fname && preg_match( '/-(?:\d+x\d+|scaled|rotated)$/', $fname ) ) {
|
|
2580 |
$number = 1; |
|
2581 |
||
2582 |
// At this point the file name may not be unique. This is tested below and the $number is incremented. |
|
2583 |
$filename = str_replace( "{$fname}{$ext}", "{$fname}-{$number}{$ext}", $filename );
|
|
2584 |
} |
|
| 0 | 2585 |
|
| 19 | 2586 |
/* |
2587 |
* Get the mime type. Uploaded files were already checked with wp_check_filetype_and_ext() |
|
2588 |
* in _wp_handle_upload(). Using wp_check_filetype() would be sufficient here. |
|
2589 |
*/ |
|
| 18 | 2590 |
$file_type = wp_check_filetype( $filename ); |
2591 |
$mime_type = $file_type['type']; |
|
2592 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2593 |
$is_image = ( ! empty( $mime_type ) && str_starts_with( $mime_type, 'image/' ) ); |
| 18 | 2594 |
$upload_dir = wp_get_upload_dir(); |
2595 |
$lc_filename = null; |
|
2596 |
||
2597 |
$lc_ext = strtolower( $ext ); |
|
2598 |
$_dir = trailingslashit( $dir ); |
|
2599 |
||
| 19 | 2600 |
/* |
2601 |
* If the extension is uppercase add an alternate file name with lowercase extension. |
|
2602 |
* Both need to be tested for uniqueness as the extension will be changed to lowercase |
|
2603 |
* for better compatibility with different filesystems. Fixes an inconsistency in WP < 2.9 |
|
2604 |
* where uppercase extensions were allowed but image sub-sizes were created with |
|
2605 |
* lowercase extensions. |
|
2606 |
*/ |
|
| 18 | 2607 |
if ( $ext && $lc_ext !== $ext ) {
|
2608 |
$lc_filename = preg_replace( '|' . preg_quote( $ext ) . '$|', $lc_ext, $filename ); |
|
2609 |
} |
|
2610 |
||
| 19 | 2611 |
/* |
2612 |
* Increment the number added to the file name if there are any files in $dir |
|
2613 |
* whose names match one of the possible name variations. |
|
2614 |
*/ |
|
| 18 | 2615 |
while ( file_exists( $_dir . $filename ) || ( $lc_filename && file_exists( $_dir . $lc_filename ) ) ) {
|
2616 |
$new_number = (int) $number + 1; |
|
2617 |
||
2618 |
if ( $lc_filename ) {
|
|
| 19 | 2619 |
$lc_filename = str_replace( |
2620 |
array( "-{$number}{$lc_ext}", "{$number}{$lc_ext}" ),
|
|
2621 |
"-{$new_number}{$lc_ext}",
|
|
2622 |
$lc_filename |
|
2623 |
); |
|
| 0 | 2624 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2625 |
|
| 18 | 2626 |
if ( '' === "{$number}{$ext}" ) {
|
2627 |
$filename = "{$filename}-{$new_number}";
|
|
2628 |
} else {
|
|
| 19 | 2629 |
$filename = str_replace( |
2630 |
array( "-{$number}{$ext}", "{$number}{$ext}" ),
|
|
2631 |
"-{$new_number}{$ext}",
|
|
2632 |
$filename |
|
2633 |
); |
|
| 16 | 2634 |
} |
| 18 | 2635 |
|
2636 |
$number = $new_number; |
|
2637 |
} |
|
2638 |
||
2639 |
// Change the extension to lowercase if needed. |
|
2640 |
if ( $lc_filename ) {
|
|
2641 |
$filename = $lc_filename; |
|
| 0 | 2642 |
} |
2643 |
||
| 19 | 2644 |
/* |
2645 |
* Prevent collisions with existing file names that contain dimension-like strings |
|
2646 |
* (whether they are subsizes or originals uploaded prior to #42437). |
|
2647 |
*/ |
|
| 18 | 2648 |
|
2649 |
$files = array(); |
|
2650 |
$count = 10000; |
|
| 16 | 2651 |
|
2652 |
// The (resized) image files would have name and extension, and will be in the uploads dir. |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2653 |
if ( $name && $ext && @is_dir( $dir ) && str_contains( $dir, $upload_dir['basedir'] ) ) {
|
| 16 | 2654 |
/** |
2655 |
* Filters the file list used for calculating a unique filename for a newly added file. |
|
2656 |
* |
|
2657 |
* Returning an array from the filter will effectively short-circuit retrieval |
|
2658 |
* from the filesystem and return the passed value instead. |
|
2659 |
* |
|
2660 |
* @since 5.5.0 |
|
2661 |
* |
|
2662 |
* @param array|null $files The list of files to use for filename comparisons. |
|
2663 |
* Default null (to retrieve the list from the filesystem). |
|
2664 |
* @param string $dir The directory for the new file. |
|
2665 |
* @param string $filename The proposed filename for the new file. |
|
2666 |
*/ |
|
2667 |
$files = apply_filters( 'pre_wp_unique_filename_file_list', null, $dir, $filename ); |
|
2668 |
||
2669 |
if ( null === $files ) {
|
|
2670 |
// List of all files and directories contained in $dir. |
|
2671 |
$files = @scandir( $dir ); |
|
2672 |
} |
|
2673 |
||
2674 |
if ( ! empty( $files ) ) {
|
|
2675 |
// Remove "dot" dirs. |
|
2676 |
$files = array_diff( $files, array( '.', '..' ) ); |
|
2677 |
} |
|
2678 |
||
2679 |
if ( ! empty( $files ) ) {
|
|
| 18 | 2680 |
$count = count( $files ); |
| 16 | 2681 |
|
| 19 | 2682 |
/* |
2683 |
* Ensure this never goes into infinite loop as it uses pathinfo() and regex in the check, |
|
2684 |
* but string replacement for the changes. |
|
2685 |
*/ |
|
| 18 | 2686 |
$i = 0; |
| 16 | 2687 |
|
2688 |
while ( $i <= $count && _wp_check_existing_file_names( $filename, $files ) ) {
|
|
2689 |
$new_number = (int) $number + 1; |
|
| 18 | 2690 |
|
2691 |
// If $ext is uppercase it was replaced with the lowercase version after the previous loop. |
|
| 19 | 2692 |
$filename = str_replace( |
2693 |
array( "-{$number}{$lc_ext}", "{$number}{$lc_ext}" ),
|
|
2694 |
"-{$new_number}{$lc_ext}",
|
|
2695 |
$filename |
|
2696 |
); |
|
| 18 | 2697 |
|
2698 |
$number = $new_number; |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2699 |
++$i; |
| 18 | 2700 |
} |
2701 |
} |
|
2702 |
} |
|
2703 |
||
| 19 | 2704 |
/* |
2705 |
* Check if an image will be converted after uploading or some existing image sub-size file names may conflict |
|
2706 |
* when regenerated. If yes, ensure the new file name will be unique and will produce unique sub-sizes. |
|
2707 |
*/ |
|
| 18 | 2708 |
if ( $is_image ) {
|
| 19 | 2709 |
/** This filter is documented in wp-includes/class-wp-image-editor.php */ |
| 18 | 2710 |
$output_formats = apply_filters( 'image_editor_output_format', array(), $_dir . $filename, $mime_type ); |
2711 |
$alt_types = array(); |
|
2712 |
||
2713 |
if ( ! empty( $output_formats[ $mime_type ] ) ) {
|
|
2714 |
// The image will be converted to this format/mime type. |
|
2715 |
$alt_mime_type = $output_formats[ $mime_type ]; |
|
2716 |
||
2717 |
// Other types of images whose names may conflict if their sub-sizes are regenerated. |
|
2718 |
$alt_types = array_keys( array_intersect( $output_formats, array( $mime_type, $alt_mime_type ) ) ); |
|
2719 |
$alt_types[] = $alt_mime_type; |
|
2720 |
} elseif ( ! empty( $output_formats ) ) {
|
|
2721 |
$alt_types = array_keys( array_intersect( $output_formats, array( $mime_type ) ) ); |
|
2722 |
} |
|
2723 |
||
2724 |
// Remove duplicates and the original mime type. It will be added later if needed. |
|
2725 |
$alt_types = array_unique( array_diff( $alt_types, array( $mime_type ) ) ); |
|
2726 |
||
2727 |
foreach ( $alt_types as $alt_type ) {
|
|
2728 |
$alt_ext = wp_get_default_extension_for_mime_type( $alt_type ); |
|
2729 |
||
2730 |
if ( ! $alt_ext ) {
|
|
2731 |
continue; |
|
2732 |
} |
|
2733 |
||
2734 |
$alt_ext = ".{$alt_ext}";
|
|
2735 |
$alt_filename = preg_replace( '|' . preg_quote( $lc_ext ) . '$|', $alt_ext, $filename ); |
|
2736 |
||
2737 |
$alt_filenames[ $alt_ext ] = $alt_filename; |
|
2738 |
} |
|
2739 |
||
2740 |
if ( ! empty( $alt_filenames ) ) {
|
|
| 19 | 2741 |
/* |
2742 |
* Add the original filename. It needs to be checked again |
|
2743 |
* together with the alternate filenames when $number is incremented. |
|
2744 |
*/ |
|
| 18 | 2745 |
$alt_filenames[ $lc_ext ] = $filename; |
2746 |
||
2747 |
// Ensure no infinite loop. |
|
2748 |
$i = 0; |
|
2749 |
||
2750 |
while ( $i <= $count && _wp_check_alternate_file_names( $alt_filenames, $_dir, $files ) ) {
|
|
2751 |
$new_number = (int) $number + 1; |
|
2752 |
||
2753 |
foreach ( $alt_filenames as $alt_ext => $alt_filename ) {
|
|
| 19 | 2754 |
$alt_filenames[ $alt_ext ] = str_replace( |
2755 |
array( "-{$number}{$alt_ext}", "{$number}{$alt_ext}" ),
|
|
2756 |
"-{$new_number}{$alt_ext}",
|
|
2757 |
$alt_filename |
|
2758 |
); |
|
| 18 | 2759 |
} |
2760 |
||
| 19 | 2761 |
/* |
2762 |
* Also update the $number in (the output) $filename. |
|
2763 |
* If the extension was uppercase it was already replaced with the lowercase version. |
|
2764 |
*/ |
|
2765 |
$filename = str_replace( |
|
2766 |
array( "-{$number}{$lc_ext}", "{$number}{$lc_ext}" ),
|
|
2767 |
"-{$new_number}{$lc_ext}",
|
|
2768 |
$filename |
|
2769 |
); |
|
| 18 | 2770 |
|
2771 |
$number = $new_number; |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2772 |
++$i; |
| 16 | 2773 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2774 |
} |
| 0 | 2775 |
} |
2776 |
} |
|
2777 |
||
| 16 | 2778 |
/** |
2779 |
* Filters the result when generating a unique file name. |
|
2780 |
* |
|
2781 |
* @since 4.5.0 |
|
| 18 | 2782 |
* @since 5.8.1 The `$alt_filenames` and `$number` parameters were added. |
| 16 | 2783 |
* |
2784 |
* @param string $filename Unique file name. |
|
| 19 | 2785 |
* @param string $ext File extension. Example: ".png". |
| 16 | 2786 |
* @param string $dir Directory path. |
2787 |
* @param callable|null $unique_filename_callback Callback function that generates the unique file name. |
|
| 18 | 2788 |
* @param string[] $alt_filenames Array of alternate file names that were checked for collisions. |
2789 |
* @param int|string $number The highest number that was used to make the file name unique |
|
2790 |
* or an empty string if unused. |
|
| 16 | 2791 |
*/ |
| 18 | 2792 |
return apply_filters( 'wp_unique_filename', $filename, $ext, $dir, $unique_filename_callback, $alt_filenames, $number ); |
2793 |
} |
|
2794 |
||
2795 |
/** |
|
2796 |
* Helper function to test if each of an array of file names could conflict with existing files. |
|
2797 |
* |
|
2798 |
* @since 5.8.1 |
|
2799 |
* @access private |
|
2800 |
* |
|
2801 |
* @param string[] $filenames Array of file names to check. |
|
2802 |
* @param string $dir The directory containing the files. |
|
2803 |
* @param array $files An array of existing files in the directory. May be empty. |
|
2804 |
* @return bool True if the tested file name could match an existing file, false otherwise. |
|
2805 |
*/ |
|
2806 |
function _wp_check_alternate_file_names( $filenames, $dir, $files ) {
|
|
2807 |
foreach ( $filenames as $filename ) {
|
|
2808 |
if ( file_exists( $dir . $filename ) ) {
|
|
2809 |
return true; |
|
2810 |
} |
|
2811 |
||
2812 |
if ( ! empty( $files ) && _wp_check_existing_file_names( $filename, $files ) ) {
|
|
2813 |
return true; |
|
2814 |
} |
|
2815 |
} |
|
2816 |
||
2817 |
return false; |
|
| 0 | 2818 |
} |
2819 |
||
2820 |
/** |
|
| 16 | 2821 |
* Helper function to check if a file name could match an existing image sub-size file name. |
2822 |
* |
|
2823 |
* @since 5.3.1 |
|
2824 |
* @access private |
|
2825 |
* |
|
2826 |
* @param string $filename The file name to check. |
|
2827 |
* @param array $files An array of existing files in the directory. |
|
2828 |
* @return bool True if the tested file name could match an existing file, false otherwise. |
|
2829 |
*/ |
|
2830 |
function _wp_check_existing_file_names( $filename, $files ) {
|
|
2831 |
$fname = pathinfo( $filename, PATHINFO_FILENAME ); |
|
2832 |
$ext = pathinfo( $filename, PATHINFO_EXTENSION ); |
|
2833 |
||
2834 |
// Edge case, file names like `.ext`. |
|
2835 |
if ( empty( $fname ) ) {
|
|
2836 |
return false; |
|
2837 |
} |
|
2838 |
||
2839 |
if ( $ext ) {
|
|
2840 |
$ext = ".$ext"; |
|
2841 |
} |
|
2842 |
||
2843 |
$regex = '/^' . preg_quote( $fname ) . '-(?:\d+x\d+|scaled|rotated)' . preg_quote( $ext ) . '$/i'; |
|
2844 |
||
2845 |
foreach ( $files as $file ) {
|
|
2846 |
if ( preg_match( $regex, $file ) ) {
|
|
2847 |
return true; |
|
2848 |
} |
|
2849 |
} |
|
2850 |
||
2851 |
return false; |
|
2852 |
} |
|
2853 |
||
2854 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2855 |
* Creates a file in the upload folder with given content. |
| 0 | 2856 |
* |
2857 |
* If there is an error, then the key 'error' will exist with the error message. |
|
2858 |
* If success, then the key 'file' will have the unique file path, the 'url' key |
|
2859 |
* will have the link to the new file. and the 'error' key will be set to false. |
|
2860 |
* |
|
2861 |
* This function will not move an uploaded file to the upload folder. It will |
|
2862 |
* create a new file with the content in $bits parameter. If you move the upload |
|
2863 |
* file, read the content of the uploaded file, and then you can give the |
|
2864 |
* filename and content to this function, which will add it to the upload |
|
2865 |
* folder. |
|
2866 |
* |
|
2867 |
* The permissions will be set on the new file automatically by this function. |
|
2868 |
* |
|
2869 |
* @since 2.0.0 |
|
2870 |
* |
|
| 16 | 2871 |
* @param string $name Filename. |
2872 |
* @param null|string $deprecated Never used. Set to null. |
|
2873 |
* @param string $bits File content |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2874 |
* @param string|null $time Optional. Time formatted in 'yyyy/mm'. Default null. |
| 16 | 2875 |
* @return array {
|
2876 |
* Information about the newly-uploaded file. |
|
2877 |
* |
|
2878 |
* @type string $file Filename of the newly-uploaded file. |
|
2879 |
* @type string $url URL of the uploaded file. |
|
2880 |
* @type string $type File type. |
|
2881 |
* @type string|false $error Error message, if there has been an error. |
|
2882 |
* } |
|
| 0 | 2883 |
*/ |
2884 |
function wp_upload_bits( $name, $deprecated, $bits, $time = null ) {
|
|
| 9 | 2885 |
if ( ! empty( $deprecated ) ) {
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2886 |
_deprecated_argument( __FUNCTION__, '2.0.0' ); |
| 9 | 2887 |
} |
2888 |
||
2889 |
if ( empty( $name ) ) {
|
|
| 0 | 2890 |
return array( 'error' => __( 'Empty filename' ) ); |
| 9 | 2891 |
} |
| 0 | 2892 |
|
2893 |
$wp_filetype = wp_check_filetype( $name ); |
|
| 9 | 2894 |
if ( ! $wp_filetype['ext'] && ! current_user_can( 'unfiltered_upload' ) ) {
|
| 19 | 2895 |
return array( 'error' => __( 'Sorry, you are not allowed to upload this file type.' ) ); |
| 9 | 2896 |
} |
| 0 | 2897 |
|
2898 |
$upload = wp_upload_dir( $time ); |
|
2899 |
||
| 16 | 2900 |
if ( false !== $upload['error'] ) {
|
| 0 | 2901 |
return $upload; |
| 9 | 2902 |
} |
| 0 | 2903 |
|
| 5 | 2904 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2905 |
* Filters whether to treat the upload bits as an error. |
| 5 | 2906 |
* |
| 16 | 2907 |
* Returning a non-array from the filter will effectively short-circuit preparing the upload bits |
2908 |
* and return that value instead. An error message should be returned as a string. |
|
| 5 | 2909 |
* |
2910 |
* @since 3.0.0 |
|
2911 |
* |
|
| 16 | 2912 |
* @param array|string $upload_bits_error An array of upload bits data, or error message to return. |
| 5 | 2913 |
*/ |
| 9 | 2914 |
$upload_bits_error = apply_filters( |
2915 |
'wp_upload_bits', |
|
2916 |
array( |
|
2917 |
'name' => $name, |
|
2918 |
'bits' => $bits, |
|
2919 |
'time' => $time, |
|
2920 |
) |
|
2921 |
); |
|
2922 |
if ( ! is_array( $upload_bits_error ) ) {
|
|
2923 |
$upload['error'] = $upload_bits_error; |
|
| 0 | 2924 |
return $upload; |
2925 |
} |
|
2926 |
||
2927 |
$filename = wp_unique_filename( $upload['path'], $name ); |
|
2928 |
||
2929 |
$new_file = $upload['path'] . "/$filename"; |
|
2930 |
if ( ! wp_mkdir_p( dirname( $new_file ) ) ) {
|
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2931 |
if ( str_starts_with( $upload['basedir'], ABSPATH ) ) {
|
| 0 | 2932 |
$error_path = str_replace( ABSPATH, '', $upload['basedir'] ) . $upload['subdir']; |
| 9 | 2933 |
} else {
|
2934 |
$error_path = wp_basename( $upload['basedir'] ) . $upload['subdir']; |
|
2935 |
} |
|
| 0 | 2936 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2937 |
$message = sprintf( |
| 16 | 2938 |
/* translators: %s: Directory path. */ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2939 |
__( 'Unable to create directory %s. Is its parent directory writable by the server?' ), |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2940 |
$error_path |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2941 |
); |
| 0 | 2942 |
return array( 'error' => $message ); |
2943 |
} |
|
2944 |
||
| 16 | 2945 |
$ifp = @fopen( $new_file, 'wb' ); |
| 9 | 2946 |
if ( ! $ifp ) {
|
| 16 | 2947 |
return array( |
2948 |
/* translators: %s: File name. */ |
|
2949 |
'error' => sprintf( __( 'Could not write file %s' ), $new_file ), |
|
2950 |
); |
|
2951 |
} |
|
2952 |
||
2953 |
fwrite( $ifp, $bits ); |
|
| 0 | 2954 |
fclose( $ifp ); |
2955 |
clearstatcache(); |
|
2956 |
||
| 16 | 2957 |
// Set correct file permissions. |
| 9 | 2958 |
$stat = @ stat( dirname( $new_file ) ); |
| 0 | 2959 |
$perms = $stat['mode'] & 0007777; |
2960 |
$perms = $perms & 0000666; |
|
| 16 | 2961 |
chmod( $new_file, $perms ); |
| 0 | 2962 |
clearstatcache(); |
2963 |
||
| 16 | 2964 |
// Compute the URL. |
| 0 | 2965 |
$url = $upload['url'] . "/$filename"; |
2966 |
||
| 18 | 2967 |
if ( is_multisite() ) {
|
2968 |
clean_dirsize_cache( $new_file ); |
|
2969 |
} |
|
2970 |
||
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2971 |
/** This filter is documented in wp-admin/includes/file.php */ |
| 9 | 2972 |
return apply_filters( |
2973 |
'wp_handle_upload', |
|
2974 |
array( |
|
2975 |
'file' => $new_file, |
|
2976 |
'url' => $url, |
|
2977 |
'type' => $wp_filetype['type'], |
|
2978 |
'error' => false, |
|
2979 |
), |
|
2980 |
'sideload' |
|
2981 |
); |
|
| 0 | 2982 |
} |
2983 |
||
2984 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2985 |
* Retrieves the file type based on the extension name. |
| 0 | 2986 |
* |
2987 |
* @since 2.5.0 |
|
2988 |
* |
|
2989 |
* @param string $ext The extension to search. |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2990 |
* @return string|void The file type, example: audio, video, document, spreadsheet, etc. |
| 0 | 2991 |
*/ |
2992 |
function wp_ext2type( $ext ) {
|
|
2993 |
$ext = strtolower( $ext ); |
|
| 5 | 2994 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2995 |
$ext2type = wp_get_ext_types(); |
| 9 | 2996 |
foreach ( $ext2type as $type => $exts ) {
|
| 16 | 2997 |
if ( in_array( $ext, $exts, true ) ) {
|
| 0 | 2998 |
return $type; |
| 9 | 2999 |
} |
3000 |
} |
|
| 0 | 3001 |
} |
3002 |
||
3003 |
/** |
|
| 18 | 3004 |
* Returns first matched extension for the mime-type, |
3005 |
* as mapped from wp_get_mime_types(). |
|
3006 |
* |
|
3007 |
* @since 5.8.1 |
|
3008 |
* |
|
3009 |
* @param string $mime_type |
|
3010 |
* |
|
3011 |
* @return string|false |
|
3012 |
*/ |
|
3013 |
function wp_get_default_extension_for_mime_type( $mime_type ) {
|
|
3014 |
$extensions = explode( '|', array_search( $mime_type, wp_get_mime_types(), true ) ); |
|
3015 |
||
3016 |
if ( empty( $extensions[0] ) ) {
|
|
3017 |
return false; |
|
3018 |
} |
|
3019 |
||
3020 |
return $extensions[0]; |
|
3021 |
} |
|
3022 |
||
3023 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3024 |
* Retrieves the file type from the file name. |
| 0 | 3025 |
* |
3026 |
* You can optionally define the mime array, if needed. |
|
3027 |
* |
|
3028 |
* @since 2.0.4 |
|
3029 |
* |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3030 |
* @param string $filename File name or path. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3031 |
* @param string[]|null $mimes Optional. Array of allowed mime types keyed by their file extension regex. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3032 |
* Defaults to the result of get_allowed_mime_types(). |
| 16 | 3033 |
* @return array {
|
3034 |
* Values for the extension and mime type. |
|
3035 |
* |
|
3036 |
* @type string|false $ext File extension, or false if the file doesn't match a mime type. |
|
3037 |
* @type string|false $type File mime type, or false if the file doesn't match a mime type. |
|
3038 |
* } |
|
| 0 | 3039 |
*/ |
3040 |
function wp_check_filetype( $filename, $mimes = null ) {
|
|
| 9 | 3041 |
if ( empty( $mimes ) ) {
|
| 0 | 3042 |
$mimes = get_allowed_mime_types(); |
| 9 | 3043 |
} |
| 0 | 3044 |
$type = false; |
| 9 | 3045 |
$ext = false; |
| 0 | 3046 |
|
3047 |
foreach ( $mimes as $ext_preg => $mime_match ) {
|
|
3048 |
$ext_preg = '!\.(' . $ext_preg . ')$!i';
|
|
3049 |
if ( preg_match( $ext_preg, $filename, $ext_matches ) ) {
|
|
3050 |
$type = $mime_match; |
|
| 9 | 3051 |
$ext = $ext_matches[1]; |
| 0 | 3052 |
break; |
3053 |
} |
|
3054 |
} |
|
3055 |
||
3056 |
return compact( 'ext', 'type' ); |
|
3057 |
} |
|
3058 |
||
3059 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3060 |
* Attempts to determine the real file type of a file. |
| 5 | 3061 |
* |
| 0 | 3062 |
* If unable to, the file name extension will be used to determine type. |
3063 |
* |
|
3064 |
* If it's determined that the extension does not match the file's real type, |
|
3065 |
* then the "proper_filename" value will be set with a proper filename and extension. |
|
3066 |
* |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3067 |
* Currently this function only supports renaming images validated via wp_get_image_mime(). |
| 0 | 3068 |
* |
3069 |
* @since 3.0.0 |
|
3070 |
* |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3071 |
* @param string $file Full path to the file. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3072 |
* @param string $filename The name of the file (may differ from $file due to $file being |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3073 |
* in a tmp directory). |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3074 |
* @param string[]|null $mimes Optional. Array of allowed mime types keyed by their file extension regex. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3075 |
* Defaults to the result of get_allowed_mime_types(). |
| 16 | 3076 |
* @return array {
|
3077 |
* Values for the extension, mime type, and corrected filename. |
|
3078 |
* |
|
3079 |
* @type string|false $ext File extension, or false if the file doesn't match a mime type. |
|
3080 |
* @type string|false $type File mime type, or false if the file doesn't match a mime type. |
|
3081 |
* @type string|false $proper_filename File name with its correct extension, or false if it cannot be determined. |
|
3082 |
* } |
|
| 0 | 3083 |
*/ |
3084 |
function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) {
|
|
3085 |
$proper_filename = false; |
|
3086 |
||
| 16 | 3087 |
// Do basic extension validation and MIME mapping. |
| 0 | 3088 |
$wp_filetype = wp_check_filetype( $filename, $mimes ); |
| 9 | 3089 |
$ext = $wp_filetype['ext']; |
3090 |
$type = $wp_filetype['type']; |
|
| 0 | 3091 |
|
| 16 | 3092 |
// We can't do any further validation without a file to work with. |
| 5 | 3093 |
if ( ! file_exists( $file ) ) {
|
| 0 | 3094 |
return compact( 'ext', 'type', 'proper_filename' ); |
| 5 | 3095 |
} |
| 0 | 3096 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3097 |
$real_mime = false; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3098 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3099 |
// Validate image types. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3100 |
if ( $type && str_starts_with( $type, 'image/' ) ) {
|
| 0 | 3101 |
|
| 16 | 3102 |
// Attempt to figure out what type of image it actually is. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3103 |
$real_mime = wp_get_image_mime( $file ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3104 |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3105 |
if ( $real_mime && $real_mime !== $type ) {
|
| 5 | 3106 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3107 |
* Filters the list mapping image mime types to their respective extensions. |
| 5 | 3108 |
* |
3109 |
* @since 3.0.0 |
|
3110 |
* |
|
| 16 | 3111 |
* @param array $mime_to_ext Array of image mime types and their matching extensions. |
| 5 | 3112 |
*/ |
| 9 | 3113 |
$mime_to_ext = apply_filters( |
3114 |
'getimagesize_mimes_to_exts', |
|
3115 |
array( |
|
3116 |
'image/jpeg' => 'jpg', |
|
3117 |
'image/png' => 'png', |
|
3118 |
'image/gif' => 'gif', |
|
3119 |
'image/bmp' => 'bmp', |
|
3120 |
'image/tiff' => 'tif', |
|
| 18 | 3121 |
'image/webp' => 'webp', |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3122 |
'image/avif' => 'avif', |
| 9 | 3123 |
) |
3124 |
); |
|
| 0 | 3125 |
|
| 16 | 3126 |
// Replace whatever is after the last period in the filename with the correct extension. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3127 |
if ( ! empty( $mime_to_ext[ $real_mime ] ) ) {
|
| 0 | 3128 |
$filename_parts = explode( '.', $filename ); |
3129 |
array_pop( $filename_parts ); |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3130 |
$filename_parts[] = $mime_to_ext[ $real_mime ]; |
| 9 | 3131 |
$new_filename = implode( '.', $filename_parts ); |
| 0 | 3132 |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3133 |
if ( $new_filename !== $filename ) {
|
| 16 | 3134 |
$proper_filename = $new_filename; // Mark that it changed. |
| 5 | 3135 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3136 |
|
| 16 | 3137 |
// Redefine the extension / MIME. |
| 0 | 3138 |
$wp_filetype = wp_check_filetype( $new_filename, $mimes ); |
| 9 | 3139 |
$ext = $wp_filetype['ext']; |
3140 |
$type = $wp_filetype['type']; |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3141 |
} else {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3142 |
// Reset $real_mime and try validating again. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3143 |
$real_mime = false; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3144 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3145 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3146 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3147 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3148 |
// Validate files that didn't get validated during previous checks. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3149 |
if ( $type && ! $real_mime && extension_loaded( 'fileinfo' ) ) {
|
| 9 | 3150 |
$finfo = finfo_open( FILEINFO_MIME_TYPE ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3151 |
$real_mime = finfo_file( $finfo, $file ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3152 |
finfo_close( $finfo ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3153 |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3154 |
$google_docs_types = array( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3155 |
'application/vnd.openxmlformats-officedocument.wordprocessingml.document', |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3156 |
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3157 |
); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3158 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3159 |
foreach ( $google_docs_types as $google_docs_type ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3160 |
/* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3161 |
* finfo_file() can return duplicate mime type for Google docs, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3162 |
* this conditional reduces it to a single instance. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3163 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3164 |
* @see https://bugs.php.net/bug.php?id=77784 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3165 |
* @see https://core.trac.wordpress.org/ticket/57898 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3166 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3167 |
if ( 2 === substr_count( $real_mime, $google_docs_type ) ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3168 |
$real_mime = $google_docs_type; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3169 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3170 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3171 |
|
| 16 | 3172 |
// fileinfo often misidentifies obscure files as one of these types. |
| 9 | 3173 |
$nonspecific_types = array( |
3174 |
'application/octet-stream', |
|
3175 |
'application/encrypted', |
|
3176 |
'application/CDFV2-encrypted', |
|
3177 |
'application/zip', |
|
3178 |
); |
|
3179 |
||
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3180 |
/* |
| 9 | 3181 |
* If $real_mime doesn't match the content type we're expecting from the file's extension, |
3182 |
* we need to do some additional vetting. Media types and those listed in $nonspecific_types are |
|
3183 |
* allowed some leeway, but anything else must exactly match the real content type. |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3184 |
*/ |
| 9 | 3185 |
if ( in_array( $real_mime, $nonspecific_types, true ) ) {
|
3186 |
// File is a non-specific binary type. That's ok if it's a type that generally tends to be binary. |
|
| 16 | 3187 |
if ( ! in_array( substr( $type, 0, strcspn( $type, '/' ) ), array( 'application', 'video', 'audio' ), true ) ) {
|
3188 |
$type = false; |
|
3189 |
$ext = false; |
|
| 9 | 3190 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3191 |
} elseif ( str_starts_with( $real_mime, 'video/' ) || str_starts_with( $real_mime, 'audio/' ) ) {
|
| 9 | 3192 |
/* |
3193 |
* For these types, only the major type must match the real value. |
|
3194 |
* This means that common mismatches are forgiven: application/vnd.apple.numbers is often misidentified as application/zip, |
|
3195 |
* and some media files are commonly named with the wrong extension (.mov instead of .mp4) |
|
3196 |
*/ |
|
3197 |
if ( substr( $real_mime, 0, strcspn( $real_mime, '/' ) ) !== substr( $type, 0, strcspn( $type, '/' ) ) ) {
|
|
| 16 | 3198 |
$type = false; |
3199 |
$ext = false; |
|
| 0 | 3200 |
} |
| 9 | 3201 |
} elseif ( 'text/plain' === $real_mime ) {
|
3202 |
// A few common file types are occasionally detected as text/plain; allow those. |
|
3203 |
if ( ! in_array( |
|
3204 |
$type, |
|
3205 |
array( |
|
3206 |
'text/plain', |
|
3207 |
'text/csv', |
|
| 18 | 3208 |
'application/csv', |
| 9 | 3209 |
'text/richtext', |
3210 |
'text/tsv', |
|
3211 |
'text/vtt', |
|
| 16 | 3212 |
), |
3213 |
true |
|
| 9 | 3214 |
) |
3215 |
) {
|
|
| 16 | 3216 |
$type = false; |
3217 |
$ext = false; |
|
| 9 | 3218 |
} |
| 18 | 3219 |
} elseif ( 'application/csv' === $real_mime ) {
|
3220 |
// Special casing for CSV files. |
|
3221 |
if ( ! in_array( |
|
3222 |
$type, |
|
3223 |
array( |
|
3224 |
'text/csv', |
|
3225 |
'text/plain', |
|
3226 |
'application/csv', |
|
3227 |
), |
|
3228 |
true |
|
3229 |
) |
|
3230 |
) {
|
|
3231 |
$type = false; |
|
3232 |
$ext = false; |
|
3233 |
} |
|
| 9 | 3234 |
} elseif ( 'text/rtf' === $real_mime ) {
|
3235 |
// Special casing for RTF files. |
|
3236 |
if ( ! in_array( |
|
3237 |
$type, |
|
3238 |
array( |
|
3239 |
'text/rtf', |
|
3240 |
'text/plain', |
|
3241 |
'application/rtf', |
|
| 16 | 3242 |
), |
3243 |
true |
|
| 9 | 3244 |
) |
3245 |
) {
|
|
| 16 | 3246 |
$type = false; |
3247 |
$ext = false; |
|
| 9 | 3248 |
} |
3249 |
} else {
|
|
3250 |
if ( $type !== $real_mime ) {
|
|
3251 |
/* |
|
3252 |
* Everything else including image/* and application/*: |
|
3253 |
* If the real content type doesn't match the file extension, assume it's dangerous. |
|
3254 |
*/ |
|
| 16 | 3255 |
$type = false; |
3256 |
$ext = false; |
|
| 9 | 3257 |
} |
3258 |
} |
|
3259 |
} |
|
3260 |
||
| 16 | 3261 |
// The mime type must be allowed. |
| 9 | 3262 |
if ( $type ) {
|
3263 |
$allowed = get_allowed_mime_types(); |
|
3264 |
||
| 16 | 3265 |
if ( ! in_array( $type, $allowed, true ) ) {
|
3266 |
$type = false; |
|
3267 |
$ext = false; |
|
| 0 | 3268 |
} |
3269 |
} |
|
3270 |
||
| 5 | 3271 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3272 |
* Filters the "real" file type of the given file. |
| 5 | 3273 |
* |
3274 |
* @since 3.0.0 |
|
| 9 | 3275 |
* @since 5.1.0 The $real_mime parameter was added. |
| 5 | 3276 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3277 |
* @param array $wp_check_filetype_and_ext {
|
| 16 | 3278 |
* Values for the extension, mime type, and corrected filename. |
3279 |
* |
|
3280 |
* @type string|false $ext File extension, or false if the file doesn't match a mime type. |
|
3281 |
* @type string|false $type File mime type, or false if the file doesn't match a mime type. |
|
3282 |
* @type string|false $proper_filename File name with its correct extension, or false if it cannot be determined. |
|
3283 |
* } |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3284 |
* @param string $file Full path to the file. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3285 |
* @param string $filename The name of the file (may differ from $file due to |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3286 |
* $file being in a tmp directory). |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3287 |
* @param string[]|null $mimes Array of mime types keyed by their file extension regex, or null if |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3288 |
* none were provided. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3289 |
* @param string|false $real_mime The actual mime type or false if the type cannot be determined. |
| 5 | 3290 |
*/ |
| 9 | 3291 |
return apply_filters( 'wp_check_filetype_and_ext', compact( 'ext', 'type', 'proper_filename' ), $file, $filename, $mimes, $real_mime ); |
| 0 | 3292 |
} |
3293 |
||
3294 |
/** |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3295 |
* Returns the real mime type of an image file. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3296 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3297 |
* This depends on exif_imagetype() or getimagesize() to determine real mime types. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3298 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3299 |
* @since 4.7.1 |
| 18 | 3300 |
* @since 5.8.0 Added support for WebP images. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3301 |
* @since 6.5.0 Added support for AVIF images. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3302 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3303 |
* @param string $file Full path to the file. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3304 |
* @return string|false The actual mime type or false if the type cannot be determined. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3305 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3306 |
function wp_get_image_mime( $file ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3307 |
/* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3308 |
* Use exif_imagetype() to check the mimetype if available or fall back to |
| 19 | 3309 |
* getimagesize() if exif isn't available. If either function throws an Exception |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3310 |
* we assume the file could not be validated. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3311 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3312 |
try {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3313 |
if ( is_callable( 'exif_imagetype' ) ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3314 |
$imagetype = exif_imagetype( $file ); |
| 9 | 3315 |
$mime = ( $imagetype ) ? image_type_to_mime_type( $imagetype ) : false; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3316 |
} elseif ( function_exists( 'getimagesize' ) ) {
|
| 18 | 3317 |
// Don't silence errors when in debug mode, unless running unit tests. |
3318 |
if ( defined( 'WP_DEBUG' ) && WP_DEBUG |
|
3319 |
&& ! defined( 'WP_RUN_CORE_TESTS' ) |
|
3320 |
) {
|
|
3321 |
// Not using wp_getimagesize() here to avoid an infinite loop. |
|
3322 |
$imagesize = getimagesize( $file ); |
|
3323 |
} else {
|
|
3324 |
$imagesize = @getimagesize( $file ); |
|
3325 |
} |
|
3326 |
||
3327 |
$mime = ( isset( $imagesize['mime'] ) ) ? $imagesize['mime'] : false; |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3328 |
} else {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3329 |
$mime = false; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3330 |
} |
| 18 | 3331 |
|
3332 |
if ( false !== $mime ) {
|
|
3333 |
return $mime; |
|
3334 |
} |
|
3335 |
||
| 19 | 3336 |
$magic = file_get_contents( $file, false, null, 0, 12 ); |
3337 |
||
| 18 | 3338 |
if ( false === $magic ) {
|
3339 |
return false; |
|
3340 |
} |
|
3341 |
||
3342 |
/* |
|
3343 |
* Add WebP fallback detection when image library doesn't support WebP. |
|
3344 |
* Note: detection values come from LibWebP, see |
|
3345 |
* https://github.com/webmproject/libwebp/blob/master/imageio/image_dec.c#L30 |
|
3346 |
*/ |
|
3347 |
$magic = bin2hex( $magic ); |
|
3348 |
if ( |
|
3349 |
// RIFF. |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3350 |
( str_starts_with( $magic, '52494646' ) ) && |
| 18 | 3351 |
// WEBP. |
3352 |
( 16 === strpos( $magic, '57454250' ) ) |
|
3353 |
) {
|
|
3354 |
$mime = 'image/webp'; |
|
3355 |
} |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3356 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3357 |
/** |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3358 |
* Add AVIF fallback detection when image library doesn't support AVIF. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3359 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3360 |
* Detection based on section 4.3.1 File-type box definition of the ISO/IEC 14496-12 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3361 |
* specification and the AV1-AVIF spec, see https://aomediacodec.github.io/av1-avif/v1.1.0.html#brands. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3362 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3363 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3364 |
// Divide the header string into 4 byte groups. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3365 |
$magic = str_split( $magic, 8 ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3366 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3367 |
if ( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3368 |
isset( $magic[1] ) && |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3369 |
isset( $magic[2] ) && |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3370 |
'ftyp' === hex2bin( $magic[1] ) && |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3371 |
( 'avif' === hex2bin( $magic[2] ) || 'avis' === hex2bin( $magic[2] ) ) |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3372 |
) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3373 |
$mime = 'image/avif'; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3374 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3375 |
} catch ( Exception $e ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3376 |
$mime = false; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3377 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3378 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3379 |
return $mime; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3380 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3381 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3382 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3383 |
* Retrieves the list of mime types and file extensions. |
| 0 | 3384 |
* |
3385 |
* @since 3.5.0 |
|
| 16 | 3386 |
* @since 4.2.0 Support was added for GIMP (.xcf) files. |
3387 |
* @since 4.9.2 Support was added for Flac (.flac) files. |
|
3388 |
* @since 4.9.6 Support was added for AAC (.aac) files. |
|
3389 |
* |
|
3390 |
* @return string[] Array of mime types keyed by the file extension regex corresponding to those types. |
|
| 0 | 3391 |
*/ |
3392 |
function wp_get_mime_types() {
|
|
| 5 | 3393 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3394 |
* Filters the list of mime types and file extensions. |
| 5 | 3395 |
* |
3396 |
* This filter should be used to add, not remove, mime types. To remove |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3397 |
* mime types, use the {@see 'upload_mimes'} filter.
|
| 5 | 3398 |
* |
3399 |
* @since 3.5.0 |
|
3400 |
* |
|
| 16 | 3401 |
* @param string[] $wp_get_mime_types Mime types keyed by the file extension regex |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3402 |
* corresponding to those types. |
| 5 | 3403 |
*/ |
| 9 | 3404 |
return apply_filters( |
3405 |
'mime_types', |
|
3406 |
array( |
|
3407 |
// Image formats. |
|
3408 |
'jpg|jpeg|jpe' => 'image/jpeg', |
|
3409 |
'gif' => 'image/gif', |
|
3410 |
'png' => 'image/png', |
|
3411 |
'bmp' => 'image/bmp', |
|
3412 |
'tiff|tif' => 'image/tiff', |
|
| 18 | 3413 |
'webp' => 'image/webp', |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3414 |
'avif' => 'image/avif', |
| 9 | 3415 |
'ico' => 'image/x-icon', |
| 16 | 3416 |
'heic' => 'image/heic', |
| 9 | 3417 |
// Video formats. |
3418 |
'asf|asx' => 'video/x-ms-asf', |
|
3419 |
'wmv' => 'video/x-ms-wmv', |
|
3420 |
'wmx' => 'video/x-ms-wmx', |
|
3421 |
'wm' => 'video/x-ms-wm', |
|
3422 |
'avi' => 'video/avi', |
|
3423 |
'divx' => 'video/divx', |
|
3424 |
'flv' => 'video/x-flv', |
|
3425 |
'mov|qt' => 'video/quicktime', |
|
3426 |
'mpeg|mpg|mpe' => 'video/mpeg', |
|
3427 |
'mp4|m4v' => 'video/mp4', |
|
3428 |
'ogv' => 'video/ogg', |
|
3429 |
'webm' => 'video/webm', |
|
3430 |
'mkv' => 'video/x-matroska', |
|
| 16 | 3431 |
'3gp|3gpp' => 'video/3gpp', // Can also be audio. |
3432 |
'3g2|3gp2' => 'video/3gpp2', // Can also be audio. |
|
| 9 | 3433 |
// Text formats. |
3434 |
'txt|asc|c|cc|h|srt' => 'text/plain', |
|
3435 |
'csv' => 'text/csv', |
|
3436 |
'tsv' => 'text/tab-separated-values', |
|
3437 |
'ics' => 'text/calendar', |
|
3438 |
'rtx' => 'text/richtext', |
|
3439 |
'css' => 'text/css', |
|
3440 |
'htm|html' => 'text/html', |
|
3441 |
'vtt' => 'text/vtt', |
|
3442 |
'dfxp' => 'application/ttaf+xml', |
|
3443 |
// Audio formats. |
|
3444 |
'mp3|m4a|m4b' => 'audio/mpeg', |
|
3445 |
'aac' => 'audio/aac', |
|
3446 |
'ra|ram' => 'audio/x-realaudio', |
|
3447 |
'wav' => 'audio/wav', |
|
3448 |
'ogg|oga' => 'audio/ogg', |
|
3449 |
'flac' => 'audio/flac', |
|
3450 |
'mid|midi' => 'audio/midi', |
|
3451 |
'wma' => 'audio/x-ms-wma', |
|
3452 |
'wax' => 'audio/x-ms-wax', |
|
3453 |
'mka' => 'audio/x-matroska', |
|
3454 |
// Misc application formats. |
|
3455 |
'rtf' => 'application/rtf', |
|
3456 |
'js' => 'application/javascript', |
|
3457 |
'pdf' => 'application/pdf', |
|
3458 |
'swf' => 'application/x-shockwave-flash', |
|
3459 |
'class' => 'application/java', |
|
3460 |
'tar' => 'application/x-tar', |
|
3461 |
'zip' => 'application/zip', |
|
3462 |
'gz|gzip' => 'application/x-gzip', |
|
3463 |
'rar' => 'application/rar', |
|
3464 |
'7z' => 'application/x-7z-compressed', |
|
3465 |
'exe' => 'application/x-msdownload', |
|
3466 |
'psd' => 'application/octet-stream', |
|
3467 |
'xcf' => 'application/octet-stream', |
|
3468 |
// MS Office formats. |
|
3469 |
'doc' => 'application/msword', |
|
3470 |
'pot|pps|ppt' => 'application/vnd.ms-powerpoint', |
|
3471 |
'wri' => 'application/vnd.ms-write', |
|
3472 |
'xla|xls|xlt|xlw' => 'application/vnd.ms-excel', |
|
3473 |
'mdb' => 'application/vnd.ms-access', |
|
3474 |
'mpp' => 'application/vnd.ms-project', |
|
3475 |
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', |
|
3476 |
'docm' => 'application/vnd.ms-word.document.macroEnabled.12', |
|
3477 |
'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template', |
|
3478 |
'dotm' => 'application/vnd.ms-word.template.macroEnabled.12', |
|
3479 |
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', |
|
3480 |
'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12', |
|
3481 |
'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12', |
|
3482 |
'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template', |
|
3483 |
'xltm' => 'application/vnd.ms-excel.template.macroEnabled.12', |
|
3484 |
'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12', |
|
3485 |
'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', |
|
3486 |
'pptm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12', |
|
3487 |
'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', |
|
3488 |
'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12', |
|
3489 |
'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template', |
|
3490 |
'potm' => 'application/vnd.ms-powerpoint.template.macroEnabled.12', |
|
3491 |
'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12', |
|
3492 |
'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide', |
|
3493 |
'sldm' => 'application/vnd.ms-powerpoint.slide.macroEnabled.12', |
|
3494 |
'onetoc|onetoc2|onetmp|onepkg' => 'application/onenote', |
|
3495 |
'oxps' => 'application/oxps', |
|
3496 |
'xps' => 'application/vnd.ms-xpsdocument', |
|
3497 |
// OpenOffice formats. |
|
3498 |
'odt' => 'application/vnd.oasis.opendocument.text', |
|
3499 |
'odp' => 'application/vnd.oasis.opendocument.presentation', |
|
3500 |
'ods' => 'application/vnd.oasis.opendocument.spreadsheet', |
|
3501 |
'odg' => 'application/vnd.oasis.opendocument.graphics', |
|
3502 |
'odc' => 'application/vnd.oasis.opendocument.chart', |
|
3503 |
'odb' => 'application/vnd.oasis.opendocument.database', |
|
3504 |
'odf' => 'application/vnd.oasis.opendocument.formula', |
|
3505 |
// WordPerfect formats. |
|
3506 |
'wp|wpd' => 'application/wordperfect', |
|
3507 |
// iWork formats. |
|
3508 |
'key' => 'application/vnd.apple.keynote', |
|
3509 |
'numbers' => 'application/vnd.apple.numbers', |
|
3510 |
'pages' => 'application/vnd.apple.pages', |
|
3511 |
) |
|
3512 |
); |
|
| 0 | 3513 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3514 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3515 |
/** |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3516 |
* Retrieves the list of common file extensions and their types. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3517 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3518 |
* @since 4.6.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3519 |
* |
| 16 | 3520 |
* @return array[] Multi-dimensional array of file extensions types keyed by the type of file. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3521 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3522 |
function wp_get_ext_types() {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3523 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3524 |
/** |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3525 |
* Filters file type based on the extension name. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3526 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3527 |
* @since 2.5.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3528 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3529 |
* @see wp_ext2type() |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3530 |
* |
| 16 | 3531 |
* @param array[] $ext2type Multi-dimensional array of file extensions types keyed by the type of file. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3532 |
*/ |
| 9 | 3533 |
return apply_filters( |
3534 |
'ext2type', |
|
3535 |
array( |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3536 |
'image' => array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico', 'heic', 'webp', 'avif' ), |
| 9 | 3537 |
'audio' => array( 'aac', 'ac3', 'aif', 'aiff', 'flac', 'm3a', 'm4a', 'm4b', 'mka', 'mp1', 'mp2', 'mp3', 'ogg', 'oga', 'ram', 'wav', 'wma' ), |
3538 |
'video' => array( '3g2', '3gp', '3gpp', 'asf', 'avi', 'divx', 'dv', 'flv', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'mpv', 'ogm', 'ogv', 'qt', 'rm', 'vob', 'wmv' ), |
|
3539 |
'document' => array( 'doc', 'docx', 'docm', 'dotm', 'odt', 'pages', 'pdf', 'xps', 'oxps', 'rtf', 'wp', 'wpd', 'psd', 'xcf' ), |
|
3540 |
'spreadsheet' => array( 'numbers', 'ods', 'xls', 'xlsx', 'xlsm', 'xlsb' ), |
|
3541 |
'interactive' => array( 'swf', 'key', 'ppt', 'pptx', 'pptm', 'pps', 'ppsx', 'ppsm', 'sldx', 'sldm', 'odp' ), |
|
3542 |
'text' => array( 'asc', 'csv', 'tsv', 'txt' ), |
|
3543 |
'archive' => array( 'bz2', 'cab', 'dmg', 'gz', 'rar', 'sea', 'sit', 'sqx', 'tar', 'tgz', 'zip', '7z' ), |
|
3544 |
'code' => array( 'css', 'htm', 'html', 'php', 'js' ), |
|
3545 |
) |
|
3546 |
); |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3547 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3548 |
|
| 0 | 3549 |
/** |
| 19 | 3550 |
* Wrapper for PHP filesize with filters and casting the result as an integer. |
3551 |
* |
|
3552 |
* @since 6.0.0 |
|
3553 |
* |
|
3554 |
* @link https://www.php.net/manual/en/function.filesize.php |
|
3555 |
* |
|
3556 |
* @param string $path Path to the file. |
|
3557 |
* @return int The size of the file in bytes, or 0 in the event of an error. |
|
3558 |
*/ |
|
3559 |
function wp_filesize( $path ) {
|
|
3560 |
/** |
|
3561 |
* Filters the result of wp_filesize before the PHP function is run. |
|
3562 |
* |
|
3563 |
* @since 6.0.0 |
|
3564 |
* |
|
3565 |
* @param null|int $size The unfiltered value. Returning an int from the callback bypasses the filesize call. |
|
3566 |
* @param string $path Path to the file. |
|
3567 |
*/ |
|
3568 |
$size = apply_filters( 'pre_wp_filesize', null, $path ); |
|
3569 |
||
3570 |
if ( is_int( $size ) ) {
|
|
3571 |
return $size; |
|
3572 |
} |
|
3573 |
||
3574 |
$size = file_exists( $path ) ? (int) filesize( $path ) : 0; |
|
3575 |
||
3576 |
/** |
|
3577 |
* Filters the size of the file. |
|
3578 |
* |
|
3579 |
* @since 6.0.0 |
|
3580 |
* |
|
3581 |
* @param int $size The result of PHP filesize on the file. |
|
3582 |
* @param string $path Path to the file. |
|
3583 |
*/ |
|
3584 |
return (int) apply_filters( 'wp_filesize', $size, $path ); |
|
3585 |
} |
|
3586 |
||
3587 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3588 |
* Retrieves the list of allowed mime types and file extensions. |
| 0 | 3589 |
* |
3590 |
* @since 2.8.6 |
|
3591 |
* |
|
3592 |
* @param int|WP_User $user Optional. User to check. Defaults to current user. |
|
| 16 | 3593 |
* @return string[] Array of mime types keyed by the file extension regex corresponding |
3594 |
* to those types. |
|
| 0 | 3595 |
*/ |
3596 |
function get_allowed_mime_types( $user = null ) {
|
|
3597 |
$t = wp_get_mime_types(); |
|
3598 |
||
3599 |
unset( $t['swf'], $t['exe'] ); |
|
| 9 | 3600 |
if ( function_exists( 'current_user_can' ) ) {
|
| 0 | 3601 |
$unfiltered = $user ? user_can( $user, 'unfiltered_html' ) : current_user_can( 'unfiltered_html' ); |
| 9 | 3602 |
} |
| 0 | 3603 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3604 |
if ( empty( $unfiltered ) ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3605 |
unset( $t['htm|html'], $t['js'] ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3606 |
} |
| 0 | 3607 |
|
| 5 | 3608 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3609 |
* Filters the list of allowed mime types and file extensions. |
| 5 | 3610 |
* |
3611 |
* @since 2.0.0 |
|
3612 |
* |
|
| 16 | 3613 |
* @param array $t Mime types keyed by the file extension regex corresponding to those types. |
| 5 | 3614 |
* @param int|WP_User|null $user User ID, User object or null if not provided (indicates current user). |
3615 |
*/ |
|
| 0 | 3616 |
return apply_filters( 'upload_mimes', $t, $user ); |
3617 |
} |
|
3618 |
||
3619 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3620 |
* Displays "Are You Sure" message to confirm the action being taken. |
| 0 | 3621 |
* |
| 5 | 3622 |
* If the action has the nonce explain message, then it will be displayed |
3623 |
* along with the "Are you sure?" message. |
|
3624 |
* |
|
| 0 | 3625 |
* @since 2.0.4 |
3626 |
* |
|
3627 |
* @param string $action The nonce action. |
|
3628 |
*/ |
|
3629 |
function wp_nonce_ays( $action ) {
|
|
| 19 | 3630 |
// Default title and response code. |
3631 |
$title = __( 'Something went wrong.' ); |
|
3632 |
$response_code = 403; |
|
3633 |
||
| 16 | 3634 |
if ( 'log-out' === $action ) {
|
| 19 | 3635 |
$title = sprintf( |
| 16 | 3636 |
/* translators: %s: Site title. */ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3637 |
__( 'You are attempting to log out of %s' ), |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3638 |
get_bloginfo( 'name' ) |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3639 |
); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3640 |
|
| 5 | 3641 |
$redirect_to = isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : ''; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3642 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3643 |
$html = $title; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3644 |
$html .= '</p><p>'; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3645 |
$html .= sprintf( |
| 16 | 3646 |
/* translators: %s: Logout URL. */ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3647 |
__( 'Do you really want to <a href="%s">log out</a>?' ), |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3648 |
wp_logout_url( $redirect_to ) |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3649 |
); |
| 0 | 3650 |
} else {
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3651 |
$html = __( 'The link you followed has expired.' ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3652 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3653 |
if ( wp_get_referer() ) {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3654 |
$wp_http_referer = remove_query_arg( 'updated', wp_get_referer() ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3655 |
$wp_http_referer = wp_validate_redirect( sanitize_url( $wp_http_referer ) ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3656 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3657 |
$html .= '</p><p>'; |
| 9 | 3658 |
$html .= sprintf( |
3659 |
'<a href="%s">%s</a>', |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3660 |
esc_url( $wp_http_referer ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3661 |
__( 'Please try again.' ) |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3662 |
); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3663 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3664 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3665 |
|
| 19 | 3666 |
wp_die( $html, $title, $response_code ); |
| 0 | 3667 |
} |
3668 |
||
3669 |
/** |
|
| 9 | 3670 |
* Kills WordPress execution and displays HTML page with an error message. |
| 0 | 3671 |
* |
| 5 | 3672 |
* This function complements the `die()` PHP function. The difference is that |
| 0 | 3673 |
* HTML will be displayed to the user. It is recommended to use this function |
| 5 | 3674 |
* only when the execution should not continue any further. It is not recommended |
3675 |
* to call this function very often, and try to handle as many errors as possible |
|
3676 |
* silently or more gracefully. |
|
3677 |
* |
|
3678 |
* As a shorthand, the desired HTTP response code may be passed as an integer to |
|
3679 |
* the `$title` parameter (the default title would apply) or the `$args` parameter. |
|
| 0 | 3680 |
* |
3681 |
* @since 2.0.4 |
|
| 5 | 3682 |
* @since 4.1.0 The `$title` and `$args` parameters were changed to optionally accept |
3683 |
* an integer to be used as the response code. |
|
| 9 | 3684 |
* @since 5.1.0 The `$link_url`, `$link_text`, and `$exit` arguments were added. |
| 16 | 3685 |
* @since 5.3.0 The `$charset` argument was added. |
3686 |
* @since 5.5.0 The `$text_direction` argument has a priority over get_language_attributes() |
|
3687 |
* in the default handler. |
|
3688 |
* |
|
3689 |
* @global WP_Query $wp_query WordPress Query object. |
|
| 5 | 3690 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3691 |
* @param string|WP_Error $message Optional. Error message. If this is a WP_Error object, |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3692 |
* and not an Ajax or XML-RPC request, the error's messages are used. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3693 |
* Default empty string. |
| 5 | 3694 |
* @param string|int $title Optional. Error title. If `$message` is a `WP_Error` object, |
3695 |
* error data with the key 'title' may be used to specify the title. |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3696 |
* If `$title` is an integer, then it is treated as the response code. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3697 |
* Default empty string. |
| 5 | 3698 |
* @param string|array|int $args {
|
3699 |
* Optional. Arguments to control behavior. If `$args` is an integer, then it is treated |
|
3700 |
* as the response code. Default empty array. |
|
3701 |
* |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3702 |
* @type int $response The HTTP response code. Default 200 for Ajax requests, 500 otherwise. |
| 9 | 3703 |
* @type string $link_url A URL to include a link to. Only works in combination with $link_text. |
3704 |
* Default empty string. |
|
3705 |
* @type string $link_text A label for the link to include. Only works in combination with $link_url. |
|
3706 |
* Default empty string. |
|
| 5 | 3707 |
* @type bool $back_link Whether to include a link to go back. Default false. |
| 16 | 3708 |
* @type string $text_direction The text direction. This is only useful internally, when WordPress is still |
3709 |
* loading and the site's locale is not set up yet. Accepts 'rtl' and 'ltr'. |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3710 |
* Default is the value of is_rtl(). |
| 16 | 3711 |
* @type string $charset Character set of the HTML output. Default 'utf-8'. |
| 9 | 3712 |
* @type string $code Error code to use. Default is 'wp_die', or the main error code if $message |
3713 |
* is a WP_Error. |
|
3714 |
* @type bool $exit Whether to exit the process after completion. Default true. |
|
| 5 | 3715 |
* } |
| 0 | 3716 |
*/ |
3717 |
function wp_die( $message = '', $title = '', $args = array() ) {
|
|
| 9 | 3718 |
global $wp_query; |
| 5 | 3719 |
|
3720 |
if ( is_int( $args ) ) {
|
|
3721 |
$args = array( 'response' => $args ); |
|
3722 |
} elseif ( is_int( $title ) ) {
|
|
3723 |
$args = array( 'response' => $title ); |
|
3724 |
$title = ''; |
|
3725 |
} |
|
3726 |
||
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3727 |
if ( wp_doing_ajax() ) {
|
| 5 | 3728 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3729 |
* Filters the callback for killing WordPress execution for Ajax requests. |
| 5 | 3730 |
* |
3731 |
* @since 3.4.0 |
|
3732 |
* |
|
| 19 | 3733 |
* @param callable $callback Callback function name. |
| 5 | 3734 |
*/ |
| 19 | 3735 |
$callback = apply_filters( 'wp_die_ajax_handler', '_ajax_wp_die_handler' ); |
| 9 | 3736 |
} elseif ( wp_is_json_request() ) {
|
3737 |
/** |
|
3738 |
* Filters the callback for killing WordPress execution for JSON requests. |
|
3739 |
* |
|
3740 |
* @since 5.1.0 |
|
3741 |
* |
|
| 19 | 3742 |
* @param callable $callback Callback function name. |
| 9 | 3743 |
*/ |
| 19 | 3744 |
$callback = apply_filters( 'wp_die_json_handler', '_json_wp_die_handler' ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3745 |
} elseif ( wp_is_serving_rest_request() && wp_is_jsonp_request() ) {
|
| 9 | 3746 |
/** |
| 18 | 3747 |
* Filters the callback for killing WordPress execution for JSONP REST requests. |
| 9 | 3748 |
* |
3749 |
* @since 5.2.0 |
|
3750 |
* |
|
| 19 | 3751 |
* @param callable $callback Callback function name. |
| 9 | 3752 |
*/ |
| 19 | 3753 |
$callback = apply_filters( 'wp_die_jsonp_handler', '_jsonp_wp_die_handler' ); |
| 5 | 3754 |
} elseif ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) {
|
3755 |
/** |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3756 |
* Filters the callback for killing WordPress execution for XML-RPC requests. |
| 5 | 3757 |
* |
3758 |
* @since 3.4.0 |
|
3759 |
* |
|
| 19 | 3760 |
* @param callable $callback Callback function name. |
| 5 | 3761 |
*/ |
| 19 | 3762 |
$callback = apply_filters( 'wp_die_xmlrpc_handler', '_xmlrpc_wp_die_handler' ); |
| 9 | 3763 |
} elseif ( wp_is_xml_request() |
3764 |
|| isset( $wp_query ) && |
|
3765 |
( function_exists( 'is_feed' ) && is_feed() |
|
3766 |
|| function_exists( 'is_comment_feed' ) && is_comment_feed() |
|
3767 |
|| function_exists( 'is_trackback' ) && is_trackback() ) ) {
|
|
3768 |
/** |
|
3769 |
* Filters the callback for killing WordPress execution for XML requests. |
|
3770 |
* |
|
3771 |
* @since 5.2.0 |
|
3772 |
* |
|
| 19 | 3773 |
* @param callable $callback Callback function name. |
| 9 | 3774 |
*/ |
| 19 | 3775 |
$callback = apply_filters( 'wp_die_xml_handler', '_xml_wp_die_handler' ); |
| 5 | 3776 |
} else {
|
3777 |
/** |
|
| 9 | 3778 |
* Filters the callback for killing WordPress execution for all non-Ajax, non-JSON, non-XML requests. |
| 5 | 3779 |
* |
3780 |
* @since 3.0.0 |
|
3781 |
* |
|
| 19 | 3782 |
* @param callable $callback Callback function name. |
| 5 | 3783 |
*/ |
| 19 | 3784 |
$callback = apply_filters( 'wp_die_handler', '_default_wp_die_handler' ); |
3785 |
} |
|
3786 |
||
3787 |
call_user_func( $callback, $message, $title, $args ); |
|
| 0 | 3788 |
} |
3789 |
||
3790 |
/** |
|
| 9 | 3791 |
* Kills WordPress execution and displays HTML page with an error message. |
3792 |
* |
|
3793 |
* This is the default handler for wp_die(). If you want a custom one, |
|
3794 |
* you can override this using the {@see 'wp_die_handler'} filter in wp_die().
|
|
| 0 | 3795 |
* |
3796 |
* @since 3.0.0 |
|
3797 |
* @access private |
|
3798 |
* |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3799 |
* @param string|WP_Error $message Error message or WP_Error object. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3800 |
* @param string $title Optional. Error title. Default empty string. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3801 |
* @param string|array $args Optional. Arguments to control behavior. Default empty array. |
| 0 | 3802 |
*/ |
3803 |
function _default_wp_die_handler( $message, $title = '', $args = array() ) {
|
|
| 16 | 3804 |
list( $message, $title, $parsed_args ) = _wp_die_process_input( $message, $title, $args ); |
| 9 | 3805 |
|
3806 |
if ( is_string( $message ) ) {
|
|
| 16 | 3807 |
if ( ! empty( $parsed_args['additional_errors'] ) ) {
|
| 9 | 3808 |
$message = array_merge( |
3809 |
array( $message ), |
|
| 16 | 3810 |
wp_list_pluck( $parsed_args['additional_errors'], 'message' ) |
| 9 | 3811 |
); |
| 18 | 3812 |
$message = "<ul>\n\t\t<li>" . implode( "</li>\n\t\t<li>", $message ) . "</li>\n\t</ul>"; |
| 0 | 3813 |
} |
| 16 | 3814 |
|
3815 |
$message = sprintf( |
|
3816 |
'<div class="wp-die-message">%s</div>', |
|
3817 |
$message |
|
3818 |
); |
|
| 9 | 3819 |
} |
3820 |
||
3821 |
$have_gettext = function_exists( '__' ); |
|
3822 |
||
| 16 | 3823 |
if ( ! empty( $parsed_args['link_url'] ) && ! empty( $parsed_args['link_text'] ) ) {
|
3824 |
$link_url = $parsed_args['link_url']; |
|
| 9 | 3825 |
if ( function_exists( 'esc_url' ) ) {
|
3826 |
$link_url = esc_url( $link_url ); |
|
| 5 | 3827 |
} |
| 16 | 3828 |
$link_text = $parsed_args['link_text']; |
| 9 | 3829 |
$message .= "\n<p><a href='{$link_url}'>{$link_text}</a></p>";
|
| 0 | 3830 |
} |
3831 |
||
| 16 | 3832 |
if ( isset( $parsed_args['back_link'] ) && $parsed_args['back_link'] ) {
|
| 9 | 3833 |
$back_text = $have_gettext ? __( '« Back' ) : '« Back'; |
3834 |
$message .= "\n<p><a href='javascript:history.back()'>$back_text</a></p>"; |
|
| 0 | 3835 |
} |
3836 |
||
3837 |
if ( ! did_action( 'admin_head' ) ) : |
|
| 9 | 3838 |
if ( ! headers_sent() ) {
|
| 16 | 3839 |
header( "Content-Type: text/html; charset={$parsed_args['charset']}" );
|
3840 |
status_header( $parsed_args['response'] ); |
|
| 0 | 3841 |
nocache_headers(); |
3842 |
} |
|
3843 |
||
| 16 | 3844 |
$text_direction = $parsed_args['text_direction']; |
3845 |
$dir_attr = "dir='$text_direction'"; |
|
3846 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3847 |
/* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3848 |
* If `text_direction` was not explicitly passed, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3849 |
* use get_language_attributes() if available. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3850 |
*/ |
| 16 | 3851 |
if ( empty( $args['text_direction'] ) |
3852 |
&& function_exists( 'language_attributes' ) && function_exists( 'is_rtl' ) |
|
3853 |
) {
|
|
| 9 | 3854 |
$dir_attr = get_language_attributes(); |
3855 |
} |
|
3856 |
?> |
|
| 0 | 3857 |
<!DOCTYPE html> |
| 16 | 3858 |
<html <?php echo $dir_attr; ?>> |
| 0 | 3859 |
<head> |
| 16 | 3860 |
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $parsed_args['charset']; ?>" /> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3861 |
<meta name="viewport" content="width=device-width"> |
| 9 | 3862 |
<?php |
| 18 | 3863 |
if ( function_exists( 'wp_robots' ) && function_exists( 'wp_robots_no_robots' ) && function_exists( 'add_filter' ) ) {
|
3864 |
add_filter( 'wp_robots', 'wp_robots_no_robots' ); |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3865 |
// Prevent warnings because of $wp_query not existing. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3866 |
remove_filter( 'wp_robots', 'wp_robots_noindex_embeds' ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3867 |
remove_filter( 'wp_robots', 'wp_robots_noindex_search' ); |
| 18 | 3868 |
wp_robots(); |
| 9 | 3869 |
} |
3870 |
?> |
|
3871 |
<title><?php echo $title; ?></title> |
|
| 0 | 3872 |
<style type="text/css"> |
3873 |
html {
|
|
| 5 | 3874 |
background: #f1f1f1; |
| 0 | 3875 |
} |
3876 |
body {
|
|
3877 |
background: #fff; |
|
| 18 | 3878 |
border: 1px solid #ccd0d4; |
| 5 | 3879 |
color: #444; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3880 |
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; |
| 0 | 3881 |
margin: 2em auto; |
3882 |
padding: 1em 2em; |
|
3883 |
max-width: 700px; |
|
| 18 | 3884 |
-webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, .04); |
3885 |
box-shadow: 0 1px 1px rgba(0, 0, 0, .04); |
|
| 0 | 3886 |
} |
3887 |
h1 {
|
|
3888 |
border-bottom: 1px solid #dadada; |
|
3889 |
clear: both; |
|
3890 |
color: #666; |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3891 |
font-size: 24px; |
| 0 | 3892 |
margin: 30px 0 0 0; |
3893 |
padding: 0; |
|
3894 |
padding-bottom: 7px; |
|
3895 |
} |
|
3896 |
#error-page {
|
|
3897 |
margin-top: 50px; |
|
3898 |
} |
|
| 16 | 3899 |
#error-page p, |
3900 |
#error-page .wp-die-message {
|
|
| 0 | 3901 |
font-size: 14px; |
3902 |
line-height: 1.5; |
|
3903 |
margin: 25px 0 20px; |
|
3904 |
} |
|
3905 |
#error-page code {
|
|
3906 |
font-family: Consolas, Monaco, monospace; |
|
3907 |
} |
|
3908 |
ul li {
|
|
3909 |
margin-bottom: 10px; |
|
3910 |
font-size: 14px ; |
|
3911 |
} |
|
3912 |
a {
|
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3913 |
color: #2271b1; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3914 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3915 |
a:hover, |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3916 |
a:active {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3917 |
color: #135e96; |
| 0 | 3918 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3919 |
a:focus {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3920 |
color: #043959; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3921 |
box-shadow: 0 0 0 2px #2271b1; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3922 |
outline: 2px solid transparent; |
| 0 | 3923 |
} |
3924 |
.button {
|
|
| 18 | 3925 |
background: #f3f5f6; |
3926 |
border: 1px solid #016087; |
|
3927 |
color: #016087; |
|
| 0 | 3928 |
display: inline-block; |
3929 |
text-decoration: none; |
|
| 5 | 3930 |
font-size: 13px; |
| 16 | 3931 |
line-height: 2; |
| 5 | 3932 |
height: 28px; |
| 0 | 3933 |
margin: 0; |
3934 |
padding: 0 10px 1px; |
|
3935 |
cursor: pointer; |
|
3936 |
-webkit-border-radius: 3px; |
|
| 5 | 3937 |
-webkit-appearance: none; |
| 0 | 3938 |
border-radius: 3px; |
3939 |
white-space: nowrap; |
|
3940 |
-webkit-box-sizing: border-box; |
|
3941 |
-moz-box-sizing: border-box; |
|
3942 |
box-sizing: border-box; |
|
| 5 | 3943 |
|
| 16 | 3944 |
vertical-align: top; |
| 0 | 3945 |
} |
3946 |
||
3947 |
.button.button-large {
|
|
| 18 | 3948 |
line-height: 2.30769231; |
3949 |
min-height: 32px; |
|
3950 |
padding: 0 12px; |
|
| 0 | 3951 |
} |
3952 |
||
3953 |
.button:hover, |
|
3954 |
.button:focus {
|
|
| 18 | 3955 |
background: #f1f1f1; |
| 0 | 3956 |
} |
3957 |
||
| 9 | 3958 |
.button:focus {
|
| 18 | 3959 |
background: #f3f5f6; |
3960 |
border-color: #007cba; |
|
3961 |
-webkit-box-shadow: 0 0 0 1px #007cba; |
|
3962 |
box-shadow: 0 0 0 1px #007cba; |
|
3963 |
color: #016087; |
|
3964 |
outline: 2px solid transparent; |
|
3965 |
outline-offset: 0; |
|
| 0 | 3966 |
} |
3967 |
||
3968 |
.button:active {
|
|
| 18 | 3969 |
background: #f3f5f6; |
3970 |
border-color: #7e8993; |
|
3971 |
-webkit-box-shadow: none; |
|
3972 |
box-shadow: none; |
|
| 0 | 3973 |
} |
3974 |
||
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3975 |
<?php |
| 16 | 3976 |
if ( 'rtl' === $text_direction ) {
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3977 |
echo 'body { font-family: Tahoma, Arial; }';
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3978 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3979 |
?> |
| 0 | 3980 |
</style> |
3981 |
</head> |
|
3982 |
<body id="error-page"> |
|
3983 |
<?php endif; // ! did_action( 'admin_head' ) ?> |
|
3984 |
<?php echo $message; ?> |
|
3985 |
</body> |
|
3986 |
</html> |
|
| 9 | 3987 |
<?php |
| 16 | 3988 |
if ( $parsed_args['exit'] ) {
|
| 9 | 3989 |
die(); |
3990 |
} |
|
3991 |
} |
|
3992 |
||
3993 |
/** |
|
3994 |
* Kills WordPress execution and displays Ajax response with an error message. |
|
3995 |
* |
|
3996 |
* This is the handler for wp_die() when processing Ajax requests. |
|
3997 |
* |
|
3998 |
* @since 3.4.0 |
|
3999 |
* @access private |
|
4000 |
* |
|
4001 |
* @param string $message Error message. |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4002 |
* @param string $title Optional. Error title (unused). Default empty string. |
| 9 | 4003 |
* @param string|array $args Optional. Arguments to control behavior. Default empty array. |
4004 |
*/ |
|
4005 |
function _ajax_wp_die_handler( $message, $title = '', $args = array() ) {
|
|
| 16 | 4006 |
// Set default 'response' to 200 for Ajax requests. |
| 9 | 4007 |
$args = wp_parse_args( |
4008 |
$args, |
|
4009 |
array( 'response' => 200 ) |
|
4010 |
); |
|
4011 |
||
| 16 | 4012 |
list( $message, $title, $parsed_args ) = _wp_die_process_input( $message, $title, $args ); |
| 9 | 4013 |
|
4014 |
if ( ! headers_sent() ) {
|
|
4015 |
// This is intentional. For backward-compatibility, support passing null here. |
|
4016 |
if ( null !== $args['response'] ) {
|
|
| 16 | 4017 |
status_header( $parsed_args['response'] ); |
| 9 | 4018 |
} |
4019 |
nocache_headers(); |
|
4020 |
} |
|
4021 |
||
4022 |
if ( is_scalar( $message ) ) {
|
|
4023 |
$message = (string) $message; |
|
4024 |
} else {
|
|
4025 |
$message = '0'; |
|
4026 |
} |
|
4027 |
||
| 16 | 4028 |
if ( $parsed_args['exit'] ) {
|
| 9 | 4029 |
die( $message ); |
4030 |
} |
|
4031 |
||
4032 |
echo $message; |
|
4033 |
} |
|
4034 |
||
4035 |
/** |
|
4036 |
* Kills WordPress execution and displays JSON response with an error message. |
|
4037 |
* |
|
4038 |
* This is the handler for wp_die() when processing JSON requests. |
|
4039 |
* |
|
4040 |
* @since 5.1.0 |
|
4041 |
* @access private |
|
4042 |
* |
|
4043 |
* @param string $message Error message. |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4044 |
* @param string $title Optional. Error title. Default empty string. |
| 9 | 4045 |
* @param string|array $args Optional. Arguments to control behavior. Default empty array. |
4046 |
*/ |
|
4047 |
function _json_wp_die_handler( $message, $title = '', $args = array() ) {
|
|
| 16 | 4048 |
list( $message, $title, $parsed_args ) = _wp_die_process_input( $message, $title, $args ); |
| 9 | 4049 |
|
4050 |
$data = array( |
|
| 16 | 4051 |
'code' => $parsed_args['code'], |
| 9 | 4052 |
'message' => $message, |
4053 |
'data' => array( |
|
| 16 | 4054 |
'status' => $parsed_args['response'], |
| 9 | 4055 |
), |
| 16 | 4056 |
'additional_errors' => $parsed_args['additional_errors'], |
| 9 | 4057 |
); |
4058 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4059 |
if ( isset( $parsed_args['error_data'] ) ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4060 |
$data['data']['error'] = $parsed_args['error_data']; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4061 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4062 |
|
| 9 | 4063 |
if ( ! headers_sent() ) {
|
| 16 | 4064 |
header( "Content-Type: application/json; charset={$parsed_args['charset']}" );
|
4065 |
if ( null !== $parsed_args['response'] ) {
|
|
4066 |
status_header( $parsed_args['response'] ); |
|
| 9 | 4067 |
} |
4068 |
nocache_headers(); |
|
4069 |
} |
|
4070 |
||
4071 |
echo wp_json_encode( $data ); |
|
| 16 | 4072 |
if ( $parsed_args['exit'] ) {
|
| 9 | 4073 |
die(); |
4074 |
} |
|
4075 |
} |
|
4076 |
||
4077 |
/** |
|
4078 |
* Kills WordPress execution and displays JSONP response with an error message. |
|
4079 |
* |
|
4080 |
* This is the handler for wp_die() when processing JSONP requests. |
|
4081 |
* |
|
4082 |
* @since 5.2.0 |
|
4083 |
* @access private |
|
4084 |
* |
|
4085 |
* @param string $message Error message. |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4086 |
* @param string $title Optional. Error title. Default empty string. |
| 9 | 4087 |
* @param string|array $args Optional. Arguments to control behavior. Default empty array. |
4088 |
*/ |
|
4089 |
function _jsonp_wp_die_handler( $message, $title = '', $args = array() ) {
|
|
| 16 | 4090 |
list( $message, $title, $parsed_args ) = _wp_die_process_input( $message, $title, $args ); |
| 9 | 4091 |
|
4092 |
$data = array( |
|
| 16 | 4093 |
'code' => $parsed_args['code'], |
| 9 | 4094 |
'message' => $message, |
4095 |
'data' => array( |
|
| 16 | 4096 |
'status' => $parsed_args['response'], |
| 9 | 4097 |
), |
| 16 | 4098 |
'additional_errors' => $parsed_args['additional_errors'], |
| 9 | 4099 |
); |
4100 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4101 |
if ( isset( $parsed_args['error_data'] ) ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4102 |
$data['data']['error'] = $parsed_args['error_data']; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4103 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4104 |
|
| 9 | 4105 |
if ( ! headers_sent() ) {
|
| 16 | 4106 |
header( "Content-Type: application/javascript; charset={$parsed_args['charset']}" );
|
| 9 | 4107 |
header( 'X-Content-Type-Options: nosniff' ); |
4108 |
header( 'X-Robots-Tag: noindex' ); |
|
| 16 | 4109 |
if ( null !== $parsed_args['response'] ) {
|
4110 |
status_header( $parsed_args['response'] ); |
|
| 9 | 4111 |
} |
4112 |
nocache_headers(); |
|
4113 |
} |
|
4114 |
||
4115 |
$result = wp_json_encode( $data ); |
|
4116 |
$jsonp_callback = $_GET['_jsonp']; |
|
4117 |
echo '/**/' . $jsonp_callback . '(' . $result . ')';
|
|
| 16 | 4118 |
if ( $parsed_args['exit'] ) {
|
| 9 | 4119 |
die(); |
4120 |
} |
|
4121 |
} |
|
4122 |
||
4123 |
/** |
|
4124 |
* Kills WordPress execution and displays XML response with an error message. |
|
4125 |
* |
|
4126 |
* This is the handler for wp_die() when processing XMLRPC requests. |
|
| 0 | 4127 |
* |
4128 |
* @since 3.2.0 |
|
4129 |
* @access private |
|
4130 |
* |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4131 |
* @global wp_xmlrpc_server $wp_xmlrpc_server |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4132 |
* |
| 5 | 4133 |
* @param string $message Error message. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4134 |
* @param string $title Optional. Error title. Default empty string. |
| 5 | 4135 |
* @param string|array $args Optional. Arguments to control behavior. Default empty array. |
| 0 | 4136 |
*/ |
4137 |
function _xmlrpc_wp_die_handler( $message, $title = '', $args = array() ) {
|
|
4138 |
global $wp_xmlrpc_server; |
|
| 9 | 4139 |
|
| 16 | 4140 |
list( $message, $title, $parsed_args ) = _wp_die_process_input( $message, $title, $args ); |
| 9 | 4141 |
|
4142 |
if ( ! headers_sent() ) {
|
|
4143 |
nocache_headers(); |
|
4144 |
} |
|
| 0 | 4145 |
|
4146 |
if ( $wp_xmlrpc_server ) {
|
|
| 16 | 4147 |
$error = new IXR_Error( $parsed_args['response'], $message ); |
| 0 | 4148 |
$wp_xmlrpc_server->output( $error->getXml() ); |
4149 |
} |
|
| 16 | 4150 |
if ( $parsed_args['exit'] ) {
|
| 9 | 4151 |
die(); |
4152 |
} |
|
4153 |
} |
|
4154 |
||
4155 |
/** |
|
4156 |
* Kills WordPress execution and displays XML response with an error message. |
|
4157 |
* |
|
4158 |
* This is the handler for wp_die() when processing XML requests. |
|
4159 |
* |
|
4160 |
* @since 5.2.0 |
|
| 0 | 4161 |
* @access private |
4162 |
* |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4163 |
* @param string $message Error message. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4164 |
* @param string $title Optional. Error title. Default empty string. |
| 9 | 4165 |
* @param string|array $args Optional. Arguments to control behavior. Default empty array. |
4166 |
*/ |
|
4167 |
function _xml_wp_die_handler( $message, $title = '', $args = array() ) {
|
|
| 16 | 4168 |
list( $message, $title, $parsed_args ) = _wp_die_process_input( $message, $title, $args ); |
| 9 | 4169 |
|
4170 |
$message = htmlspecialchars( $message ); |
|
4171 |
$title = htmlspecialchars( $title ); |
|
4172 |
||
4173 |
$xml = <<<EOD |
|
4174 |
<error> |
|
| 16 | 4175 |
<code>{$parsed_args['code']}</code>
|
| 9 | 4176 |
<title><![CDATA[{$title}]]></title>
|
4177 |
<message><![CDATA[{$message}]]></message>
|
|
4178 |
<data> |
|
| 16 | 4179 |
<status>{$parsed_args['response']}</status>
|
| 9 | 4180 |
</data> |
4181 |
</error> |
|
4182 |
||
4183 |
EOD; |
|
4184 |
||
4185 |
if ( ! headers_sent() ) {
|
|
| 16 | 4186 |
header( "Content-Type: text/xml; charset={$parsed_args['charset']}" );
|
4187 |
if ( null !== $parsed_args['response'] ) {
|
|
4188 |
status_header( $parsed_args['response'] ); |
|
| 9 | 4189 |
} |
4190 |
nocache_headers(); |
|
4191 |
} |
|
4192 |
||
4193 |
echo $xml; |
|
| 16 | 4194 |
if ( $parsed_args['exit'] ) {
|
| 9 | 4195 |
die(); |
4196 |
} |
|
4197 |
} |
|
4198 |
||
4199 |
/** |
|
4200 |
* Kills WordPress execution and displays an error message. |
|
4201 |
* |
|
4202 |
* This is the handler for wp_die() when processing APP requests. |
|
4203 |
* |
|
4204 |
* @since 3.4.0 |
|
4205 |
* @since 5.1.0 Added the $title and $args parameters. |
|
4206 |
* @access private |
|
4207 |
* |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4208 |
* @param string $message Optional. Response to print. Default empty string. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4209 |
* @param string $title Optional. Error title (unused). Default empty string. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4210 |
* @param string|array $args Optional. Arguments to control behavior. Default empty array. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4211 |
*/ |
| 9 | 4212 |
function _scalar_wp_die_handler( $message = '', $title = '', $args = array() ) {
|
| 16 | 4213 |
list( $message, $title, $parsed_args ) = _wp_die_process_input( $message, $title, $args ); |
4214 |
||
4215 |
if ( $parsed_args['exit'] ) {
|
|
| 9 | 4216 |
if ( is_scalar( $message ) ) {
|
4217 |
die( (string) $message ); |
|
4218 |
} |
|
4219 |
die(); |
|
4220 |
} |
|
4221 |
||
4222 |
if ( is_scalar( $message ) ) {
|
|
4223 |
echo (string) $message; |
|
4224 |
} |
|
4225 |
} |
|
4226 |
||
4227 |
/** |
|
4228 |
* Processes arguments passed to wp_die() consistently for its handlers. |
|
4229 |
* |
|
4230 |
* @since 5.1.0 |
|
4231 |
* @access private |
|
4232 |
* |
|
| 16 | 4233 |
* @param string|WP_Error $message Error message or WP_Error object. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4234 |
* @param string $title Optional. Error title. Default empty string. |
| 16 | 4235 |
* @param string|array $args Optional. Arguments to control behavior. Default empty array. |
4236 |
* @return array {
|
|
4237 |
* Processed arguments. |
|
4238 |
* |
|
4239 |
* @type string $0 Error message. |
|
4240 |
* @type string $1 Error title. |
|
4241 |
* @type array $2 Arguments to control behavior. |
|
4242 |
* } |
|
| 9 | 4243 |
*/ |
4244 |
function _wp_die_process_input( $message, $title = '', $args = array() ) {
|
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4245 |
$defaults = array( |
| 9 | 4246 |
'response' => 0, |
4247 |
'code' => '', |
|
4248 |
'exit' => true, |
|
4249 |
'back_link' => false, |
|
4250 |
'link_url' => '', |
|
4251 |
'link_text' => '', |
|
4252 |
'text_direction' => '', |
|
| 16 | 4253 |
'charset' => 'utf-8', |
| 9 | 4254 |
'additional_errors' => array(), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4255 |
); |
| 9 | 4256 |
|
4257 |
$args = wp_parse_args( $args, $defaults ); |
|
4258 |
||
4259 |
if ( function_exists( 'is_wp_error' ) && is_wp_error( $message ) ) {
|
|
4260 |
if ( ! empty( $message->errors ) ) {
|
|
4261 |
$errors = array(); |
|
4262 |
foreach ( (array) $message->errors as $error_code => $error_messages ) {
|
|
4263 |
foreach ( (array) $error_messages as $error_message ) {
|
|
4264 |
$errors[] = array( |
|
4265 |
'code' => $error_code, |
|
4266 |
'message' => $error_message, |
|
4267 |
'data' => $message->get_error_data( $error_code ), |
|
4268 |
); |
|
4269 |
} |
|
4270 |
} |
|
4271 |
||
4272 |
$message = $errors[0]['message']; |
|
4273 |
if ( empty( $args['code'] ) ) {
|
|
4274 |
$args['code'] = $errors[0]['code']; |
|
4275 |
} |
|
4276 |
if ( empty( $args['response'] ) && is_array( $errors[0]['data'] ) && ! empty( $errors[0]['data']['status'] ) ) {
|
|
4277 |
$args['response'] = $errors[0]['data']['status']; |
|
4278 |
} |
|
4279 |
if ( empty( $title ) && is_array( $errors[0]['data'] ) && ! empty( $errors[0]['data']['title'] ) ) {
|
|
4280 |
$title = $errors[0]['data']['title']; |
|
4281 |
} |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4282 |
if ( WP_DEBUG_DISPLAY && is_array( $errors[0]['data'] ) && ! empty( $errors[0]['data']['error'] ) ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4283 |
$args['error_data'] = $errors[0]['data']['error']; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4284 |
} |
| 9 | 4285 |
|
4286 |
unset( $errors[0] ); |
|
4287 |
$args['additional_errors'] = array_values( $errors ); |
|
4288 |
} else {
|
|
4289 |
$message = ''; |
|
4290 |
} |
|
4291 |
} |
|
4292 |
||
4293 |
$have_gettext = function_exists( '__' ); |
|
4294 |
||
4295 |
// The $title and these specific $args must always have a non-empty value. |
|
4296 |
if ( empty( $args['code'] ) ) {
|
|
4297 |
$args['code'] = 'wp_die'; |
|
4298 |
} |
|
4299 |
if ( empty( $args['response'] ) ) {
|
|
4300 |
$args['response'] = 500; |
|
4301 |
} |
|
4302 |
if ( empty( $title ) ) {
|
|
4303 |
$title = $have_gettext ? __( 'WordPress › Error' ) : 'WordPress › Error'; |
|
4304 |
} |
|
4305 |
if ( empty( $args['text_direction'] ) || ! in_array( $args['text_direction'], array( 'ltr', 'rtl' ), true ) ) {
|
|
4306 |
$args['text_direction'] = 'ltr'; |
|
4307 |
if ( function_exists( 'is_rtl' ) && is_rtl() ) {
|
|
4308 |
$args['text_direction'] = 'rtl'; |
|
4309 |
} |
|
4310 |
} |
|
4311 |
||
| 16 | 4312 |
if ( ! empty( $args['charset'] ) ) {
|
4313 |
$args['charset'] = _canonical_charset( $args['charset'] ); |
|
4314 |
} |
|
4315 |
||
| 9 | 4316 |
return array( $message, $title, $args ); |
| 0 | 4317 |
} |
4318 |
||
4319 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4320 |
* Encodes a variable into JSON, with some confidence checks. |
| 5 | 4321 |
* |
4322 |
* @since 4.1.0 |
|
| 16 | 4323 |
* @since 5.3.0 No longer handles support for PHP < 5.6. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4324 |
* @since 6.5.0 The `$data` parameter has been renamed to `$value` and |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4325 |
* the `$options` parameter to `$flags` for parity with PHP. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4326 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4327 |
* @param mixed $value Variable (usually an array or object) to encode as JSON. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4328 |
* @param int $flags Optional. Options to be passed to json_encode(). Default 0. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4329 |
* @param int $depth Optional. Maximum depth to walk through $value. Must be |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4330 |
* greater than 0. Default 512. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4331 |
* @return string|false The JSON encoded string, or false if it cannot be encoded. |
| 5 | 4332 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4333 |
function wp_json_encode( $value, $flags = 0, $depth = 512 ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4334 |
$json = json_encode( $value, $flags, $depth ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4335 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4336 |
// If json_encode() was successful, no need to do more confidence checking. |
| 16 | 4337 |
if ( false !== $json ) {
|
| 5 | 4338 |
return $json; |
4339 |
} |
|
4340 |
||
4341 |
try {
|
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4342 |
$value = _wp_json_sanity_check( $value, $depth ); |
| 5 | 4343 |
} catch ( Exception $e ) {
|
4344 |
return false; |
|
4345 |
} |
|
4346 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4347 |
return json_encode( $value, $flags, $depth ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4348 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4349 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4350 |
/** |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4351 |
* Performs confidence checks on data that shall be encoded to JSON. |
| 5 | 4352 |
* |
4353 |
* @ignore |
|
4354 |
* @since 4.1.0 |
|
4355 |
* @access private |
|
4356 |
* |
|
4357 |
* @see wp_json_encode() |
|
4358 |
* |
|
| 16 | 4359 |
* @throws Exception If depth limit is reached. |
4360 |
* |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4361 |
* @param mixed $value Variable (usually an array or object) to encode as JSON. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4362 |
* @param int $depth Maximum depth to walk through $value. Must be greater than 0. |
| 5 | 4363 |
* @return mixed The sanitized data that shall be encoded to JSON. |
4364 |
*/ |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4365 |
function _wp_json_sanity_check( $value, $depth ) {
|
| 5 | 4366 |
if ( $depth < 0 ) {
|
4367 |
throw new Exception( 'Reached depth limit' ); |
|
4368 |
} |
|
4369 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4370 |
if ( is_array( $value ) ) {
|
| 5 | 4371 |
$output = array(); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4372 |
foreach ( $value as $id => $el ) {
|
| 5 | 4373 |
// Don't forget to sanitize the ID! |
4374 |
if ( is_string( $id ) ) {
|
|
4375 |
$clean_id = _wp_json_convert_string( $id ); |
|
4376 |
} else {
|
|
4377 |
$clean_id = $id; |
|
4378 |
} |
|
4379 |
||
4380 |
// Check the element type, so that we're only recursing if we really have to. |
|
4381 |
if ( is_array( $el ) || is_object( $el ) ) {
|
|
4382 |
$output[ $clean_id ] = _wp_json_sanity_check( $el, $depth - 1 ); |
|
4383 |
} elseif ( is_string( $el ) ) {
|
|
4384 |
$output[ $clean_id ] = _wp_json_convert_string( $el ); |
|
4385 |
} else {
|
|
4386 |
$output[ $clean_id ] = $el; |
|
4387 |
} |
|
4388 |
} |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4389 |
} elseif ( is_object( $value ) ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4390 |
$output = new stdClass(); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4391 |
foreach ( $value as $id => $el ) {
|
| 5 | 4392 |
if ( is_string( $id ) ) {
|
4393 |
$clean_id = _wp_json_convert_string( $id ); |
|
4394 |
} else {
|
|
4395 |
$clean_id = $id; |
|
4396 |
} |
|
4397 |
||
4398 |
if ( is_array( $el ) || is_object( $el ) ) {
|
|
4399 |
$output->$clean_id = _wp_json_sanity_check( $el, $depth - 1 ); |
|
4400 |
} elseif ( is_string( $el ) ) {
|
|
4401 |
$output->$clean_id = _wp_json_convert_string( $el ); |
|
4402 |
} else {
|
|
4403 |
$output->$clean_id = $el; |
|
4404 |
} |
|
4405 |
} |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4406 |
} elseif ( is_string( $value ) ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4407 |
return _wp_json_convert_string( $value ); |
| 5 | 4408 |
} else {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4409 |
return $value; |
| 5 | 4410 |
} |
4411 |
||
4412 |
return $output; |
|
4413 |
} |
|
4414 |
||
4415 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4416 |
* Converts a string to UTF-8, so that it can be safely encoded to JSON. |
| 5 | 4417 |
* |
4418 |
* @ignore |
|
4419 |
* @since 4.1.0 |
|
4420 |
* @access private |
|
4421 |
* |
|
4422 |
* @see _wp_json_sanity_check() |
|
4423 |
* |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4424 |
* @param string $input_string The string which is to be converted. |
| 5 | 4425 |
* @return string The checked string. |
4426 |
*/ |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4427 |
function _wp_json_convert_string( $input_string ) {
|
| 5 | 4428 |
static $use_mb = null; |
4429 |
if ( is_null( $use_mb ) ) {
|
|
4430 |
$use_mb = function_exists( 'mb_convert_encoding' ); |
|
4431 |
} |
|
4432 |
||
4433 |
if ( $use_mb ) {
|
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4434 |
$encoding = mb_detect_encoding( $input_string, mb_detect_order(), true ); |
| 5 | 4435 |
if ( $encoding ) {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4436 |
return mb_convert_encoding( $input_string, 'UTF-8', $encoding ); |
| 5 | 4437 |
} else {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4438 |
return mb_convert_encoding( $input_string, 'UTF-8', 'UTF-8' ); |
| 5 | 4439 |
} |
4440 |
} else {
|
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4441 |
return wp_check_invalid_utf8( $input_string, true ); |
| 5 | 4442 |
} |
4443 |
} |
|
4444 |
||
4445 |
/** |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4446 |
* Prepares response data to be serialized to JSON. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4447 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4448 |
* This supports the JsonSerializable interface for PHP 5.2-5.3 as well. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4449 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4450 |
* @ignore |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4451 |
* @since 4.4.0 |
| 16 | 4452 |
* @deprecated 5.3.0 This function is no longer needed as support for PHP 5.2-5.3 |
4453 |
* has been dropped. |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4454 |
* @access private |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4455 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4456 |
* @param mixed $value Native representation. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4457 |
* @return bool|int|float|null|string|array Data ready for `json_encode()`. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4458 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4459 |
function _wp_json_prepare_data( $value ) {
|
| 16 | 4460 |
_deprecated_function( __FUNCTION__, '5.3.0' ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4461 |
return $value; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4462 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4463 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4464 |
/** |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4465 |
* Sends a JSON response back to an Ajax request. |
| 0 | 4466 |
* |
4467 |
* @since 3.5.0 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4468 |
* @since 4.7.0 The `$status_code` parameter was added. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4469 |
* @since 5.6.0 The `$flags` parameter was added. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4470 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4471 |
* @param mixed $response Variable (usually an array or object) to encode as JSON, |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4472 |
* then print and die. |
| 18 | 4473 |
* @param int $status_code Optional. The HTTP status code to output. Default null. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4474 |
* @param int $flags Optional. Options to be passed to json_encode(). Default 0. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4475 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4476 |
function wp_send_json( $response, $status_code = null, $flags = 0 ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4477 |
if ( wp_is_serving_rest_request() ) {
|
| 16 | 4478 |
_doing_it_wrong( |
4479 |
__FUNCTION__, |
|
4480 |
sprintf( |
|
4481 |
/* translators: 1: WP_REST_Response, 2: WP_Error */ |
|
4482 |
__( 'Return a %1$s or %2$s object from your callback when using the REST API.' ), |
|
4483 |
'WP_REST_Response', |
|
4484 |
'WP_Error' |
|
4485 |
), |
|
4486 |
'5.5.0' |
|
4487 |
); |
|
4488 |
} |
|
4489 |
||
4490 |
if ( ! headers_sent() ) {
|
|
4491 |
header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) ); |
|
4492 |
if ( null !== $status_code ) {
|
|
4493 |
status_header( $status_code ); |
|
4494 |
} |
|
4495 |
} |
|
4496 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4497 |
echo wp_json_encode( $response, $flags ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4498 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4499 |
if ( wp_doing_ajax() ) {
|
| 9 | 4500 |
wp_die( |
4501 |
'', |
|
4502 |
'', |
|
4503 |
array( |
|
4504 |
'response' => null, |
|
4505 |
) |
|
4506 |
); |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4507 |
} else {
|
| 0 | 4508 |
die; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4509 |
} |
| 0 | 4510 |
} |
4511 |
||
4512 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4513 |
* Sends a JSON response back to an Ajax request, indicating success. |
| 0 | 4514 |
* |
4515 |
* @since 3.5.0 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4516 |
* @since 4.7.0 The `$status_code` parameter was added. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4517 |
* @since 5.6.0 The `$flags` parameter was added. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4518 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4519 |
* @param mixed $value Optional. Data to encode as JSON, then print and die. Default null. |
| 18 | 4520 |
* @param int $status_code Optional. The HTTP status code to output. Default null. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4521 |
* @param int $flags Optional. Options to be passed to json_encode(). Default 0. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4522 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4523 |
function wp_send_json_success( $value = null, $status_code = null, $flags = 0 ) {
|
| 0 | 4524 |
$response = array( 'success' => true ); |
4525 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4526 |
if ( isset( $value ) ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4527 |
$response['data'] = $value; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4528 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4529 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4530 |
wp_send_json( $response, $status_code, $flags ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4531 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4532 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4533 |
/** |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4534 |
* Sends a JSON response back to an Ajax request, indicating failure. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4535 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4536 |
* If the `$value` parameter is a WP_Error object, the errors |
| 5 | 4537 |
* within the object are processed and output as an array of error |
4538 |
* codes and corresponding messages. All other types are output |
|
4539 |
* without further processing. |
|
4540 |
* |
|
| 0 | 4541 |
* @since 3.5.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4542 |
* @since 4.1.0 The `$value` parameter is now processed if a WP_Error object is passed in. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4543 |
* @since 4.7.0 The `$status_code` parameter was added. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4544 |
* @since 5.6.0 The `$flags` parameter was added. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4545 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4546 |
* @param mixed $value Optional. Data to encode as JSON, then print and die. Default null. |
| 18 | 4547 |
* @param int $status_code Optional. The HTTP status code to output. Default null. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4548 |
* @param int $flags Optional. Options to be passed to json_encode(). Default 0. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4549 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4550 |
function wp_send_json_error( $value = null, $status_code = null, $flags = 0 ) {
|
| 0 | 4551 |
$response = array( 'success' => false ); |
4552 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4553 |
if ( isset( $value ) ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4554 |
if ( is_wp_error( $value ) ) {
|
| 5 | 4555 |
$result = array(); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4556 |
foreach ( $value->errors as $code => $messages ) {
|
| 5 | 4557 |
foreach ( $messages as $message ) {
|
| 9 | 4558 |
$result[] = array( |
4559 |
'code' => $code, |
|
4560 |
'message' => $message, |
|
4561 |
); |
|
| 5 | 4562 |
} |
4563 |
} |
|
4564 |
||
4565 |
$response['data'] = $result; |
|
4566 |
} else {
|
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4567 |
$response['data'] = $value; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4568 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4569 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4570 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4571 |
wp_send_json( $response, $status_code, $flags ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4572 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4573 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4574 |
/** |
| 16 | 4575 |
* Checks that a JSONP callback is a valid JavaScript callback name. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4576 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4577 |
* Only allows alphanumeric characters and the dot character in callback |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4578 |
* function names. This helps to mitigate XSS attacks caused by directly |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4579 |
* outputting user input. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4580 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4581 |
* @since 4.6.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4582 |
* |
| 16 | 4583 |
* @param string $callback Supplied JSONP callback function name. |
4584 |
* @return bool Whether the callback function name is valid. |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4585 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4586 |
function wp_check_jsonp_callback( $callback ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4587 |
if ( ! is_string( $callback ) ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4588 |
return false; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4589 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4590 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4591 |
preg_replace( '/[^\w\.]/', '', $callback, -1, $illegal_char_count ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4592 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4593 |
return 0 === $illegal_char_count; |
| 0 | 4594 |
} |
4595 |
||
4596 |
/** |
|
| 19 | 4597 |
* Reads and decodes a JSON file. |
4598 |
* |
|
4599 |
* @since 5.9.0 |
|
4600 |
* |
|
4601 |
* @param string $filename Path to the JSON file. |
|
4602 |
* @param array $options {
|
|
4603 |
* Optional. Options to be used with `json_decode()`. |
|
4604 |
* |
|
4605 |
* @type bool $associative Optional. When `true`, JSON objects will be returned as associative arrays. |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4606 |
* When `false`, JSON objects will be returned as objects. Default false. |
| 19 | 4607 |
* } |
4608 |
* |
|
4609 |
* @return mixed Returns the value encoded in JSON in appropriate PHP type. |
|
4610 |
* `null` is returned if the file is not found, or its content can't be decoded. |
|
4611 |
*/ |
|
4612 |
function wp_json_file_decode( $filename, $options = array() ) {
|
|
4613 |
$result = null; |
|
4614 |
$filename = wp_normalize_path( realpath( $filename ) ); |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4615 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4616 |
if ( ! $filename ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4617 |
wp_trigger_error( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4618 |
__FUNCTION__, |
| 19 | 4619 |
sprintf( |
4620 |
/* translators: %s: Path to the JSON file. */ |
|
4621 |
__( "File %s doesn't exist!" ), |
|
4622 |
$filename |
|
4623 |
) |
|
4624 |
); |
|
4625 |
return $result; |
|
4626 |
} |
|
4627 |
||
4628 |
$options = wp_parse_args( $options, array( 'associative' => false ) ); |
|
4629 |
$decoded_file = json_decode( file_get_contents( $filename ), $options['associative'] ); |
|
4630 |
||
4631 |
if ( JSON_ERROR_NONE !== json_last_error() ) {
|
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4632 |
wp_trigger_error( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4633 |
__FUNCTION__, |
| 19 | 4634 |
sprintf( |
4635 |
/* translators: 1: Path to the JSON file, 2: Error message. */ |
|
4636 |
__( 'Error when decoding a JSON file at path %1$s: %2$s' ), |
|
4637 |
$filename, |
|
4638 |
json_last_error_msg() |
|
4639 |
) |
|
4640 |
); |
|
4641 |
return $result; |
|
4642 |
} |
|
4643 |
||
4644 |
return $decoded_file; |
|
4645 |
} |
|
4646 |
||
4647 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4648 |
* Retrieves the WordPress home page URL. |
| 0 | 4649 |
* |
| 5 | 4650 |
* If the constant named 'WP_HOME' exists, then it will be used and returned |
4651 |
* by the function. This can be used to counter the redirection on your local |
|
| 0 | 4652 |
* development environment. |
4653 |
* |
|
| 5 | 4654 |
* @since 2.2.0 |
| 0 | 4655 |
* @access private |
| 5 | 4656 |
* |
4657 |
* @see WP_HOME |
|
4658 |
* |
|
4659 |
* @param string $url URL for the home location. |
|
| 0 | 4660 |
* @return string Homepage location. |
4661 |
*/ |
|
4662 |
function _config_wp_home( $url = '' ) {
|
|
| 9 | 4663 |
if ( defined( 'WP_HOME' ) ) {
|
| 0 | 4664 |
return untrailingslashit( WP_HOME ); |
| 9 | 4665 |
} |
| 0 | 4666 |
return $url; |
4667 |
} |
|
4668 |
||
4669 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4670 |
* Retrieves the WordPress site URL. |
| 0 | 4671 |
* |
4672 |
* If the constant named 'WP_SITEURL' is defined, then the value in that |
|
| 5 | 4673 |
* constant will always be returned. This can be used for debugging a site |
4674 |
* on your localhost while not having to change the database to your URL. |
|
4675 |
* |
|
4676 |
* @since 2.2.0 |
|
| 0 | 4677 |
* @access private |
| 5 | 4678 |
* |
4679 |
* @see WP_SITEURL |
|
| 0 | 4680 |
* |
4681 |
* @param string $url URL to set the WordPress site location. |
|
| 19 | 4682 |
* @return string The WordPress site URL. |
| 0 | 4683 |
*/ |
4684 |
function _config_wp_siteurl( $url = '' ) {
|
|
| 9 | 4685 |
if ( defined( 'WP_SITEURL' ) ) {
|
| 0 | 4686 |
return untrailingslashit( WP_SITEURL ); |
| 9 | 4687 |
} |
| 0 | 4688 |
return $url; |
4689 |
} |
|
4690 |
||
4691 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4692 |
* Deletes the fresh site option. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4693 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4694 |
* @since 4.7.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4695 |
* @access private |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4696 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4697 |
function _delete_option_fresh_site() {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4698 |
update_option( 'fresh_site', '0' ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4699 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4700 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4701 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4702 |
* Sets the localized direction for MCE plugin. |
| 0 | 4703 |
* |
| 5 | 4704 |
* Will only set the direction to 'rtl', if the WordPress locale has |
4705 |
* the text direction set to 'rtl'. |
|
4706 |
* |
|
4707 |
* Fills in the 'directionality' setting, enables the 'directionality' |
|
4708 |
* plugin, and adds the 'ltr' button to 'toolbar1', formerly |
|
4709 |
* 'theme_advanced_buttons1' array keys. These keys are then returned |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4710 |
* in the $mce_init (TinyMCE settings) array. |
| 5 | 4711 |
* |
4712 |
* @since 2.1.0 |
|
| 0 | 4713 |
* @access private |
| 5 | 4714 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4715 |
* @param array $mce_init MCE settings array. |
| 0 | 4716 |
* @return array Direction set for 'rtl', if needed by locale. |
4717 |
*/ |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4718 |
function _mce_set_direction( $mce_init ) {
|
| 0 | 4719 |
if ( is_rtl() ) {
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4720 |
$mce_init['directionality'] = 'rtl'; |
| 9 | 4721 |
$mce_init['rtl_ui'] = true; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4722 |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4723 |
if ( ! empty( $mce_init['plugins'] ) && ! str_contains( $mce_init['plugins'], 'directionality' ) ) {
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4724 |
$mce_init['plugins'] .= ',directionality'; |
| 5 | 4725 |
} |
4726 |
||
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4727 |
if ( ! empty( $mce_init['toolbar1'] ) && ! preg_match( '/\bltr\b/', $mce_init['toolbar1'] ) ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4728 |
$mce_init['toolbar1'] .= ',ltr'; |
| 5 | 4729 |
} |
| 0 | 4730 |
} |
4731 |
||
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4732 |
return $mce_init; |
| 0 | 4733 |
} |
4734 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4735 |
/** |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4736 |
* Determines whether WordPress is currently serving a REST API request. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4737 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4738 |
* The function relies on the 'REST_REQUEST' global. As such, it only returns true when an actual REST _request_ is |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4739 |
* being made. It does not return true when a REST endpoint is hit as part of another request, e.g. for preloading a |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4740 |
* REST response. See {@see wp_is_rest_endpoint()} for that purpose.
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4741 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4742 |
* This function should not be called until the {@see 'parse_request'} action, as the constant is only defined then,
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4743 |
* even for an actual REST request. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4744 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4745 |
* @since 6.5.0 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4746 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4747 |
* @return bool True if it's a WordPress REST API request, false otherwise. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4748 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4749 |
function wp_is_serving_rest_request() {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4750 |
return defined( 'REST_REQUEST' ) && REST_REQUEST; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4751 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4752 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4753 |
/** |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4754 |
* Converts smiley code to the icon graphic file equivalent. |
| 0 | 4755 |
* |
4756 |
* You can turn off smilies, by going to the write setting screen and unchecking |
|
4757 |
* the box, or by setting 'use_smilies' option to false or removing the option. |
|
4758 |
* |
|
4759 |
* Plugins may override the default smiley list by setting the $wpsmiliestrans |
|
4760 |
* to an array, with the key the code the blogger types in and the value the |
|
4761 |
* image file. |
|
4762 |
* |
|
4763 |
* The $wp_smiliessearch global is for the regular expression and is set each |
|
4764 |
* time the function is called. |
|
4765 |
* |
|
4766 |
* The full list of smilies can be found in the function and won't be listed in |
|
4767 |
* the description. Probably should create a Codex page for it, so that it is |
|
4768 |
* available. |
|
4769 |
* |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4770 |
* @since 2.2.0 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4771 |
* |
| 0 | 4772 |
* @global array $wpsmiliestrans |
4773 |
* @global array $wp_smiliessearch |
|
4774 |
*/ |
|
4775 |
function smilies_init() {
|
|
4776 |
global $wpsmiliestrans, $wp_smiliessearch; |
|
4777 |
||
| 16 | 4778 |
// Don't bother setting up smilies if they are disabled. |
| 9 | 4779 |
if ( ! get_option( 'use_smilies' ) ) {
|
| 0 | 4780 |
return; |
| 9 | 4781 |
} |
4782 |
||
4783 |
if ( ! isset( $wpsmiliestrans ) ) {
|
|
| 0 | 4784 |
$wpsmiliestrans = array( |
| 9 | 4785 |
':mrgreen:' => 'mrgreen.png', |
4786 |
':neutral:' => "\xf0\x9f\x98\x90", |
|
4787 |
':twisted:' => "\xf0\x9f\x98\x88", |
|
4788 |
':arrow:' => "\xe2\x9e\xa1", |
|
4789 |
':shock:' => "\xf0\x9f\x98\xaf", |
|
4790 |
':smile:' => "\xf0\x9f\x99\x82", |
|
4791 |
':???:' => "\xf0\x9f\x98\x95", |
|
4792 |
':cool:' => "\xf0\x9f\x98\x8e", |
|
4793 |
':evil:' => "\xf0\x9f\x91\xbf", |
|
4794 |
':grin:' => "\xf0\x9f\x98\x80", |
|
4795 |
':idea:' => "\xf0\x9f\x92\xa1", |
|
4796 |
':oops:' => "\xf0\x9f\x98\xb3", |
|
4797 |
':razz:' => "\xf0\x9f\x98\x9b", |
|
4798 |
':roll:' => "\xf0\x9f\x99\x84", |
|
4799 |
':wink:' => "\xf0\x9f\x98\x89", |
|
4800 |
':cry:' => "\xf0\x9f\x98\xa5", |
|
4801 |
':eek:' => "\xf0\x9f\x98\xae", |
|
4802 |
':lol:' => "\xf0\x9f\x98\x86", |
|
4803 |
':mad:' => "\xf0\x9f\x98\xa1", |
|
4804 |
':sad:' => "\xf0\x9f\x99\x81", |
|
4805 |
'8-)' => "\xf0\x9f\x98\x8e", |
|
4806 |
'8-O' => "\xf0\x9f\x98\xaf", |
|
4807 |
':-(' => "\xf0\x9f\x99\x81",
|
|
4808 |
':-)' => "\xf0\x9f\x99\x82", |
|
4809 |
':-?' => "\xf0\x9f\x98\x95", |
|
4810 |
':-D' => "\xf0\x9f\x98\x80", |
|
4811 |
':-P' => "\xf0\x9f\x98\x9b", |
|
4812 |
':-o' => "\xf0\x9f\x98\xae", |
|
4813 |
':-x' => "\xf0\x9f\x98\xa1", |
|
4814 |
':-|' => "\xf0\x9f\x98\x90", |
|
4815 |
';-)' => "\xf0\x9f\x98\x89", |
|
4816 |
// This one transformation breaks regular text with frequency. |
|
4817 |
// '8)' => "\xf0\x9f\x98\x8e", |
|
4818 |
'8O' => "\xf0\x9f\x98\xaf", |
|
4819 |
':(' => "\xf0\x9f\x99\x81",
|
|
4820 |
':)' => "\xf0\x9f\x99\x82", |
|
4821 |
':?' => "\xf0\x9f\x98\x95", |
|
4822 |
':D' => "\xf0\x9f\x98\x80", |
|
4823 |
':P' => "\xf0\x9f\x98\x9b", |
|
4824 |
':o' => "\xf0\x9f\x98\xae", |
|
4825 |
':x' => "\xf0\x9f\x98\xa1", |
|
4826 |
':|' => "\xf0\x9f\x98\x90", |
|
4827 |
';)' => "\xf0\x9f\x98\x89", |
|
4828 |
':!:' => "\xe2\x9d\x97", |
|
4829 |
':?:' => "\xe2\x9d\x93", |
|
| 0 | 4830 |
); |
4831 |
} |
|
4832 |
||
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4833 |
/** |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4834 |
* Filters all the smilies. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4835 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4836 |
* This filter must be added before `smilies_init` is run, as |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4837 |
* it is normally only run once to setup the smilies regex. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4838 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4839 |
* @since 4.7.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4840 |
* |
| 16 | 4841 |
* @param string[] $wpsmiliestrans List of the smilies' hexadecimal representations, keyed by their smily code. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4842 |
*/ |
| 9 | 4843 |
$wpsmiliestrans = apply_filters( 'smilies', $wpsmiliestrans ); |
4844 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4845 |
if ( count( $wpsmiliestrans ) === 0 ) {
|
| 0 | 4846 |
return; |
4847 |
} |
|
4848 |
||
4849 |
/* |
|
4850 |
* NOTE: we sort the smilies in reverse key order. This is to make sure |
|
4851 |
* we match the longest possible smilie (:???: vs :?) as the regular |
|
4852 |
* expression used below is first-match |
|
4853 |
*/ |
|
| 9 | 4854 |
krsort( $wpsmiliestrans ); |
| 0 | 4855 |
|
| 5 | 4856 |
$spaces = wp_spaces_regexp(); |
4857 |
||
| 16 | 4858 |
// Begin first "subpattern". |
| 5 | 4859 |
$wp_smiliessearch = '/(?<=' . $spaces . '|^)'; |
| 0 | 4860 |
|
4861 |
$subchar = ''; |
|
4862 |
foreach ( (array) $wpsmiliestrans as $smiley => $img ) {
|
|
| 9 | 4863 |
$firstchar = substr( $smiley, 0, 1 ); |
4864 |
$rest = substr( $smiley, 1 ); |
|
| 0 | 4865 |
|
| 16 | 4866 |
// New subpattern? |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4867 |
if ( $firstchar !== $subchar ) {
|
| 16 | 4868 |
if ( '' !== $subchar ) {
|
4869 |
$wp_smiliessearch .= ')(?=' . $spaces . '|$)'; // End previous "subpattern". |
|
4870 |
$wp_smiliessearch .= '|(?<=' . $spaces . '|^)'; // Begin another "subpattern". |
|
| 0 | 4871 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4872 |
|
| 9 | 4873 |
$subchar = $firstchar; |
4874 |
$wp_smiliessearch .= preg_quote( $firstchar, '/' ) . '(?:'; |
|
| 0 | 4875 |
} else {
|
4876 |
$wp_smiliessearch .= '|'; |
|
4877 |
} |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4878 |
|
| 9 | 4879 |
$wp_smiliessearch .= preg_quote( $rest, '/' ); |
| 0 | 4880 |
} |
4881 |
||
| 5 | 4882 |
$wp_smiliessearch .= ')(?=' . $spaces . '|$)/m'; |
| 0 | 4883 |
} |
4884 |
||
4885 |
/** |
|
| 18 | 4886 |
* Merges user defined arguments into defaults array. |
| 0 | 4887 |
* |
4888 |
* This function is used throughout WordPress to allow for both string or array |
|
4889 |
* to be merged into another array. |
|
4890 |
* |
|
4891 |
* @since 2.2.0 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4892 |
* @since 2.3.0 `$args` can now also be an object. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4893 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4894 |
* @param string|array|object $args Value to merge with $defaults. |
| 16 | 4895 |
* @param array $defaults Optional. Array that serves as the defaults. |
4896 |
* Default empty array. |
|
| 0 | 4897 |
* @return array Merged user defined values with defaults. |
4898 |
*/ |
|
| 16 | 4899 |
function wp_parse_args( $args, $defaults = array() ) {
|
| 9 | 4900 |
if ( is_object( $args ) ) {
|
| 16 | 4901 |
$parsed_args = get_object_vars( $args ); |
| 9 | 4902 |
} elseif ( is_array( $args ) ) {
|
| 16 | 4903 |
$parsed_args =& $args; |
| 9 | 4904 |
} else {
|
| 16 | 4905 |
wp_parse_str( $args, $parsed_args ); |
4906 |
} |
|
4907 |
||
4908 |
if ( is_array( $defaults ) && $defaults ) {
|
|
4909 |
return array_merge( $defaults, $parsed_args ); |
|
4910 |
} |
|
4911 |
return $parsed_args; |
|
| 0 | 4912 |
} |
4913 |
||
4914 |
/** |
|
| 18 | 4915 |
* Converts a comma- or space-separated list of scalar values to an array. |
| 9 | 4916 |
* |
4917 |
* @since 5.1.0 |
|
4918 |
* |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4919 |
* @param array|string $input_list List of values. |
| 18 | 4920 |
* @return array Array of values. |
| 9 | 4921 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4922 |
function wp_parse_list( $input_list ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4923 |
if ( ! is_array( $input_list ) ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4924 |
return preg_split( '/[\s,]+/', $input_list, -1, PREG_SPLIT_NO_EMPTY ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4925 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4926 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4927 |
// Validate all entries of the list are scalar. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4928 |
$input_list = array_filter( $input_list, 'is_scalar' ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4929 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4930 |
return $input_list; |
| 9 | 4931 |
} |
4932 |
||
4933 |
/** |
|
| 18 | 4934 |
* Cleans up an array, comma- or space-separated list of IDs. |
| 0 | 4935 |
* |
4936 |
* @since 3.0.0 |
|
| 18 | 4937 |
* @since 5.1.0 Refactored to use wp_parse_list(). |
| 0 | 4938 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4939 |
* @param array|string $input_list List of IDs. |
| 16 | 4940 |
* @return int[] Sanitized array of IDs. |
| 0 | 4941 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4942 |
function wp_parse_id_list( $input_list ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4943 |
$input_list = wp_parse_list( $input_list ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4944 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4945 |
return array_unique( array_map( 'absint', $input_list ) ); |
| 0 | 4946 |
} |
4947 |
||
4948 |
/** |
|
| 18 | 4949 |
* Cleans up an array, comma- or space-separated list of slugs. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4950 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4951 |
* @since 4.7.0 |
| 18 | 4952 |
* @since 5.1.0 Refactored to use wp_parse_list(). |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4953 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4954 |
* @param array|string $input_list List of slugs. |
| 16 | 4955 |
* @return string[] Sanitized array of slugs. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4956 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4957 |
function wp_parse_slug_list( $input_list ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4958 |
$input_list = wp_parse_list( $input_list ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4959 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4960 |
return array_unique( array_map( 'sanitize_title', $input_list ) ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4961 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4962 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4963 |
/** |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4964 |
* Extracts a slice of an array, given a list of keys. |
| 0 | 4965 |
* |
4966 |
* @since 3.1.0 |
|
4967 |
* |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4968 |
* @param array $input_array The original array. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4969 |
* @param array $keys The list of keys. |
| 5 | 4970 |
* @return array The array slice. |
| 0 | 4971 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4972 |
function wp_array_slice_assoc( $input_array, $keys ) {
|
| 0 | 4973 |
$slice = array(); |
| 18 | 4974 |
|
| 9 | 4975 |
foreach ( $keys as $key ) {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4976 |
if ( isset( $input_array[ $key ] ) ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4977 |
$slice[ $key ] = $input_array[ $key ]; |
| 9 | 4978 |
} |
4979 |
} |
|
| 0 | 4980 |
|
4981 |
return $slice; |
|
4982 |
} |
|
4983 |
||
4984 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4985 |
* Sorts the keys of an array alphabetically. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4986 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4987 |
* The array is passed by reference so it doesn't get returned |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4988 |
* which mimics the behavior of `ksort()`. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4989 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4990 |
* @since 6.0.0 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4991 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4992 |
* @param array $input_array The array to sort, passed by reference. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4993 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4994 |
function wp_recursive_ksort( &$input_array ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4995 |
foreach ( $input_array as &$value ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4996 |
if ( is_array( $value ) ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4997 |
wp_recursive_ksort( $value ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4998 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4999 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5000 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5001 |
ksort( $input_array ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5002 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5003 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5004 |
/** |
| 18 | 5005 |
* Accesses an array in depth based on a path of keys. |
5006 |
* |
|
5007 |
* It is the PHP equivalent of JavaScript's `lodash.get()` and mirroring it may help other components |
|
5008 |
* retain some symmetry between client and server implementations. |
|
5009 |
* |
|
5010 |
* Example usage: |
|
5011 |
* |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5012 |
* $input_array = array( |
| 18 | 5013 |
* 'a' => array( |
5014 |
* 'b' => array( |
|
5015 |
* 'c' => 1, |
|
5016 |
* ), |
|
5017 |
* ), |
|
5018 |
* ); |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5019 |
* _wp_array_get( $input_array, array( 'a', 'b', 'c' ) ); |
| 18 | 5020 |
* |
5021 |
* @internal |
|
5022 |
* |
|
5023 |
* @since 5.6.0 |
|
5024 |
* @access private |
|
5025 |
* |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5026 |
* @param array $input_array An array from which we want to retrieve some information. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5027 |
* @param array $path An array of keys describing the path with which to retrieve information. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5028 |
* @param mixed $default_value Optional. The return value if the path does not exist within the array, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5029 |
* or if `$input_array` or `$path` are not arrays. Default null. |
| 18 | 5030 |
* @return mixed The value from the path specified. |
5031 |
*/ |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5032 |
function _wp_array_get( $input_array, $path, $default_value = null ) {
|
| 18 | 5033 |
// Confirm $path is valid. |
5034 |
if ( ! is_array( $path ) || 0 === count( $path ) ) {
|
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5035 |
return $default_value; |
| 18 | 5036 |
} |
5037 |
||
5038 |
foreach ( $path as $path_element ) {
|
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5039 |
if ( ! is_array( $input_array ) ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5040 |
return $default_value; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5041 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5042 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5043 |
if ( is_string( $path_element ) |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5044 |
|| is_integer( $path_element ) |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5045 |
|| null === $path_element |
| 18 | 5046 |
) {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5047 |
/* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5048 |
* Check if the path element exists in the input array. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5049 |
* We check with `isset()` first, as it is a lot faster |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5050 |
* than `array_key_exists()`. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5051 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5052 |
if ( isset( $input_array[ $path_element ] ) ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5053 |
$input_array = $input_array[ $path_element ]; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5054 |
continue; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5055 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5056 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5057 |
/* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5058 |
* If `isset()` returns false, we check with `array_key_exists()`, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5059 |
* which also checks for `null` values. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5060 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5061 |
if ( array_key_exists( $path_element, $input_array ) ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5062 |
$input_array = $input_array[ $path_element ]; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5063 |
continue; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5064 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5065 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5066 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5067 |
return $default_value; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5068 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5069 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5070 |
return $input_array; |
| 18 | 5071 |
} |
5072 |
||
5073 |
/** |
|
5074 |
* Sets an array in depth based on a path of keys. |
|
5075 |
* |
|
5076 |
* It is the PHP equivalent of JavaScript's `lodash.set()` and mirroring it may help other components |
|
5077 |
* retain some symmetry between client and server implementations. |
|
5078 |
* |
|
5079 |
* Example usage: |
|
5080 |
* |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5081 |
* $input_array = array(); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5082 |
* _wp_array_set( $input_array, array( 'a', 'b', 'c', 1 ) ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5083 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5084 |
* $input_array becomes: |
| 18 | 5085 |
* array( |
5086 |
* 'a' => array( |
|
5087 |
* 'b' => array( |
|
5088 |
* 'c' => 1, |
|
5089 |
* ), |
|
5090 |
* ), |
|
5091 |
* ); |
|
5092 |
* |
|
5093 |
* @internal |
|
5094 |
* |
|
5095 |
* @since 5.8.0 |
|
5096 |
* @access private |
|
5097 |
* |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5098 |
* @param array $input_array An array that we want to mutate to include a specific value in a path. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5099 |
* @param array $path An array of keys describing the path that we want to mutate. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5100 |
* @param mixed $value The value that will be set. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5101 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5102 |
function _wp_array_set( &$input_array, $path, $value = null ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5103 |
// Confirm $input_array is valid. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5104 |
if ( ! is_array( $input_array ) ) {
|
| 18 | 5105 |
return; |
5106 |
} |
|
5107 |
||
5108 |
// Confirm $path is valid. |
|
5109 |
if ( ! is_array( $path ) ) {
|
|
5110 |
return; |
|
5111 |
} |
|
5112 |
||
5113 |
$path_length = count( $path ); |
|
5114 |
||
5115 |
if ( 0 === $path_length ) {
|
|
5116 |
return; |
|
5117 |
} |
|
5118 |
||
5119 |
foreach ( $path as $path_element ) {
|
|
5120 |
if ( |
|
5121 |
! is_string( $path_element ) && ! is_integer( $path_element ) && |
|
5122 |
! is_null( $path_element ) |
|
5123 |
) {
|
|
5124 |
return; |
|
5125 |
} |
|
5126 |
} |
|
5127 |
||
5128 |
for ( $i = 0; $i < $path_length - 1; ++$i ) {
|
|
5129 |
$path_element = $path[ $i ]; |
|
5130 |
if ( |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5131 |
! array_key_exists( $path_element, $input_array ) || |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5132 |
! is_array( $input_array[ $path_element ] ) |
| 18 | 5133 |
) {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5134 |
$input_array[ $path_element ] = array(); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5135 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5136 |
$input_array = &$input_array[ $path_element ]; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5137 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5138 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5139 |
$input_array[ $path[ $i ] ] = $value; |
| 18 | 5140 |
} |
5141 |
||
5142 |
/** |
|
5143 |
* This function is trying to replicate what |
|
5144 |
* lodash's kebabCase (JS library) does in the client. |
|
5145 |
* |
|
5146 |
* The reason we need this function is that we do some processing |
|
5147 |
* in both the client and the server (e.g.: we generate |
|
5148 |
* preset classes from preset slugs) that needs to |
|
5149 |
* create the same output. |
|
5150 |
* |
|
5151 |
* We can't remove or update the client's library due to backward compatibility |
|
5152 |
* (some of the output of lodash's kebabCase is saved in the post content). |
|
5153 |
* We have to make the server behave like the client. |
|
5154 |
* |
|
5155 |
* Changes to this function should follow updates in the client |
|
5156 |
* with the same logic. |
|
5157 |
* |
|
5158 |
* @link https://github.com/lodash/lodash/blob/4.17/dist/lodash.js#L14369 |
|
5159 |
* @link https://github.com/lodash/lodash/blob/4.17/dist/lodash.js#L278 |
|
5160 |
* @link https://github.com/lodash-php/lodash-php/blob/master/src/String/kebabCase.php |
|
5161 |
* @link https://github.com/lodash-php/lodash-php/blob/master/src/internal/unicodeWords.php |
|
5162 |
* |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5163 |
* @param string $input_string The string to kebab-case. |
| 18 | 5164 |
* |
5165 |
* @return string kebab-cased-string. |
|
5166 |
*/ |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5167 |
function _wp_to_kebab_case( $input_string ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5168 |
// Ignore the camelCase names for variables so the names are the same as lodash so comparing and porting new changes is easier. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5169 |
// phpcs:disable WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase |
| 18 | 5170 |
|
5171 |
/* |
|
5172 |
* Some notable things we've removed compared to the lodash version are: |
|
5173 |
* |
|
5174 |
* - non-alphanumeric characters: rsAstralRange, rsEmoji, etc |
|
5175 |
* - the groups that processed the apostrophe, as it's removed before passing the string to preg_match: rsApos, rsOptContrLower, and rsOptContrUpper |
|
5176 |
* |
|
5177 |
*/ |
|
5178 |
||
5179 |
/** Used to compose unicode character classes. */ |
|
5180 |
$rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff'; |
|
5181 |
$rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf'; |
|
5182 |
$rsPunctuationRange = '\\x{2000}-\\x{206f}';
|
|
5183 |
$rsSpaceRange = ' \\t\\x0b\\f\\xa0\\x{feff}\\n\\r\\x{2028}\\x{2029}\\x{1680}\\x{180e}\\x{2000}\\x{2001}\\x{2002}\\x{2003}\\x{2004}\\x{2005}\\x{2006}\\x{2007}\\x{2008}\\x{2009}\\x{200a}\\x{202f}\\x{205f}\\x{3000}';
|
|
5184 |
$rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde'; |
|
5185 |
$rsBreakRange = $rsNonCharRange . $rsPunctuationRange . $rsSpaceRange; |
|
5186 |
||
5187 |
/** Used to compose unicode capture groups. */ |
|
5188 |
$rsBreak = '[' . $rsBreakRange . ']'; |
|
5189 |
$rsDigits = '\\d+'; // The last lodash version in GitHub uses a single digit here and expands it when in use. |
|
5190 |
$rsLower = '[' . $rsLowerRange . ']'; |
|
5191 |
$rsMisc = '[^' . $rsBreakRange . $rsDigits . $rsLowerRange . $rsUpperRange . ']'; |
|
5192 |
$rsUpper = '[' . $rsUpperRange . ']'; |
|
5193 |
||
5194 |
/** Used to compose unicode regexes. */ |
|
5195 |
$rsMiscLower = '(?:' . $rsLower . '|' . $rsMisc . ')'; |
|
5196 |
$rsMiscUpper = '(?:' . $rsUpper . '|' . $rsMisc . ')'; |
|
5197 |
$rsOrdLower = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])'; |
|
5198 |
$rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])'; |
|
5199 |
||
5200 |
$regexp = '/' . implode( |
|
5201 |
'|', |
|
5202 |
array( |
|
5203 |
$rsUpper . '?' . $rsLower . '+' . '(?=' . implode( '|', array( $rsBreak, $rsUpper, '$' ) ) . ')', |
|
5204 |
$rsMiscUpper . '+' . '(?=' . implode( '|', array( $rsBreak, $rsUpper . $rsMiscLower, '$' ) ) . ')', |
|
5205 |
$rsUpper . '?' . $rsMiscLower . '+', |
|
5206 |
$rsUpper . '+', |
|
5207 |
$rsOrdUpper, |
|
5208 |
$rsOrdLower, |
|
5209 |
$rsDigits, |
|
5210 |
) |
|
5211 |
) . '/u'; |
|
5212 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5213 |
preg_match_all( $regexp, str_replace( "'", '', $input_string ), $matches ); |
| 18 | 5214 |
return strtolower( implode( '-', $matches[0] ) ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5215 |
// phpcs:enable WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase |
| 18 | 5216 |
} |
5217 |
||
5218 |
/** |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5219 |
* Determines if the variable is a numeric-indexed array. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5220 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5221 |
* @since 4.4.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5222 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5223 |
* @param mixed $data Variable to check. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5224 |
* @return bool Whether the variable is a list. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5225 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5226 |
function wp_is_numeric_array( $data ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5227 |
if ( ! is_array( $data ) ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5228 |
return false; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5229 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5230 |
|
| 9 | 5231 |
$keys = array_keys( $data ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5232 |
$string_keys = array_filter( $keys, 'is_string' ); |
| 18 | 5233 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5234 |
return count( $string_keys ) === 0; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5235 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5236 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5237 |
/** |
| 0 | 5238 |
* Filters a list of objects, based on a set of key => value arguments. |
5239 |
* |
|
| 18 | 5240 |
* Retrieves the objects from the list that match the given arguments. |
5241 |
* Key represents property name, and value represents property value. |
|
5242 |
* |
|
5243 |
* If an object has more properties than those specified in arguments, |
|
5244 |
* that will not disqualify it. When using the 'AND' operator, |
|
5245 |
* any missing properties will disqualify it. |
|
5246 |
* |
|
5247 |
* When using the `$field` argument, this function can also retrieve |
|
5248 |
* a particular field from all matching objects, whereas wp_list_filter() |
|
5249 |
* only does the filtering. |
|
5250 |
* |
|
| 0 | 5251 |
* @since 3.0.0 |
| 9 | 5252 |
* @since 4.7.0 Uses `WP_List_Util` class. |
| 0 | 5253 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5254 |
* @param array $input_list An array of objects to filter. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5255 |
* @param array $args Optional. An array of key => value arguments to match |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5256 |
* against each object. Default empty array. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5257 |
* @param string $operator Optional. The logical operation to perform. 'AND' means |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5258 |
* all elements from the array must match. 'OR' means only |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5259 |
* one element needs to match. 'NOT' means no elements may |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5260 |
* match. Default 'AND'. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5261 |
* @param bool|string $field Optional. A field from the object to place instead |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5262 |
* of the entire object. Default false. |
| 5 | 5263 |
* @return array A list of objects or object fields. |
| 0 | 5264 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5265 |
function wp_filter_object_list( $input_list, $args = array(), $operator = 'and', $field = false ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5266 |
if ( ! is_array( $input_list ) ) {
|
| 0 | 5267 |
return array(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5268 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5269 |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5270 |
$util = new WP_List_Util( $input_list ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5271 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5272 |
$util->filter( $args, $operator ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5273 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5274 |
if ( $field ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5275 |
$util->pluck( $field ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5276 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5277 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5278 |
return $util->get_output(); |
| 0 | 5279 |
} |
5280 |
||
5281 |
/** |
|
5282 |
* Filters a list of objects, based on a set of key => value arguments. |
|
5283 |
* |
|
| 18 | 5284 |
* Retrieves the objects from the list that match the given arguments. |
5285 |
* Key represents property name, and value represents property value. |
|
5286 |
* |
|
5287 |
* If an object has more properties than those specified in arguments, |
|
5288 |
* that will not disqualify it. When using the 'AND' operator, |
|
5289 |
* any missing properties will disqualify it. |
|
5290 |
* |
|
5291 |
* If you want to retrieve a particular field from all matching objects, |
|
5292 |
* use wp_filter_object_list() instead. |
|
5293 |
* |
|
| 0 | 5294 |
* @since 3.1.0 |
| 9 | 5295 |
* @since 4.7.0 Uses `WP_List_Util` class. |
| 19 | 5296 |
* @since 5.9.0 Converted into a wrapper for `wp_filter_object_list()`. |
| 0 | 5297 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5298 |
* @param array $input_list An array of objects to filter. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5299 |
* @param array $args Optional. An array of key => value arguments to match |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5300 |
* against each object. Default empty array. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5301 |
* @param string $operator Optional. The logical operation to perform. 'AND' means |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5302 |
* all elements from the array must match. 'OR' means only |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5303 |
* one element needs to match. 'NOT' means no elements may |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5304 |
* match. Default 'AND'. |
| 5 | 5305 |
* @return array Array of found values. |
| 0 | 5306 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5307 |
function wp_list_filter( $input_list, $args = array(), $operator = 'AND' ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5308 |
return wp_filter_object_list( $input_list, $args, $operator ); |
| 19 | 5309 |
} |
5310 |
||
5311 |
/** |
|
5312 |
* Plucks a certain field out of each object or array in an array. |
|
| 0 | 5313 |
* |
| 5 | 5314 |
* This has the same functionality and prototype of |
5315 |
* array_column() (PHP 5.5) but also supports objects. |
|
5316 |
* |
|
| 0 | 5317 |
* @since 3.1.0 |
| 5 | 5318 |
* @since 4.0.0 $index_key parameter added. |
| 9 | 5319 |
* @since 4.7.0 Uses `WP_List_Util` class. |
| 5 | 5320 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5321 |
* @param array $input_list List of objects or arrays. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5322 |
* @param int|string $field Field from the object to place instead of the entire object. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5323 |
* @param int|string $index_key Optional. Field from the object to use as keys for the new array. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5324 |
* Default null. |
| 5 | 5325 |
* @return array Array of found values. If `$index_key` is set, an array of found values with keys |
5326 |
* corresponding to `$index_key`. If `$index_key` is null, array keys from the original |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5327 |
* `$input_list` will be preserved in the results. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5328 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5329 |
function wp_list_pluck( $input_list, $field, $index_key = null ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5330 |
if ( ! is_array( $input_list ) ) {
|
| 19 | 5331 |
return array(); |
5332 |
} |
|
5333 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5334 |
$util = new WP_List_Util( $input_list ); |
| 18 | 5335 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5336 |
return $util->pluck( $field, $index_key ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5337 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5338 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5339 |
/** |
| 19 | 5340 |
* Sorts an array of objects or arrays based on one or more orderby arguments. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5341 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5342 |
* @since 4.7.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5343 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5344 |
* @param array $input_list An array of objects or arrays to sort. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5345 |
* @param string|array $orderby Optional. Either the field name to order by or an array |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5346 |
* of multiple orderby fields as `$orderby => $order`. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5347 |
* Default empty array. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5348 |
* @param string $order Optional. Either 'ASC' or 'DESC'. Only used if `$orderby` |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5349 |
* is a string. Default 'ASC'. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5350 |
* @param bool $preserve_keys Optional. Whether to preserve keys. Default false. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5351 |
* @return array The sorted array. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5352 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5353 |
function wp_list_sort( $input_list, $orderby = array(), $order = 'ASC', $preserve_keys = false ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5354 |
if ( ! is_array( $input_list ) ) {
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5355 |
return array(); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5356 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5357 |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5358 |
$util = new WP_List_Util( $input_list ); |
| 18 | 5359 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5360 |
return $util->sort( $orderby, $order, $preserve_keys ); |
| 0 | 5361 |
} |
5362 |
||
5363 |
/** |
|
5364 |
* Determines if Widgets library should be loaded. |
|
5365 |
* |
|
| 5 | 5366 |
* Checks to make sure that the widgets library hasn't already been loaded. |
5367 |
* If it hasn't, then it will load the widgets library and run an action hook. |
|
| 0 | 5368 |
* |
5369 |
* @since 2.2.0 |
|
5370 |
*/ |
|
5371 |
function wp_maybe_load_widgets() {
|
|
| 5 | 5372 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5373 |
* Filters whether to load the Widgets library. |
| 5 | 5374 |
* |
| 16 | 5375 |
* Returning a falsey value from the filter will effectively short-circuit |
| 5 | 5376 |
* the Widgets library from loading. |
5377 |
* |
|
5378 |
* @since 2.8.0 |
|
5379 |
* |
|
5380 |
* @param bool $wp_maybe_load_widgets Whether to load the Widgets library. |
|
5381 |
* Default true. |
|
5382 |
*/ |
|
5383 |
if ( ! apply_filters( 'load_default_widgets', true ) ) {
|
|
| 0 | 5384 |
return; |
| 5 | 5385 |
} |
5386 |
||
| 16 | 5387 |
require_once ABSPATH . WPINC . '/default-widgets.php'; |
| 5 | 5388 |
|
| 0 | 5389 |
add_action( '_admin_menu', 'wp_widgets_add_menu' ); |
5390 |
} |
|
5391 |
||
5392 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5393 |
* Appends the Widgets menu to the themes main menu. |
| 0 | 5394 |
* |
5395 |
* @since 2.2.0 |
|
| 19 | 5396 |
* @since 5.9.3 Don't specify menu order when the active theme is a block theme. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5397 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5398 |
* @global array $submenu |
| 0 | 5399 |
*/ |
5400 |
function wp_widgets_add_menu() {
|
|
5401 |
global $submenu; |
|
5402 |
||
| 9 | 5403 |
if ( ! current_theme_supports( 'widgets' ) ) {
|
| 0 | 5404 |
return; |
| 9 | 5405 |
} |
| 0 | 5406 |
|
| 19 | 5407 |
$menu_name = __( 'Widgets' ); |
5408 |
if ( wp_is_block_theme() ) {
|
|
5409 |
$submenu['themes.php'][] = array( $menu_name, 'edit_theme_options', 'widgets.php' ); |
|
5410 |
} else {
|
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5411 |
$submenu['themes.php'][8] = array( $menu_name, 'edit_theme_options', 'widgets.php' ); |
| 19 | 5412 |
} |
5413 |
||
| 0 | 5414 |
ksort( $submenu['themes.php'], SORT_NUMERIC ); |
5415 |
} |
|
5416 |
||
5417 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5418 |
* Flushes all output buffers for PHP 5.2. |
| 0 | 5419 |
* |
| 5 | 5420 |
* Make sure all output buffers are flushed before our singletons are destroyed. |
| 0 | 5421 |
* |
5422 |
* @since 2.2.0 |
|
5423 |
*/ |
|
5424 |
function wp_ob_end_flush_all() {
|
|
5425 |
$levels = ob_get_level(); |
|
| 9 | 5426 |
for ( $i = 0; $i < $levels; $i++ ) {
|
| 0 | 5427 |
ob_end_flush(); |
| 9 | 5428 |
} |
| 0 | 5429 |
} |
5430 |
||
5431 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5432 |
* Loads custom DB error or display WordPress DB error. |
| 0 | 5433 |
* |
5434 |
* If a file exists in the wp-content directory named db-error.php, then it will |
|
5435 |
* be loaded instead of displaying the WordPress DB error. If it is not found, |
|
5436 |
* then the WordPress DB error will be displayed instead. |
|
5437 |
* |
|
5438 |
* The WordPress DB error sets the HTTP status header to 500 to try to prevent |
|
5439 |
* search engines from caching the message. Custom DB messages should do the |
|
5440 |
* same. |
|
5441 |
* |
|
5442 |
* This function was backported to WordPress 2.3.2, but originally was added |
|
5443 |
* in WordPress 2.5.0. |
|
5444 |
* |
|
5445 |
* @since 2.3.2 |
|
| 5 | 5446 |
* |
5447 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
| 0 | 5448 |
*/ |
5449 |
function dead_db() {
|
|
5450 |
global $wpdb; |
|
5451 |
||
| 5 | 5452 |
wp_load_translations_early(); |
5453 |
||
| 0 | 5454 |
// Load custom DB error template, if present. |
5455 |
if ( file_exists( WP_CONTENT_DIR . '/db-error.php' ) ) {
|
|
| 16 | 5456 |
require_once WP_CONTENT_DIR . '/db-error.php'; |
| 0 | 5457 |
die(); |
5458 |
} |
|
5459 |
||
5460 |
// If installing or in the admin, provide the verbose message. |
|
| 9 | 5461 |
if ( wp_installing() || defined( 'WP_ADMIN' ) ) {
|
5462 |
wp_die( $wpdb->error ); |
|
5463 |
} |
|
| 0 | 5464 |
|
5465 |
// Otherwise, be terse. |
|
| 9 | 5466 |
wp_die( '<h1>' . __( 'Error establishing a database connection' ) . '</h1>', __( 'Database Error' ) ); |
| 0 | 5467 |
} |
5468 |
||
5469 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5470 |
* Converts a value to non-negative integer. |
| 0 | 5471 |
* |
5472 |
* @since 2.5.0 |
|
5473 |
* |
|
| 5 | 5474 |
* @param mixed $maybeint Data you wish to have converted to a non-negative integer. |
5475 |
* @return int A non-negative integer. |
|
| 0 | 5476 |
*/ |
5477 |
function absint( $maybeint ) {
|
|
| 18 | 5478 |
return abs( (int) $maybeint ); |
| 0 | 5479 |
} |
5480 |
||
5481 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5482 |
* Marks a function as deprecated and inform when it has been used. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5483 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5484 |
* There is a {@see 'deprecated_function_run'} hook that will be called that can be used
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5485 |
* to get the backtrace up to what file and function called the deprecated function. |
| 0 | 5486 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5487 |
* The current behavior is to trigger a user error if `WP_DEBUG` is true. |
| 0 | 5488 |
* |
5489 |
* This function is to be used in every function that is deprecated. |
|
5490 |
* |
|
5491 |
* @since 2.5.0 |
|
| 16 | 5492 |
* @since 5.4.0 This function is no longer marked as "private". |
5493 |
* @since 5.4.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE). |
|
| 0 | 5494 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5495 |
* @param string $function_name The function that was called. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5496 |
* @param string $version The version of WordPress that deprecated the function. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5497 |
* @param string $replacement Optional. The function that should have been called. Default empty string. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5498 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5499 |
function _deprecated_function( $function_name, $version, $replacement = '' ) {
|
| 0 | 5500 |
|
| 5 | 5501 |
/** |
5502 |
* Fires when a deprecated function is called. |
|
5503 |
* |
|
5504 |
* @since 2.5.0 |
|
5505 |
* |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5506 |
* @param string $function_name The function that was called. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5507 |
* @param string $replacement The function that should have been called. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5508 |
* @param string $version The version of WordPress that deprecated the function. |
| 5 | 5509 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5510 |
do_action( 'deprecated_function_run', $function_name, $replacement, $version ); |
| 0 | 5511 |
|
| 5 | 5512 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5513 |
* Filters whether to trigger an error for deprecated functions. |
| 5 | 5514 |
* |
5515 |
* @since 2.5.0 |
|
5516 |
* |
|
5517 |
* @param bool $trigger Whether to trigger the error for deprecated functions. Default true. |
|
5518 |
*/ |
|
| 0 | 5519 |
if ( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true ) ) {
|
5520 |
if ( function_exists( '__' ) ) {
|
|
| 16 | 5521 |
if ( $replacement ) {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5522 |
$message = sprintf( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5523 |
/* translators: 1: PHP function name, 2: Version number, 3: Alternative function name. */ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5524 |
__( 'Function %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5525 |
$function_name, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5526 |
$version, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5527 |
$replacement |
| 16 | 5528 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5529 |
} else {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5530 |
$message = sprintf( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5531 |
/* translators: 1: PHP function name, 2: Version number. */ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5532 |
__( 'Function %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5533 |
$function_name, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5534 |
$version |
| 16 | 5535 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5536 |
} |
| 0 | 5537 |
} else {
|
| 16 | 5538 |
if ( $replacement ) {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5539 |
$message = sprintf( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5540 |
'Function %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5541 |
$function_name, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5542 |
$version, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5543 |
$replacement |
| 16 | 5544 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5545 |
} else {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5546 |
$message = sprintf( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5547 |
'Function %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5548 |
$function_name, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5549 |
$version |
| 16 | 5550 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5551 |
} |
| 0 | 5552 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5553 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5554 |
wp_trigger_error( '', $message, E_USER_DEPRECATED ); |
| 0 | 5555 |
} |
5556 |
} |
|
5557 |
||
5558 |
/** |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5559 |
* Marks a constructor as deprecated and informs when it has been used. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5560 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5561 |
* Similar to _deprecated_function(), but with different strings. Used to |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5562 |
* remove PHP4-style constructors. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5563 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5564 |
* The current behavior is to trigger a user error if `WP_DEBUG` is true. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5565 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5566 |
* This function is to be used in every PHP4-style constructor method that is deprecated. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5567 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5568 |
* @since 4.3.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5569 |
* @since 4.5.0 Added the `$parent_class` parameter. |
| 16 | 5570 |
* @since 5.4.0 This function is no longer marked as "private". |
5571 |
* @since 5.4.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE). |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5572 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5573 |
* @param string $class_name The class containing the deprecated constructor. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5574 |
* @param string $version The version of WordPress that deprecated the function. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5575 |
* @param string $parent_class Optional. The parent class calling the deprecated constructor. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5576 |
* Default empty string. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5577 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5578 |
function _deprecated_constructor( $class_name, $version, $parent_class = '' ) {
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5579 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5580 |
/** |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5581 |
* Fires when a deprecated constructor is called. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5582 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5583 |
* @since 4.3.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5584 |
* @since 4.5.0 Added the `$parent_class` parameter. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5585 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5586 |
* @param string $class_name The class containing the deprecated constructor. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5587 |
* @param string $version The version of WordPress that deprecated the function. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5588 |
* @param string $parent_class The parent class calling the deprecated constructor. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5589 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5590 |
do_action( 'deprecated_constructor_run', $class_name, $version, $parent_class ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5591 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5592 |
/** |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5593 |
* Filters whether to trigger an error for deprecated functions. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5594 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5595 |
* `WP_DEBUG` must be true in addition to the filter evaluating to true. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5596 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5597 |
* @since 4.3.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5598 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5599 |
* @param bool $trigger Whether to trigger the error for deprecated functions. Default true. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5600 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5601 |
if ( WP_DEBUG && apply_filters( 'deprecated_constructor_trigger_error', true ) ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5602 |
if ( function_exists( '__' ) ) {
|
| 16 | 5603 |
if ( $parent_class ) {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5604 |
$message = sprintf( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5605 |
/* translators: 1: PHP class name, 2: PHP parent class name, 3: Version number, 4: __construct() method. */ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5606 |
__( 'The called constructor method for %1$s class in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.' ), |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5607 |
$class_name, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5608 |
$parent_class, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5609 |
$version, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5610 |
'<code>__construct()</code>' |
| 9 | 5611 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5612 |
} else {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5613 |
$message = sprintf( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5614 |
/* translators: 1: PHP class name, 2: Version number, 3: __construct() method. */ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5615 |
__( 'The called constructor method for %1$s class is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5616 |
$class_name, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5617 |
$version, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5618 |
'<code>__construct()</code>' |
| 9 | 5619 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5620 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5621 |
} else {
|
| 16 | 5622 |
if ( $parent_class ) {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5623 |
$message = sprintf( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5624 |
'The called constructor method for %1$s class in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.', |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5625 |
$class_name, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5626 |
$parent_class, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5627 |
$version, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5628 |
'<code>__construct()</code>' |
| 9 | 5629 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5630 |
} else {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5631 |
$message = sprintf( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5632 |
'The called constructor method for %1$s class is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5633 |
$class_name, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5634 |
$version, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5635 |
'<code>__construct()</code>' |
| 9 | 5636 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5637 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5638 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5639 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5640 |
wp_trigger_error( '', $message, E_USER_DEPRECATED ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5641 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5642 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5643 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5644 |
/** |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5645 |
* Marks a class as deprecated and informs when it has been used. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5646 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5647 |
* There is a {@see 'deprecated_class_run'} hook that will be called that can be used
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5648 |
* to get the backtrace up to what file and function called the deprecated class. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5649 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5650 |
* The current behavior is to trigger a user error if `WP_DEBUG` is true. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5651 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5652 |
* This function is to be used in the class constructor for every deprecated class. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5653 |
* See {@see _deprecated_constructor()} for deprecating PHP4-style constructors.
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5654 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5655 |
* @since 6.4.0 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5656 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5657 |
* @param string $class_name The name of the class being instantiated. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5658 |
* @param string $version The version of WordPress that deprecated the class. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5659 |
* @param string $replacement Optional. The class or function that should have been called. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5660 |
* Default empty string. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5661 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5662 |
function _deprecated_class( $class_name, $version, $replacement = '' ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5663 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5664 |
/** |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5665 |
* Fires when a deprecated class is called. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5666 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5667 |
* @since 6.4.0 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5668 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5669 |
* @param string $class_name The name of the class being instantiated. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5670 |
* @param string $replacement The class or function that should have been called. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5671 |
* @param string $version The version of WordPress that deprecated the class. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5672 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5673 |
do_action( 'deprecated_class_run', $class_name, $replacement, $version ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5674 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5675 |
/** |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5676 |
* Filters whether to trigger an error for a deprecated class. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5677 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5678 |
* @since 6.4.0 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5679 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5680 |
* @param bool $trigger Whether to trigger an error for a deprecated class. Default true. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5681 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5682 |
if ( WP_DEBUG && apply_filters( 'deprecated_class_trigger_error', true ) ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5683 |
if ( function_exists( '__' ) ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5684 |
if ( $replacement ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5685 |
$message = sprintf( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5686 |
/* translators: 1: PHP class name, 2: Version number, 3: Alternative class or function name. */ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5687 |
__( 'Class %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5688 |
$class_name, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5689 |
$version, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5690 |
$replacement |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5691 |
); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5692 |
} else {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5693 |
$message = sprintf( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5694 |
/* translators: 1: PHP class name, 2: Version number. */ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5695 |
__( 'Class %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5696 |
$class_name, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5697 |
$version |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5698 |
); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5699 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5700 |
} else {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5701 |
if ( $replacement ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5702 |
$message = sprintf( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5703 |
'Class %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5704 |
$class_name, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5705 |
$version, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5706 |
$replacement |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5707 |
); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5708 |
} else {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5709 |
$message = sprintf( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5710 |
'Class %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5711 |
$class_name, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5712 |
$version |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5713 |
); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5714 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5715 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5716 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5717 |
wp_trigger_error( '', $message, E_USER_DEPRECATED ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5718 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5719 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5720 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5721 |
/** |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5722 |
* Marks a file as deprecated and inform when it has been used. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5723 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5724 |
* There is a {@see 'deprecated_file_included'} hook that will be called that can be used
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5725 |
* to get the backtrace up to what file and function included the deprecated file. |
| 0 | 5726 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5727 |
* The current behavior is to trigger a user error if `WP_DEBUG` is true. |
| 0 | 5728 |
* |
5729 |
* This function is to be used in every file that is deprecated. |
|
5730 |
* |
|
5731 |
* @since 2.5.0 |
|
| 16 | 5732 |
* @since 5.4.0 This function is no longer marked as "private". |
5733 |
* @since 5.4.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE). |
|
| 0 | 5734 |
* |
| 5 | 5735 |
* @param string $file The file that was included. |
5736 |
* @param string $version The version of WordPress that deprecated the file. |
|
5737 |
* @param string $replacement Optional. The file that should have been included based on ABSPATH. |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5738 |
* Default empty string. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5739 |
* @param string $message Optional. A message regarding the change. Default empty string. |
| 0 | 5740 |
*/ |
| 16 | 5741 |
function _deprecated_file( $file, $version, $replacement = '', $message = '' ) {
|
| 0 | 5742 |
|
| 5 | 5743 |
/** |
5744 |
* Fires when a deprecated file is called. |
|
5745 |
* |
|
5746 |
* @since 2.5.0 |
|
5747 |
* |
|
5748 |
* @param string $file The file that was called. |
|
5749 |
* @param string $replacement The file that should have been included based on ABSPATH. |
|
5750 |
* @param string $version The version of WordPress that deprecated the file. |
|
5751 |
* @param string $message A message regarding the change. |
|
5752 |
*/ |
|
| 0 | 5753 |
do_action( 'deprecated_file_included', $file, $replacement, $version, $message ); |
5754 |
||
| 5 | 5755 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5756 |
* Filters whether to trigger an error for deprecated files. |
| 5 | 5757 |
* |
5758 |
* @since 2.5.0 |
|
5759 |
* |
|
5760 |
* @param bool $trigger Whether to trigger the error for deprecated files. Default true. |
|
5761 |
*/ |
|
| 0 | 5762 |
if ( WP_DEBUG && apply_filters( 'deprecated_file_trigger_error', true ) ) {
|
5763 |
$message = empty( $message ) ? '' : ' ' . $message; |
|
| 16 | 5764 |
|
| 0 | 5765 |
if ( function_exists( '__' ) ) {
|
| 16 | 5766 |
if ( $replacement ) {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5767 |
$message = sprintf( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5768 |
/* translators: 1: PHP file name, 2: Version number, 3: Alternative file name. */ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5769 |
__( 'File %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5770 |
$file, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5771 |
$version, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5772 |
$replacement |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5773 |
) . $message; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5774 |
} else {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5775 |
$message = sprintf( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5776 |
/* translators: 1: PHP file name, 2: Version number. */ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5777 |
__( 'File %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5778 |
$file, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5779 |
$version |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5780 |
) . $message; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5781 |
} |
| 0 | 5782 |
} else {
|
| 16 | 5783 |
if ( $replacement ) {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5784 |
$message = sprintf( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5785 |
'File %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5786 |
$file, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5787 |
$version, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5788 |
$replacement |
| 16 | 5789 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5790 |
} else {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5791 |
$message = sprintf( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5792 |
'File %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5793 |
$file, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5794 |
$version |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5795 |
) . $message; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5796 |
} |
| 0 | 5797 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5798 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5799 |
wp_trigger_error( '', $message, E_USER_DEPRECATED ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5800 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5801 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5802 |
/** |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5803 |
* Marks a function argument as deprecated and inform when it has been used. |
| 0 | 5804 |
* |
5805 |
* This function is to be used whenever a deprecated function argument is used. |
|
5806 |
* Before this function is called, the argument must be checked for whether it was |
|
5807 |
* used by comparing it to its default value or evaluating whether it is empty. |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5808 |
* |
| 0 | 5809 |
* For example: |
| 5 | 5810 |
* |
5811 |
* if ( ! empty( $deprecated ) ) {
|
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5812 |
* _deprecated_argument( __FUNCTION__, '3.0.0' ); |
| 5 | 5813 |
* } |
5814 |
* |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5815 |
* There is a {@see 'deprecated_argument_run'} hook that will be called that can be used
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5816 |
* to get the backtrace up to what file and function used the deprecated argument. |
| 0 | 5817 |
* |
5818 |
* The current behavior is to trigger a user error if WP_DEBUG is true. |
|
5819 |
* |
|
5820 |
* @since 3.0.0 |
|
| 16 | 5821 |
* @since 5.4.0 This function is no longer marked as "private". |
5822 |
* @since 5.4.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE). |
|
| 0 | 5823 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5824 |
* @param string $function_name The function that was called. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5825 |
* @param string $version The version of WordPress that deprecated the argument used. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5826 |
* @param string $message Optional. A message regarding the change. Default empty string. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5827 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5828 |
function _deprecated_argument( $function_name, $version, $message = '' ) {
|
| 0 | 5829 |
|
| 5 | 5830 |
/** |
5831 |
* Fires when a deprecated argument is called. |
|
5832 |
* |
|
5833 |
* @since 3.0.0 |
|
5834 |
* |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5835 |
* @param string $function_name The function that was called. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5836 |
* @param string $message A message regarding the change. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5837 |
* @param string $version The version of WordPress that deprecated the argument used. |
| 5 | 5838 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5839 |
do_action( 'deprecated_argument_run', $function_name, $message, $version ); |
| 0 | 5840 |
|
| 5 | 5841 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5842 |
* Filters whether to trigger an error for deprecated arguments. |
| 5 | 5843 |
* |
5844 |
* @since 3.0.0 |
|
5845 |
* |
|
5846 |
* @param bool $trigger Whether to trigger the error for deprecated arguments. Default true. |
|
5847 |
*/ |
|
| 0 | 5848 |
if ( WP_DEBUG && apply_filters( 'deprecated_argument_trigger_error', true ) ) {
|
5849 |
if ( function_exists( '__' ) ) {
|
|
| 16 | 5850 |
if ( $message ) {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5851 |
$message = sprintf( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5852 |
/* translators: 1: PHP function name, 2: Version number, 3: Optional message regarding the change. */ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5853 |
__( 'Function %1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s' ), |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5854 |
$function_name, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5855 |
$version, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5856 |
$message |
| 16 | 5857 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5858 |
} else {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5859 |
$message = sprintf( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5860 |
/* translators: 1: PHP function name, 2: Version number. */ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5861 |
__( 'Function %1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.' ), |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5862 |
$function_name, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5863 |
$version |
| 16 | 5864 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5865 |
} |
| 0 | 5866 |
} else {
|
| 16 | 5867 |
if ( $message ) {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5868 |
$message = sprintf( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5869 |
'Function %1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s', |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5870 |
$function_name, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5871 |
$version, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5872 |
$message |
| 16 | 5873 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5874 |
} else {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5875 |
$message = sprintf( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5876 |
'Function %1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.', |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5877 |
$function_name, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5878 |
$version |
| 16 | 5879 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5880 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5881 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5882 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5883 |
wp_trigger_error( '', $message, E_USER_DEPRECATED ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5884 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5885 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5886 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5887 |
/** |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5888 |
* Marks a deprecated action or filter hook as deprecated and throws a notice. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5889 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5890 |
* Use the {@see 'deprecated_hook_run'} action to get the backtrace describing where
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5891 |
* the deprecated hook was called. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5892 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5893 |
* Default behavior is to trigger a user error if `WP_DEBUG` is true. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5894 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5895 |
* This function is called by the do_action_deprecated() and apply_filters_deprecated() |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5896 |
* functions, and so generally does not need to be called directly. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5897 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5898 |
* @since 4.6.0 |
| 16 | 5899 |
* @since 5.4.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE). |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5900 |
* @access private |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5901 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5902 |
* @param string $hook The hook that was used. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5903 |
* @param string $version The version of WordPress that deprecated the hook. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5904 |
* @param string $replacement Optional. The hook that should have been used. Default empty string. |
| 16 | 5905 |
* @param string $message Optional. A message regarding the change. Default empty. |
5906 |
*/ |
|
5907 |
function _deprecated_hook( $hook, $version, $replacement = '', $message = '' ) {
|
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5908 |
/** |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5909 |
* Fires when a deprecated hook is called. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5910 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5911 |
* @since 4.6.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5912 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5913 |
* @param string $hook The hook that was called. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5914 |
* @param string $replacement The hook that should be used as a replacement. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5915 |
* @param string $version The version of WordPress that deprecated the argument used. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5916 |
* @param string $message A message regarding the change. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5917 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5918 |
do_action( 'deprecated_hook_run', $hook, $replacement, $version, $message ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5919 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5920 |
/** |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5921 |
* Filters whether to trigger deprecated hook errors. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5922 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5923 |
* @since 4.6.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5924 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5925 |
* @param bool $trigger Whether to trigger deprecated hook errors. Requires |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5926 |
* `WP_DEBUG` to be defined true. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5927 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5928 |
if ( WP_DEBUG && apply_filters( 'deprecated_hook_trigger_error', true ) ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5929 |
$message = empty( $message ) ? '' : ' ' . $message; |
| 16 | 5930 |
|
5931 |
if ( $replacement ) {
|
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5932 |
$message = sprintf( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5933 |
/* translators: 1: WordPress hook name, 2: Version number, 3: Alternative hook name. */ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5934 |
__( 'Hook %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5935 |
$hook, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5936 |
$version, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5937 |
$replacement |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5938 |
) . $message; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5939 |
} else {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5940 |
$message = sprintf( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5941 |
/* translators: 1: WordPress hook name, 2: Version number. */ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5942 |
__( 'Hook %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5943 |
$hook, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5944 |
$version |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5945 |
) . $message; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5946 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5947 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5948 |
wp_trigger_error( '', $message, E_USER_DEPRECATED ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5949 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5950 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5951 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5952 |
/** |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5953 |
* Marks something as being incorrectly called. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5954 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5955 |
* There is a {@see 'doing_it_wrong_run'} hook that will be called that can be used
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5956 |
* to get the backtrace up to what file and function called the deprecated function. |
| 0 | 5957 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5958 |
* The current behavior is to trigger a user error if `WP_DEBUG` is true. |
| 0 | 5959 |
* |
5960 |
* @since 3.1.0 |
|
| 16 | 5961 |
* @since 5.4.0 This function is no longer marked as "private". |
| 0 | 5962 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5963 |
* @param string $function_name The function that was called. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5964 |
* @param string $message A message explaining what has been done incorrectly. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5965 |
* @param string $version The version of WordPress where the message was added. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5966 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5967 |
function _doing_it_wrong( $function_name, $message, $version ) {
|
| 0 | 5968 |
|
| 5 | 5969 |
/** |
5970 |
* Fires when the given function is being used incorrectly. |
|
5971 |
* |
|
5972 |
* @since 3.1.0 |
|
5973 |
* |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5974 |
* @param string $function_name The function that was called. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5975 |
* @param string $message A message explaining what has been done incorrectly. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5976 |
* @param string $version The version of WordPress where the message was added. |
| 5 | 5977 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5978 |
do_action( 'doing_it_wrong_run', $function_name, $message, $version ); |
| 0 | 5979 |
|
| 5 | 5980 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5981 |
* Filters whether to trigger an error for _doing_it_wrong() calls. |
| 5 | 5982 |
* |
5983 |
* @since 3.1.0 |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5984 |
* @since 5.1.0 Added the $function_name, $message and $version parameters. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5985 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5986 |
* @param bool $trigger Whether to trigger the error for _doing_it_wrong() calls. Default true. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5987 |
* @param string $function_name The function that was called. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5988 |
* @param string $message A message explaining what has been done incorrectly. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5989 |
* @param string $version The version of WordPress where the message was added. |
| 5 | 5990 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5991 |
if ( WP_DEBUG && apply_filters( 'doing_it_wrong_trigger_error', true, $function_name, $message, $version ) ) {
|
| 0 | 5992 |
if ( function_exists( '__' ) ) {
|
| 16 | 5993 |
if ( $version ) {
|
5994 |
/* translators: %s: Version number. */ |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5995 |
$version = sprintf( __( '(This message was added in version %s.)' ), $version ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5996 |
} |
| 16 | 5997 |
|
| 9 | 5998 |
$message .= ' ' . sprintf( |
| 16 | 5999 |
/* translators: %s: Documentation URL. */ |
| 9 | 6000 |
__( 'Please see <a href="%s">Debugging in WordPress</a> for more information.' ), |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6001 |
__( 'https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/' ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6002 |
); |
| 16 | 6003 |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6004 |
$message = sprintf( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6005 |
/* translators: Developer debugging message. 1: PHP function name, 2: Explanatory message, 3: WordPress version number. */ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6006 |
__( 'Function %1$s was called <strong>incorrectly</strong>. %2$s %3$s' ), |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6007 |
$function_name, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6008 |
$message, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6009 |
$version |
| 16 | 6010 |
); |
| 0 | 6011 |
} else {
|
| 16 | 6012 |
if ( $version ) {
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6013 |
$version = sprintf( '(This message was added in version %s.)', $version ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6014 |
} |
| 16 | 6015 |
|
| 9 | 6016 |
$message .= sprintf( |
6017 |
' Please see <a href="%s">Debugging in WordPress</a> for more information.', |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6018 |
'https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/' |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6019 |
); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6020 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6021 |
$message = sprintf( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6022 |
'Function %1$s was called <strong>incorrectly</strong>. %2$s %3$s', |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6023 |
$function_name, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6024 |
$message, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6025 |
$version |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6026 |
); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6027 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6028 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6029 |
wp_trigger_error( '', $message ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6030 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6031 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6032 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6033 |
/** |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6034 |
* Generates a user-level error/warning/notice/deprecation message. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6035 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6036 |
* Generates the message when `WP_DEBUG` is true. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6037 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6038 |
* @since 6.4.0 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6039 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6040 |
* @param string $function_name The function that triggered the error. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6041 |
* @param string $message The message explaining the error. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6042 |
* The message can contain allowed HTML 'a' (with href), 'code', |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6043 |
* 'br', 'em', and 'strong' tags and http or https protocols. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6044 |
* If it contains other HTML tags or protocols, the message should be escaped |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6045 |
* before passing to this function to avoid being stripped {@see wp_kses()}.
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6046 |
* @param int $error_level Optional. The designated error type for this error. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6047 |
* Only works with E_USER family of constants. Default E_USER_NOTICE. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6048 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6049 |
function wp_trigger_error( $function_name, $message, $error_level = E_USER_NOTICE ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6050 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6051 |
// Bail out if WP_DEBUG is not turned on. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6052 |
if ( ! WP_DEBUG ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6053 |
return; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6054 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6055 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6056 |
/** |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6057 |
* Fires when the given function triggers a user-level error/warning/notice/deprecation message. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6058 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6059 |
* Can be used for debug backtracking. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6060 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6061 |
* @since 6.4.0 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6062 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6063 |
* @param string $function_name The function that was called. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6064 |
* @param string $message A message explaining what has been done incorrectly. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6065 |
* @param int $error_level The designated error type for this error. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6066 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6067 |
do_action( 'wp_trigger_error_run', $function_name, $message, $error_level ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6068 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6069 |
if ( ! empty( $function_name ) ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6070 |
$message = sprintf( '%s(): %s', $function_name, $message ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6071 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6072 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6073 |
$message = wp_kses( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6074 |
$message, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6075 |
array( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6076 |
'a' => array( 'href' => true ), |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6077 |
'br' => array(), |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6078 |
'code' => array(), |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6079 |
'em' => array(), |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6080 |
'strong' => array(), |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6081 |
), |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6082 |
array( 'http', 'https' ) |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6083 |
); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6084 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6085 |
trigger_error( $message, $error_level ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6086 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6087 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6088 |
/** |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6089 |
* Determines whether the server is running an earlier than 1.5.0 version of lighttpd. |
| 0 | 6090 |
* |
6091 |
* @since 2.5.0 |
|
6092 |
* |
|
| 5 | 6093 |
* @return bool Whether the server is running lighttpd < 1.5.0. |
| 0 | 6094 |
*/ |
6095 |
function is_lighttpd_before_150() {
|
|
| 9 | 6096 |
$server_parts = explode( '/', isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : '' ); |
6097 |
$server_parts[1] = isset( $server_parts[1] ) ? $server_parts[1] : ''; |
|
| 16 | 6098 |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6099 |
return ( 'lighttpd' === $server_parts[0] && -1 === version_compare( $server_parts[1], '1.5.0' ) ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6100 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6101 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6102 |
/** |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6103 |
* Determines whether the specified module exist in the Apache config. |
| 0 | 6104 |
* |
6105 |
* @since 2.5.0 |
|
6106 |
* |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6107 |
* @global bool $is_apache |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6108 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6109 |
* @param string $mod The module, e.g. mod_rewrite. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6110 |
* @param bool $default_value Optional. The default return value if the module is not found. Default false. |
| 5 | 6111 |
* @return bool Whether the specified module is loaded. |
| 0 | 6112 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6113 |
function apache_mod_loaded( $mod, $default_value = false ) {
|
| 0 | 6114 |
global $is_apache; |
6115 |
||
| 9 | 6116 |
if ( ! $is_apache ) {
|
| 0 | 6117 |
return false; |
| 9 | 6118 |
} |
| 0 | 6119 |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6120 |
$loaded_mods = array(); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6121 |
|
| 5 | 6122 |
if ( function_exists( 'apache_get_modules' ) ) {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6123 |
$loaded_mods = apache_get_modules(); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6124 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6125 |
if ( in_array( $mod, $loaded_mods, true ) ) {
|
| 0 | 6126 |
return true; |
| 9 | 6127 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6128 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6129 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6130 |
if ( empty( $loaded_mods ) |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6131 |
&& function_exists( 'phpinfo' ) |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6132 |
&& ! str_contains( ini_get( 'disable_functions' ), 'phpinfo' ) |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6133 |
) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6134 |
ob_start(); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6135 |
phpinfo( INFO_MODULES ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6136 |
$phpinfo = ob_get_clean(); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6137 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6138 |
if ( str_contains( $phpinfo, $mod ) ) {
|
| 9 | 6139 |
return true; |
6140 |
} |
|
| 0 | 6141 |
} |
| 16 | 6142 |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6143 |
return $default_value; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6144 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6145 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6146 |
/** |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6147 |
* Checks if IIS 7+ supports pretty permalinks. |
| 0 | 6148 |
* |
6149 |
* @since 2.8.0 |
|
6150 |
* |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6151 |
* @global bool $is_iis7 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6152 |
* |
| 5 | 6153 |
* @return bool Whether IIS7 supports permalinks. |
| 0 | 6154 |
*/ |
6155 |
function iis7_supports_permalinks() {
|
|
6156 |
global $is_iis7; |
|
6157 |
||
6158 |
$supports_permalinks = false; |
|
6159 |
if ( $is_iis7 ) {
|
|
6160 |
/* First we check if the DOMDocument class exists. If it does not exist, then we cannot |
|
6161 |
* easily update the xml configuration file, hence we just bail out and tell user that |
|
6162 |
* pretty permalinks cannot be used. |
|
6163 |
* |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6164 |
* Next we check if the URL Rewrite Module 1.1 is loaded and enabled for the website. When |
| 0 | 6165 |
* URL Rewrite 1.1 is loaded it always sets a server variable called 'IIS_UrlRewriteModule'. |
6166 |
* Lastly we make sure that PHP is running via FastCGI. This is important because if it runs |
|
6167 |
* via ISAPI then pretty permalinks will not work. |
|
6168 |
*/ |
|
| 16 | 6169 |
$supports_permalinks = class_exists( 'DOMDocument', false ) && isset( $_SERVER['IIS_UrlRewriteModule'] ) && ( 'cgi-fcgi' === PHP_SAPI ); |
| 0 | 6170 |
} |
6171 |
||
| 5 | 6172 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6173 |
* Filters whether IIS 7+ supports pretty permalinks. |
| 5 | 6174 |
* |
6175 |
* @since 2.8.0 |
|
6176 |
* |
|
6177 |
* @param bool $supports_permalinks Whether IIS7 supports permalinks. Default false. |
|
6178 |
*/ |
|
6179 |
return apply_filters( 'iis7_supports_permalinks', $supports_permalinks ); |
|
| 0 | 6180 |
} |
6181 |
||
6182 |
/** |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6183 |
* Validates a file name and path against an allowed set of rules. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6184 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6185 |
* A return value of `1` means the file path contains directory traversal. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6186 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6187 |
* A return value of `2` means the file path contains a Windows drive path. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6188 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6189 |
* A return value of `3` means the file is not in the allowed files list. |
| 0 | 6190 |
* |
6191 |
* @since 1.2.0 |
|
6192 |
* |
|
| 16 | 6193 |
* @param string $file File path. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6194 |
* @param string[] $allowed_files Optional. Array of allowed files. Default empty array. |
| 0 | 6195 |
* @return int 0 means nothing is wrong, greater than 0 means something was wrong. |
6196 |
*/ |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6197 |
function validate_file( $file, $allowed_files = array() ) {
|
| 19 | 6198 |
if ( ! is_scalar( $file ) || '' === $file ) {
|
6199 |
return 0; |
|
6200 |
} |
|
6201 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6202 |
// Normalize path for Windows servers. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6203 |
$file = wp_normalize_path( $file ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6204 |
// Normalize path for $allowed_files as well so it's an apples to apples comparison. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6205 |
$allowed_files = array_map( 'wp_normalize_path', $allowed_files ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6206 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6207 |
// `../` on its own is not allowed: |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6208 |
if ( '../' === $file ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6209 |
return 1; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6210 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6211 |
|
| 19 | 6212 |
// More than one occurrence of `../` is not allowed: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6213 |
if ( preg_match_all( '#\.\./#', $file, $matches, PREG_SET_ORDER ) && ( count( $matches ) > 1 ) ) {
|
| 0 | 6214 |
return 1; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6215 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6216 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6217 |
// `../` which does not occur at the end of the path is not allowed: |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6218 |
if ( str_contains( $file, '../' ) && '../' !== mb_substr( $file, -3, 3 ) ) {
|
| 0 | 6219 |
return 1; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6220 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6221 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6222 |
// Files not in the allowed file list are not allowed: |
| 16 | 6223 |
if ( ! empty( $allowed_files ) && ! in_array( $file, $allowed_files, true ) ) {
|
| 0 | 6224 |
return 3; |
| 9 | 6225 |
} |
| 0 | 6226 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6227 |
// Absolute Windows drive paths are not allowed: |
| 16 | 6228 |
if ( ':' === substr( $file, 1, 1 ) ) {
|
| 0 | 6229 |
return 2; |
| 9 | 6230 |
} |
| 0 | 6231 |
|
6232 |
return 0; |
|
6233 |
} |
|
6234 |
||
6235 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6236 |
* Determines whether to force SSL used for the Administration Screens. |
| 0 | 6237 |
* |
6238 |
* @since 2.6.0 |
|
6239 |
* |
|
| 5 | 6240 |
* @param string|bool $force Optional. Whether to force SSL in admin screens. Default null. |
| 0 | 6241 |
* @return bool True if forced, false if not forced. |
6242 |
*/ |
|
6243 |
function force_ssl_admin( $force = null ) {
|
|
6244 |
static $forced = false; |
|
6245 |
||
| 9 | 6246 |
if ( ! is_null( $force ) ) {
|
| 0 | 6247 |
$old_forced = $forced; |
| 9 | 6248 |
$forced = $force; |
| 0 | 6249 |
return $old_forced; |
6250 |
} |
|
6251 |
||
6252 |
return $forced; |
|
6253 |
} |
|
6254 |
||
6255 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6256 |
* Guesses the URL for the site. |
| 0 | 6257 |
* |
6258 |
* Will remove wp-admin links to retrieve only return URLs not in the wp-admin |
|
6259 |
* directory. |
|
6260 |
* |
|
6261 |
* @since 2.6.0 |
|
6262 |
* |
|
| 5 | 6263 |
* @return string The guessed URL. |
| 0 | 6264 |
*/ |
6265 |
function wp_guess_url() {
|
|
| 16 | 6266 |
if ( defined( 'WP_SITEURL' ) && '' !== WP_SITEURL ) {
|
| 0 | 6267 |
$url = WP_SITEURL; |
6268 |
} else {
|
|
| 9 | 6269 |
$abspath_fix = str_replace( '\\', '/', ABSPATH ); |
| 0 | 6270 |
$script_filename_dir = dirname( $_SERVER['SCRIPT_FILENAME'] ); |
6271 |
||
| 16 | 6272 |
// The request is for the admin. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6273 |
if ( str_contains( $_SERVER['REQUEST_URI'], 'wp-admin' ) || str_contains( $_SERVER['REQUEST_URI'], 'wp-login.php' ) ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6274 |
$path = preg_replace( '#/(wp-admin/?.*|wp-login\.php.*)#i', '', $_SERVER['REQUEST_URI'] ); |
| 0 | 6275 |
|
| 16 | 6276 |
// The request is for a file in ABSPATH. |
6277 |
} elseif ( $script_filename_dir . '/' === $abspath_fix ) {
|
|
6278 |
// Strip off any file/query params in the path. |
|
| 0 | 6279 |
$path = preg_replace( '#/[^/]*$#i', '', $_SERVER['PHP_SELF'] ); |
6280 |
||
6281 |
} else {
|
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6282 |
if ( str_contains( $_SERVER['SCRIPT_FILENAME'], $abspath_fix ) ) {
|
| 16 | 6283 |
// Request is hitting a file inside ABSPATH. |
| 0 | 6284 |
$directory = str_replace( ABSPATH, '', $script_filename_dir ); |
| 16 | 6285 |
// Strip off the subdirectory, and any file/query params. |
| 9 | 6286 |
$path = preg_replace( '#/' . preg_quote( $directory, '#' ) . '/[^/]*$#i', '', $_SERVER['REQUEST_URI'] ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6287 |
} elseif ( str_contains( $abspath_fix, $script_filename_dir ) ) {
|
| 16 | 6288 |
// Request is hitting a file above ABSPATH. |
| 5 | 6289 |
$subdirectory = substr( $abspath_fix, strpos( $abspath_fix, $script_filename_dir ) + strlen( $script_filename_dir ) ); |
| 16 | 6290 |
// Strip off any file/query params from the path, appending the subdirectory to the installation. |
| 9 | 6291 |
$path = preg_replace( '#/[^/]*$#i', '', $_SERVER['REQUEST_URI'] ) . $subdirectory; |
| 0 | 6292 |
} else {
|
6293 |
$path = $_SERVER['REQUEST_URI']; |
|
6294 |
} |
|
6295 |
} |
|
6296 |
||
| 16 | 6297 |
$schema = is_ssl() ? 'https://' : 'http://'; // set_url_scheme() is not defined yet. |
| 9 | 6298 |
$url = $schema . $_SERVER['HTTP_HOST'] . $path; |
6299 |
} |
|
6300 |
||
6301 |
return rtrim( $url, '/' ); |
|
| 0 | 6302 |
} |
6303 |
||
6304 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6305 |
* Temporarily suspends cache additions. |
| 0 | 6306 |
* |
6307 |
* Stops more data being added to the cache, but still allows cache retrieval. |
|
6308 |
* This is useful for actions, such as imports, when a lot of data would otherwise |
|
6309 |
* be almost uselessly added to the cache. |
|
6310 |
* |
|
6311 |
* Suspension lasts for a single page load at most. Remember to call this |
|
6312 |
* function again if you wish to re-enable cache adds earlier. |
|
6313 |
* |
|
6314 |
* @since 3.3.0 |
|
6315 |
* |
|
6316 |
* @param bool $suspend Optional. Suspends additions if true, re-enables them if false. |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6317 |
* Defaults to not changing the current setting. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6318 |
* @return bool The current suspend setting. |
| 0 | 6319 |
*/ |
6320 |
function wp_suspend_cache_addition( $suspend = null ) {
|
|
6321 |
static $_suspend = false; |
|
6322 |
||
| 9 | 6323 |
if ( is_bool( $suspend ) ) {
|
| 0 | 6324 |
$_suspend = $suspend; |
| 9 | 6325 |
} |
| 0 | 6326 |
|
6327 |
return $_suspend; |
|
6328 |
} |
|
6329 |
||
6330 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6331 |
* Suspends cache invalidation. |
| 0 | 6332 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6333 |
* Turns cache invalidation on and off. Useful during imports where you don't want to do |
| 5 | 6334 |
* invalidations every time a post is inserted. Callers must be sure that what they are |
6335 |
* doing won't lead to an inconsistent cache when invalidation is suspended. |
|
| 0 | 6336 |
* |
6337 |
* @since 2.7.0 |
|
6338 |
* |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6339 |
* @global bool $_wp_suspend_cache_invalidation |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6340 |
* |
| 5 | 6341 |
* @param bool $suspend Optional. Whether to suspend or enable cache invalidation. Default true. |
6342 |
* @return bool The current suspend setting. |
|
| 0 | 6343 |
*/ |
| 5 | 6344 |
function wp_suspend_cache_invalidation( $suspend = true ) {
|
| 0 | 6345 |
global $_wp_suspend_cache_invalidation; |
6346 |
||
| 9 | 6347 |
$current_suspend = $_wp_suspend_cache_invalidation; |
| 0 | 6348 |
$_wp_suspend_cache_invalidation = $suspend; |
6349 |
return $current_suspend; |
|
6350 |
} |
|
6351 |
||
6352 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6353 |
* Determines whether a site is the main site of the current network. |
| 0 | 6354 |
* |
6355 |
* @since 3.0.0 |
|
| 9 | 6356 |
* @since 4.9.0 The `$network_id` parameter was added. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6357 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6358 |
* @param int $site_id Optional. Site ID to test. Defaults to current site. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6359 |
* @param int $network_id Optional. Network ID of the network to check for. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6360 |
* Defaults to current network. |
| 5 | 6361 |
* @return bool True if $site_id is the main site of the network, or if not |
6362 |
* running Multisite. |
|
| 0 | 6363 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6364 |
function is_main_site( $site_id = null, $network_id = null ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6365 |
if ( ! is_multisite() ) {
|
| 0 | 6366 |
return true; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6367 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6368 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6369 |
if ( ! $site_id ) {
|
| 0 | 6370 |
$site_id = get_current_blog_id(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6371 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6372 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6373 |
$site_id = (int) $site_id; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6374 |
|
| 16 | 6375 |
return get_main_site_id( $network_id ) === $site_id; |
| 0 | 6376 |
} |
6377 |
||
6378 |
/** |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6379 |
* Gets the main site ID. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6380 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6381 |
* @since 4.9.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6382 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6383 |
* @param int $network_id Optional. The ID of the network for which to get the main site. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6384 |
* Defaults to the current network. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6385 |
* @return int The ID of the main site. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6386 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6387 |
function get_main_site_id( $network_id = null ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6388 |
if ( ! is_multisite() ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6389 |
return get_current_blog_id(); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6390 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6391 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6392 |
$network = get_network( $network_id ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6393 |
if ( ! $network ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6394 |
return 0; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6395 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6396 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6397 |
return $network->site_id; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6398 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6399 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6400 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6401 |
* Determines whether a network is the main network of the Multisite installation. |
| 0 | 6402 |
* |
6403 |
* @since 3.7.0 |
|
6404 |
* |
|
6405 |
* @param int $network_id Optional. Network ID to test. Defaults to current network. |
|
| 5 | 6406 |
* @return bool True if $network_id is the main network, or if not running Multisite. |
| 0 | 6407 |
*/ |
6408 |
function is_main_network( $network_id = null ) {
|
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6409 |
if ( ! is_multisite() ) {
|
| 0 | 6410 |
return true; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6411 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6412 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6413 |
if ( null === $network_id ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6414 |
$network_id = get_current_network_id(); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6415 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6416 |
|
| 0 | 6417 |
$network_id = (int) $network_id; |
6418 |
||
| 16 | 6419 |
return ( get_main_network_id() === $network_id ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6420 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6421 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6422 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6423 |
* Gets the main network ID. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6424 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6425 |
* @since 4.3.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6426 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6427 |
* @return int The ID of the main network. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6428 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6429 |
function get_main_network_id() {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6430 |
if ( ! is_multisite() ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6431 |
return 1; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6432 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6433 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6434 |
$current_network = get_network(); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6435 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6436 |
if ( defined( 'PRIMARY_NETWORK_ID' ) ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6437 |
$main_network_id = PRIMARY_NETWORK_ID; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6438 |
} elseif ( isset( $current_network->id ) && 1 === (int) $current_network->id ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6439 |
// If the current network has an ID of 1, assume it is the main network. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6440 |
$main_network_id = 1; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6441 |
} else {
|
| 9 | 6442 |
$_networks = get_networks( |
6443 |
array( |
|
6444 |
'fields' => 'ids', |
|
6445 |
'number' => 1, |
|
6446 |
) |
|
6447 |
); |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6448 |
$main_network_id = array_shift( $_networks ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6449 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6450 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6451 |
/** |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6452 |
* Filters the main network ID. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6453 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6454 |
* @since 4.3.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6455 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6456 |
* @param int $main_network_id The ID of the main network. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6457 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6458 |
return (int) apply_filters( 'get_main_network_id', $main_network_id ); |
| 0 | 6459 |
} |
6460 |
||
6461 |
/** |
|
| 9 | 6462 |
* Determines whether site meta is enabled. |
6463 |
* |
|
6464 |
* This function checks whether the 'blogmeta' database table exists. The result is saved as |
|
6465 |
* a setting for the main network, making it essentially a global setting. Subsequent requests |
|
6466 |
* will refer to this setting instead of running the query. |
|
6467 |
* |
|
6468 |
* @since 5.1.0 |
|
6469 |
* |
|
6470 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
6471 |
* |
|
6472 |
* @return bool True if site meta is supported, false otherwise. |
|
6473 |
*/ |
|
6474 |
function is_site_meta_supported() {
|
|
6475 |
global $wpdb; |
|
6476 |
||
6477 |
if ( ! is_multisite() ) {
|
|
6478 |
return false; |
|
6479 |
} |
|
6480 |
||
6481 |
$network_id = get_main_network_id(); |
|
6482 |
||
6483 |
$supported = get_network_option( $network_id, 'site_meta_supported', false ); |
|
6484 |
if ( false === $supported ) {
|
|
6485 |
$supported = $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->blogmeta}'" ) ? 1 : 0;
|
|
6486 |
||
6487 |
update_network_option( $network_id, 'site_meta_supported', $supported ); |
|
6488 |
} |
|
6489 |
||
6490 |
return (bool) $supported; |
|
6491 |
} |
|
6492 |
||
6493 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6494 |
* Modifies gmt_offset for smart timezone handling. |
| 0 | 6495 |
* |
6496 |
* Overrides the gmt_offset option if we have a timezone_string available. |
|
6497 |
* |
|
6498 |
* @since 2.8.0 |
|
6499 |
* |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6500 |
* @return float|false Timezone GMT offset, false otherwise. |
| 0 | 6501 |
*/ |
6502 |
function wp_timezone_override_offset() {
|
|
| 16 | 6503 |
$timezone_string = get_option( 'timezone_string' ); |
6504 |
if ( ! $timezone_string ) {
|
|
| 0 | 6505 |
return false; |
6506 |
} |
|
6507 |
||
6508 |
$timezone_object = timezone_open( $timezone_string ); |
|
6509 |
$datetime_object = date_create(); |
|
6510 |
if ( false === $timezone_object || false === $datetime_object ) {
|
|
6511 |
return false; |
|
6512 |
} |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6513 |
|
| 0 | 6514 |
return round( timezone_offset_get( $timezone_object, $datetime_object ) / HOUR_IN_SECONDS, 2 ); |
6515 |
} |
|
6516 |
||
6517 |
/** |
|
6518 |
* Sort-helper for timezones. |
|
6519 |
* |
|
6520 |
* @since 2.9.0 |
|
| 5 | 6521 |
* @access private |
| 0 | 6522 |
* |
6523 |
* @param array $a |
|
6524 |
* @param array $b |
|
6525 |
* @return int |
|
6526 |
*/ |
|
6527 |
function _wp_timezone_choice_usort_callback( $a, $b ) {
|
|
| 16 | 6528 |
// Don't use translated versions of Etc. |
| 0 | 6529 |
if ( 'Etc' === $a['continent'] && 'Etc' === $b['continent'] ) {
|
| 16 | 6530 |
// Make the order of these more like the old dropdown. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6531 |
if ( str_starts_with( $a['city'], 'GMT+' ) && str_starts_with( $b['city'], 'GMT+' ) ) {
|
| 0 | 6532 |
return -1 * ( strnatcasecmp( $a['city'], $b['city'] ) ); |
6533 |
} |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6534 |
|
| 0 | 6535 |
if ( 'UTC' === $a['city'] ) {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6536 |
if ( str_starts_with( $b['city'], 'GMT+' ) ) {
|
| 0 | 6537 |
return 1; |
6538 |
} |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6539 |
|
| 0 | 6540 |
return -1; |
6541 |
} |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6542 |
|
| 0 | 6543 |
if ( 'UTC' === $b['city'] ) {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6544 |
if ( str_starts_with( $a['city'], 'GMT+' ) ) {
|
| 0 | 6545 |
return -1; |
6546 |
} |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6547 |
|
| 0 | 6548 |
return 1; |
6549 |
} |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6550 |
|
| 0 | 6551 |
return strnatcasecmp( $a['city'], $b['city'] ); |
6552 |
} |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6553 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6554 |
if ( $a['t_continent'] === $b['t_continent'] ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6555 |
if ( $a['t_city'] === $b['t_city'] ) {
|
| 0 | 6556 |
return strnatcasecmp( $a['t_subcity'], $b['t_subcity'] ); |
6557 |
} |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6558 |
|
| 0 | 6559 |
return strnatcasecmp( $a['t_city'], $b['t_city'] ); |
6560 |
} else {
|
|
| 16 | 6561 |
// Force Etc to the bottom of the list. |
| 0 | 6562 |
if ( 'Etc' === $a['continent'] ) {
|
6563 |
return 1; |
|
6564 |
} |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6565 |
|
| 0 | 6566 |
if ( 'Etc' === $b['continent'] ) {
|
6567 |
return -1; |
|
6568 |
} |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6569 |
|
| 0 | 6570 |
return strnatcasecmp( $a['t_continent'], $b['t_continent'] ); |
6571 |
} |
|
6572 |
} |
|
6573 |
||
6574 |
/** |
|
| 5 | 6575 |
* Gives a nicely-formatted list of timezone strings. |
| 0 | 6576 |
* |
6577 |
* @since 2.9.0 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6578 |
* @since 4.7.0 Added the `$locale` parameter. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6579 |
* |
| 5 | 6580 |
* @param string $selected_zone Selected timezone. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6581 |
* @param string $locale Optional. Locale to load the timezones in. Default current site locale. |
| 0 | 6582 |
* @return string |
6583 |
*/ |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6584 |
function wp_timezone_choice( $selected_zone, $locale = null ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6585 |
static $mo_loaded = false, $locale_loaded = null; |
| 0 | 6586 |
|
| 9 | 6587 |
$continents = array( 'Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific' ); |
| 0 | 6588 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6589 |
// Load translations for continents and cities. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6590 |
if ( ! $mo_loaded || $locale !== $locale_loaded ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6591 |
$locale_loaded = $locale ? $locale : get_locale(); |
| 9 | 6592 |
$mofile = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo'; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6593 |
unload_textdomain( 'continents-cities', true ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6594 |
load_textdomain( 'continents-cities', $mofile, $locale_loaded ); |
| 0 | 6595 |
$mo_loaded = true; |
6596 |
} |
|
6597 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6598 |
$tz_identifiers = timezone_identifiers_list(); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6599 |
$zonen = array(); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6600 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6601 |
foreach ( $tz_identifiers as $zone ) {
|
| 0 | 6602 |
$zone = explode( '/', $zone ); |
| 16 | 6603 |
if ( ! in_array( $zone[0], $continents, true ) ) {
|
| 0 | 6604 |
continue; |
6605 |
} |
|
6606 |
||
| 16 | 6607 |
// This determines what gets set and translated - we don't translate Etc/* strings here, they are done later. |
| 9 | 6608 |
$exists = array( |
| 0 | 6609 |
0 => ( isset( $zone[0] ) && $zone[0] ), |
6610 |
1 => ( isset( $zone[1] ) && $zone[1] ), |
|
6611 |
2 => ( isset( $zone[2] ) && $zone[2] ), |
|
6612 |
); |
|
6613 |
$exists[3] = ( $exists[0] && 'Etc' !== $zone[0] ); |
|
6614 |
$exists[4] = ( $exists[1] && $exists[3] ); |
|
6615 |
$exists[5] = ( $exists[2] && $exists[3] ); |
|
6616 |
||
| 9 | 6617 |
// phpcs:disable WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText |
| 0 | 6618 |
$zonen[] = array( |
6619 |
'continent' => ( $exists[0] ? $zone[0] : '' ), |
|
6620 |
'city' => ( $exists[1] ? $zone[1] : '' ), |
|
6621 |
'subcity' => ( $exists[2] ? $zone[2] : '' ), |
|
6622 |
't_continent' => ( $exists[3] ? translate( str_replace( '_', ' ', $zone[0] ), 'continents-cities' ) : '' ), |
|
6623 |
't_city' => ( $exists[4] ? translate( str_replace( '_', ' ', $zone[1] ), 'continents-cities' ) : '' ), |
|
| 9 | 6624 |
't_subcity' => ( $exists[5] ? translate( str_replace( '_', ' ', $zone[2] ), 'continents-cities' ) : '' ), |
| 0 | 6625 |
); |
| 9 | 6626 |
// phpcs:enable |
| 0 | 6627 |
} |
6628 |
usort( $zonen, '_wp_timezone_choice_usort_callback' ); |
|
6629 |
||
6630 |
$structure = array(); |
|
6631 |
||
6632 |
if ( empty( $selected_zone ) ) {
|
|
6633 |
$structure[] = '<option selected="selected" value="">' . __( 'Select a city' ) . '</option>'; |
|
6634 |
} |
|
6635 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6636 |
// If this is a deprecated, but valid, timezone string, display it at the top of the list as-is. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6637 |
if ( in_array( $selected_zone, $tz_identifiers, true ) === false |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6638 |
&& in_array( $selected_zone, timezone_identifiers_list( DateTimeZone::ALL_WITH_BC ), true ) |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6639 |
) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6640 |
$structure[] = '<option selected="selected" value="' . esc_attr( $selected_zone ) . '">' . esc_html( $selected_zone ) . '</option>'; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6641 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6642 |
|
| 0 | 6643 |
foreach ( $zonen as $key => $zone ) {
|
| 16 | 6644 |
// Build value in an array to join later. |
| 0 | 6645 |
$value = array( $zone['continent'] ); |
6646 |
||
6647 |
if ( empty( $zone['city'] ) ) {
|
|
| 16 | 6648 |
// It's at the continent level (generally won't happen). |
| 0 | 6649 |
$display = $zone['t_continent']; |
6650 |
} else {
|
|
| 16 | 6651 |
// It's inside a continent group. |
6652 |
||
6653 |
// Continent optgroup. |
|
| 9 | 6654 |
if ( ! isset( $zonen[ $key - 1 ] ) || $zonen[ $key - 1 ]['continent'] !== $zone['continent'] ) {
|
6655 |
$label = $zone['t_continent']; |
|
6656 |
$structure[] = '<optgroup label="' . esc_attr( $label ) . '">'; |
|
| 0 | 6657 |
} |
6658 |
||
| 16 | 6659 |
// Add the city to the value. |
| 0 | 6660 |
$value[] = $zone['city']; |
6661 |
||
6662 |
$display = $zone['t_city']; |
|
| 9 | 6663 |
if ( ! empty( $zone['subcity'] ) ) {
|
| 16 | 6664 |
// Add the subcity to the value. |
| 9 | 6665 |
$value[] = $zone['subcity']; |
| 0 | 6666 |
$display .= ' - ' . $zone['t_subcity']; |
6667 |
} |
|
6668 |
} |
|
6669 |
||
| 16 | 6670 |
// Build the value. |
| 18 | 6671 |
$value = implode( '/', $value ); |
| 0 | 6672 |
$selected = ''; |
6673 |
if ( $value === $selected_zone ) {
|
|
6674 |
$selected = 'selected="selected" '; |
|
6675 |
} |
|
| 9 | 6676 |
$structure[] = '<option ' . $selected . 'value="' . esc_attr( $value ) . '">' . esc_html( $display ) . '</option>'; |
| 0 | 6677 |
|
| 16 | 6678 |
// Close continent optgroup. |
| 9 | 6679 |
if ( ! empty( $zone['city'] ) && ( ! isset( $zonen[ $key + 1 ] ) || ( isset( $zonen[ $key + 1 ] ) && $zonen[ $key + 1 ]['continent'] !== $zone['continent'] ) ) ) {
|
| 0 | 6680 |
$structure[] = '</optgroup>'; |
6681 |
} |
|
6682 |
} |
|
6683 |
||
| 16 | 6684 |
// Do UTC. |
| 9 | 6685 |
$structure[] = '<optgroup label="' . esc_attr__( 'UTC' ) . '">'; |
6686 |
$selected = ''; |
|
6687 |
if ( 'UTC' === $selected_zone ) {
|
|
| 0 | 6688 |
$selected = 'selected="selected" '; |
| 9 | 6689 |
} |
6690 |
$structure[] = '<option ' . $selected . 'value="' . esc_attr( 'UTC' ) . '">' . __( 'UTC' ) . '</option>'; |
|
| 0 | 6691 |
$structure[] = '</optgroup>'; |
6692 |
||
| 16 | 6693 |
// Do manual UTC offsets. |
| 9 | 6694 |
$structure[] = '<optgroup label="' . esc_attr__( 'Manual Offsets' ) . '">'; |
6695 |
$offset_range = array( |
|
6696 |
-12, |
|
6697 |
-11.5, |
|
6698 |
-11, |
|
6699 |
-10.5, |
|
6700 |
-10, |
|
6701 |
-9.5, |
|
6702 |
-9, |
|
6703 |
-8.5, |
|
6704 |
-8, |
|
6705 |
-7.5, |
|
6706 |
-7, |
|
6707 |
-6.5, |
|
6708 |
-6, |
|
6709 |
-5.5, |
|
6710 |
-5, |
|
6711 |
-4.5, |
|
6712 |
-4, |
|
6713 |
-3.5, |
|
6714 |
-3, |
|
6715 |
-2.5, |
|
6716 |
-2, |
|
6717 |
-1.5, |
|
6718 |
-1, |
|
6719 |
-0.5, |
|
6720 |
0, |
|
6721 |
0.5, |
|
6722 |
1, |
|
6723 |
1.5, |
|
6724 |
2, |
|
6725 |
2.5, |
|
6726 |
3, |
|
6727 |
3.5, |
|
6728 |
4, |
|
6729 |
4.5, |
|
6730 |
5, |
|
6731 |
5.5, |
|
6732 |
5.75, |
|
6733 |
6, |
|
6734 |
6.5, |
|
6735 |
7, |
|
6736 |
7.5, |
|
6737 |
8, |
|
6738 |
8.5, |
|
6739 |
8.75, |
|
6740 |
9, |
|
6741 |
9.5, |
|
6742 |
10, |
|
6743 |
10.5, |
|
6744 |
11, |
|
6745 |
11.5, |
|
6746 |
12, |
|
6747 |
12.75, |
|
6748 |
13, |
|
6749 |
13.75, |
|
6750 |
14, |
|
6751 |
); |
|
| 0 | 6752 |
foreach ( $offset_range as $offset ) {
|
| 9 | 6753 |
if ( 0 <= $offset ) {
|
| 0 | 6754 |
$offset_name = '+' . $offset; |
| 9 | 6755 |
} else {
|
| 0 | 6756 |
$offset_name = (string) $offset; |
| 9 | 6757 |
} |
| 0 | 6758 |
|
6759 |
$offset_value = $offset_name; |
|
| 9 | 6760 |
$offset_name = str_replace( array( '.25', '.5', '.75' ), array( ':15', ':30', ':45' ), $offset_name ); |
6761 |
$offset_name = 'UTC' . $offset_name; |
|
| 0 | 6762 |
$offset_value = 'UTC' . $offset_value; |
| 9 | 6763 |
$selected = ''; |
6764 |
if ( $offset_value === $selected_zone ) {
|
|
| 0 | 6765 |
$selected = 'selected="selected" '; |
| 9 | 6766 |
} |
6767 |
$structure[] = '<option ' . $selected . 'value="' . esc_attr( $offset_value ) . '">' . esc_html( $offset_name ) . '</option>'; |
|
| 0 | 6768 |
|
6769 |
} |
|
6770 |
$structure[] = '</optgroup>'; |
|
6771 |
||
| 18 | 6772 |
return implode( "\n", $structure ); |
| 0 | 6773 |
} |
6774 |
||
6775 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6776 |
* Strips close comment and close php tags from file headers used by WP. |
| 0 | 6777 |
* |
6778 |
* @since 2.8.0 |
|
| 5 | 6779 |
* @access private |
6780 |
* |
|
6781 |
* @see https://core.trac.wordpress.org/ticket/8497 |
|
6782 |
* |
|
6783 |
* @param string $str Header comment to clean up. |
|
| 0 | 6784 |
* @return string |
6785 |
*/ |
|
| 5 | 6786 |
function _cleanup_header_comment( $str ) {
|
| 9 | 6787 |
return trim( preg_replace( '/\s*(?:\*\/|\?>).*/', '', $str ) ); |
| 0 | 6788 |
} |
6789 |
||
6790 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6791 |
* Permanently deletes comments or posts of any type that have held a status |
| 5 | 6792 |
* of 'trash' for the number of days defined in EMPTY_TRASH_DAYS. |
6793 |
* |
|
6794 |
* The default value of `EMPTY_TRASH_DAYS` is 30 (days). |
|
| 0 | 6795 |
* |
6796 |
* @since 2.9.0 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6797 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6798 |
* @global wpdb $wpdb WordPress database abstraction object. |
| 0 | 6799 |
*/ |
6800 |
function wp_scheduled_delete() {
|
|
6801 |
global $wpdb; |
|
6802 |
||
6803 |
$delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS ); |
|
6804 |
||
| 9 | 6805 |
$posts_to_delete = $wpdb->get_results( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_trash_meta_time' AND meta_value < %d", $delete_timestamp ), ARRAY_A ); |
| 0 | 6806 |
|
6807 |
foreach ( (array) $posts_to_delete as $post ) {
|
|
6808 |
$post_id = (int) $post['post_id']; |
|
| 9 | 6809 |
if ( ! $post_id ) {
|
| 0 | 6810 |
continue; |
| 9 | 6811 |
} |
6812 |
||
6813 |
$del_post = get_post( $post_id ); |
|
6814 |
||
| 16 | 6815 |
if ( ! $del_post || 'trash' !== $del_post->post_status ) {
|
| 9 | 6816 |
delete_post_meta( $post_id, '_wp_trash_meta_status' ); |
6817 |
delete_post_meta( $post_id, '_wp_trash_meta_time' ); |
|
| 0 | 6818 |
} else {
|
| 9 | 6819 |
wp_delete_post( $post_id ); |
| 0 | 6820 |
} |
6821 |
} |
|
6822 |
||
| 9 | 6823 |
$comments_to_delete = $wpdb->get_results( $wpdb->prepare( "SELECT comment_id FROM $wpdb->commentmeta WHERE meta_key = '_wp_trash_meta_time' AND meta_value < %d", $delete_timestamp ), ARRAY_A ); |
| 0 | 6824 |
|
6825 |
foreach ( (array) $comments_to_delete as $comment ) {
|
|
6826 |
$comment_id = (int) $comment['comment_id']; |
|
| 9 | 6827 |
if ( ! $comment_id ) {
|
| 0 | 6828 |
continue; |
| 9 | 6829 |
} |
6830 |
||
6831 |
$del_comment = get_comment( $comment_id ); |
|
6832 |
||
| 16 | 6833 |
if ( ! $del_comment || 'trash' !== $del_comment->comment_approved ) {
|
| 9 | 6834 |
delete_comment_meta( $comment_id, '_wp_trash_meta_time' ); |
6835 |
delete_comment_meta( $comment_id, '_wp_trash_meta_status' ); |
|
| 0 | 6836 |
} else {
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6837 |
wp_delete_comment( $del_comment ); |
| 0 | 6838 |
} |
6839 |
} |
|
6840 |
} |
|
6841 |
||
6842 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6843 |
* Retrieves metadata from a file. |
| 0 | 6844 |
* |
| 16 | 6845 |
* Searches for metadata in the first 8 KB of a file, such as a plugin or theme. |
| 0 | 6846 |
* Each piece of metadata must be on its own line. Fields can not span multiple |
6847 |
* lines, the value will get cut at the end of the first line. |
|
6848 |
* |
|
| 16 | 6849 |
* If the file data is not within that first 8 KB, then the author should correct |
| 0 | 6850 |
* their plugin file and move the data headers to the top. |
6851 |
* |
|
| 5 | 6852 |
* @link https://codex.wordpress.org/File_Header |
| 0 | 6853 |
* |
6854 |
* @since 2.9.0 |
|
| 5 | 6855 |
* |
| 9 | 6856 |
* @param string $file Absolute path to the file. |
| 16 | 6857 |
* @param array $default_headers List of headers, in the format `array( 'HeaderKey' => 'Header Name' )`. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6858 |
* @param string $context Optional. If specified adds filter hook {@see 'extra_$context_headers'}.
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6859 |
* Default empty string. |
| 16 | 6860 |
* @return string[] Array of file header values keyed by header name. |
| 0 | 6861 |
*/ |
6862 |
function get_file_data( $file, $default_headers, $context = '' ) {
|
|
| 19 | 6863 |
// Pull only the first 8 KB of the file in. |
6864 |
$file_data = file_get_contents( $file, false, null, 0, 8 * KB_IN_BYTES ); |
|
6865 |
||
6866 |
if ( false === $file_data ) {
|
|
| 18 | 6867 |
$file_data = ''; |
6868 |
} |
|
| 0 | 6869 |
|
6870 |
// Make sure we catch CR-only line endings. |
|
6871 |
$file_data = str_replace( "\r", "\n", $file_data ); |
|
6872 |
||
| 5 | 6873 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6874 |
* Filters extra file headers by context. |
| 5 | 6875 |
* |
6876 |
* The dynamic portion of the hook name, `$context`, refers to |
|
6877 |
* the context where extra headers might be loaded. |
|
6878 |
* |
|
6879 |
* @since 2.9.0 |
|
6880 |
* |
|
6881 |
* @param array $extra_context_headers Empty array by default. |
|
6882 |
*/ |
|
| 16 | 6883 |
$extra_headers = $context ? apply_filters( "extra_{$context}_headers", array() ) : array();
|
6884 |
if ( $extra_headers ) {
|
|
6885 |
$extra_headers = array_combine( $extra_headers, $extra_headers ); // Keys equal values. |
|
| 9 | 6886 |
$all_headers = array_merge( $extra_headers, (array) $default_headers ); |
| 0 | 6887 |
} else {
|
6888 |
$all_headers = $default_headers; |
|
6889 |
} |
|
6890 |
||
6891 |
foreach ( $all_headers as $field => $regex ) {
|
|
| 18 | 6892 |
if ( preg_match( '/^(?:[ \t]*<\?php)?[ \t\/*#@]*' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, $match ) && $match[1] ) {
|
| 0 | 6893 |
$all_headers[ $field ] = _cleanup_header_comment( $match[1] ); |
| 9 | 6894 |
} else {
|
| 0 | 6895 |
$all_headers[ $field ] = ''; |
| 9 | 6896 |
} |
| 0 | 6897 |
} |
6898 |
||
6899 |
return $all_headers; |
|
6900 |
} |
|
6901 |
||
6902 |
/** |
|
6903 |
* Returns true. |
|
6904 |
* |
|
6905 |
* Useful for returning true to filters easily. |
|
6906 |
* |
|
6907 |
* @since 3.0.0 |
|
| 5 | 6908 |
* |
| 0 | 6909 |
* @see __return_false() |
| 5 | 6910 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6911 |
* @return true True. |
| 0 | 6912 |
*/ |
| 16 | 6913 |
function __return_true() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore
|
| 0 | 6914 |
return true; |
6915 |
} |
|
6916 |
||
6917 |
/** |
|
6918 |
* Returns false. |
|
6919 |
* |
|
6920 |
* Useful for returning false to filters easily. |
|
6921 |
* |
|
6922 |
* @since 3.0.0 |
|
| 5 | 6923 |
* |
| 0 | 6924 |
* @see __return_true() |
| 5 | 6925 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6926 |
* @return false False. |
| 0 | 6927 |
*/ |
| 16 | 6928 |
function __return_false() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore
|
| 0 | 6929 |
return false; |
6930 |
} |
|
6931 |
||
6932 |
/** |
|
6933 |
* Returns 0. |
|
6934 |
* |
|
6935 |
* Useful for returning 0 to filters easily. |
|
6936 |
* |
|
6937 |
* @since 3.0.0 |
|
| 5 | 6938 |
* |
6939 |
* @return int 0. |
|
| 0 | 6940 |
*/ |
| 16 | 6941 |
function __return_zero() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore
|
| 0 | 6942 |
return 0; |
6943 |
} |
|
6944 |
||
6945 |
/** |
|
6946 |
* Returns an empty array. |
|
6947 |
* |
|
6948 |
* Useful for returning an empty array to filters easily. |
|
6949 |
* |
|
6950 |
* @since 3.0.0 |
|
| 5 | 6951 |
* |
6952 |
* @return array Empty array. |
|
| 0 | 6953 |
*/ |
| 16 | 6954 |
function __return_empty_array() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore
|
| 0 | 6955 |
return array(); |
6956 |
} |
|
6957 |
||
6958 |
/** |
|
6959 |
* Returns null. |
|
6960 |
* |
|
6961 |
* Useful for returning null to filters easily. |
|
6962 |
* |
|
6963 |
* @since 3.4.0 |
|
| 5 | 6964 |
* |
6965 |
* @return null Null value. |
|
| 0 | 6966 |
*/ |
| 16 | 6967 |
function __return_null() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore
|
| 0 | 6968 |
return null; |
6969 |
} |
|
6970 |
||
6971 |
/** |
|
6972 |
* Returns an empty string. |
|
6973 |
* |
|
6974 |
* Useful for returning an empty string to filters easily. |
|
6975 |
* |
|
6976 |
* @since 3.7.0 |
|
| 5 | 6977 |
* |
| 0 | 6978 |
* @see __return_null() |
| 5 | 6979 |
* |
6980 |
* @return string Empty string. |
|
| 0 | 6981 |
*/ |
| 16 | 6982 |
function __return_empty_string() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore
|
| 0 | 6983 |
return ''; |
6984 |
} |
|
6985 |
||
6986 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6987 |
* Sends a HTTP header to disable content type sniffing in browsers which support it. |
| 0 | 6988 |
* |
6989 |
* @since 3.0.0 |
|
| 5 | 6990 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6991 |
* @see https://blogs.msdn.com/ie/archive/2008/07/02/ie8-security-part-v-comprehensive-protection.aspx |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6992 |
* @see https://src.chromium.org/viewvc/chrome?view=rev&revision=6985 |
| 0 | 6993 |
*/ |
6994 |
function send_nosniff_header() {
|
|
| 16 | 6995 |
header( 'X-Content-Type-Options: nosniff' ); |
| 0 | 6996 |
} |
6997 |
||
6998 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6999 |
* Returns a MySQL expression for selecting the week number based on the start_of_week option. |
| 5 | 7000 |
* |
7001 |
* @ignore |
|
| 0 | 7002 |
* @since 3.0.0 |
| 5 | 7003 |
* |
7004 |
* @param string $column Database column. |
|
7005 |
* @return string SQL clause. |
|
| 0 | 7006 |
*/ |
7007 |
function _wp_mysql_week( $column ) {
|
|
| 16 | 7008 |
$start_of_week = (int) get_option( 'start_of_week' ); |
7009 |
switch ( $start_of_week ) {
|
|
| 9 | 7010 |
case 1: |
7011 |
return "WEEK( $column, 1 )"; |
|
7012 |
case 2: |
|
7013 |
case 3: |
|
7014 |
case 4: |
|
7015 |
case 5: |
|
7016 |
case 6: |
|
7017 |
return "WEEK( DATE_SUB( $column, INTERVAL $start_of_week DAY ), 0 )"; |
|
7018 |
case 0: |
|
7019 |
default: |
|
7020 |
return "WEEK( $column, 0 )"; |
|
| 0 | 7021 |
} |
7022 |
} |
|
7023 |
||
7024 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7025 |
* Finds hierarchy loops using a callback function that maps object IDs to parent IDs. |
| 0 | 7026 |
* |
7027 |
* @since 3.1.0 |
|
7028 |
* @access private |
|
7029 |
* |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7030 |
* @param callable $callback Function that accepts ( ID, $callback_args ) and outputs parent_ID. |
| 5 | 7031 |
* @param int $start The ID to start the loop check at. |
7032 |
* @param int $start_parent The parent_ID of $start to use instead of calling $callback( $start ). |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7033 |
* Use null to always use $callback. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7034 |
* @param array $callback_args Optional. Additional arguments to send to $callback. Default empty array. |
| 5 | 7035 |
* @return array IDs of all members of loop. |
| 0 | 7036 |
*/ |
7037 |
function wp_find_hierarchy_loop( $callback, $start, $start_parent, $callback_args = array() ) {
|
|
7038 |
$override = is_null( $start_parent ) ? array() : array( $start => $start_parent ); |
|
7039 |
||
| 16 | 7040 |
$arbitrary_loop_member = wp_find_hierarchy_loop_tortoise_hare( $callback, $start, $override, $callback_args ); |
7041 |
if ( ! $arbitrary_loop_member ) {
|
|
| 0 | 7042 |
return array(); |
| 9 | 7043 |
} |
| 0 | 7044 |
|
7045 |
return wp_find_hierarchy_loop_tortoise_hare( $callback, $arbitrary_loop_member, $override, $callback_args, true ); |
|
7046 |
} |
|
7047 |
||
7048 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7049 |
* Uses the "The Tortoise and the Hare" algorithm to detect loops. |
| 0 | 7050 |
* |
7051 |
* For every step of the algorithm, the hare takes two steps and the tortoise one. |
|
7052 |
* If the hare ever laps the tortoise, there must be a loop. |
|
7053 |
* |
|
7054 |
* @since 3.1.0 |
|
7055 |
* @access private |
|
7056 |
* |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7057 |
* @param callable $callback Function that accepts ( ID, callback_arg, ... ) and outputs parent_ID. |
| 5 | 7058 |
* @param int $start The ID to start the loop check at. |
7059 |
* @param array $override Optional. An array of ( ID => parent_ID, ... ) to use instead of $callback. |
|
7060 |
* Default empty array. |
|
7061 |
* @param array $callback_args Optional. Additional arguments to send to $callback. Default empty array. |
|
7062 |
* @param bool $_return_loop Optional. Return loop members or just detect presence of loop? Only set |
|
7063 |
* to true if you already know the given $start is part of a loop (otherwise |
|
7064 |
* the returned array might include branches). Default false. |
|
7065 |
* @return mixed Scalar ID of some arbitrary member of the loop, or array of IDs of all members of loop if |
|
7066 |
* $_return_loop |
|
| 0 | 7067 |
*/ |
7068 |
function wp_find_hierarchy_loop_tortoise_hare( $callback, $start, $override = array(), $callback_args = array(), $_return_loop = false ) {
|
|
| 16 | 7069 |
$tortoise = $start; |
7070 |
$hare = $start; |
|
7071 |
$evanescent_hare = $start; |
|
7072 |
$return = array(); |
|
7073 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7074 |
// Set evanescent_hare to one past hare. Increment hare two steps. |
| 0 | 7075 |
while ( |
7076 |
$tortoise |
|
7077 |
&& |
|
| 9 | 7078 |
( $evanescent_hare = isset( $override[ $hare ] ) ? $override[ $hare ] : call_user_func_array( $callback, array_merge( array( $hare ), $callback_args ) ) ) |
| 0 | 7079 |
&& |
| 9 | 7080 |
( $hare = isset( $override[ $evanescent_hare ] ) ? $override[ $evanescent_hare ] : call_user_func_array( $callback, array_merge( array( $evanescent_hare ), $callback_args ) ) ) |
| 0 | 7081 |
) {
|
| 9 | 7082 |
if ( $_return_loop ) {
|
| 16 | 7083 |
$return[ $tortoise ] = true; |
7084 |
$return[ $evanescent_hare ] = true; |
|
7085 |
$return[ $hare ] = true; |
|
| 9 | 7086 |
} |
| 0 | 7087 |
|
| 16 | 7088 |
// Tortoise got lapped - must be a loop. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7089 |
if ( $tortoise === $evanescent_hare || $tortoise === $hare ) {
|
| 0 | 7090 |
return $_return_loop ? $return : $tortoise; |
| 9 | 7091 |
} |
| 0 | 7092 |
|
| 16 | 7093 |
// Increment tortoise by one step. |
| 9 | 7094 |
$tortoise = isset( $override[ $tortoise ] ) ? $override[ $tortoise ] : call_user_func_array( $callback, array_merge( array( $tortoise ), $callback_args ) ); |
| 0 | 7095 |
} |
7096 |
||
7097 |
return false; |
|
7098 |
} |
|
7099 |
||
7100 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7101 |
* Sends a HTTP header to limit rendering of pages to same origin iframes. |
| 0 | 7102 |
* |
7103 |
* @since 3.1.3 |
|
| 5 | 7104 |
* |
| 19 | 7105 |
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options |
| 0 | 7106 |
*/ |
7107 |
function send_frame_options_header() {
|
|
| 16 | 7108 |
header( 'X-Frame-Options: SAMEORIGIN' ); |
| 0 | 7109 |
} |
7110 |
||
7111 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7112 |
* Retrieves a list of protocols to allow in HTML attributes. |
| 0 | 7113 |
* |
7114 |
* @since 3.3.0 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7115 |
* @since 4.3.0 Added 'webcal' to the protocols array. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7116 |
* @since 4.7.0 Added 'urn' to the protocols array. |
| 16 | 7117 |
* @since 5.3.0 Added 'sms' to the protocols array. |
| 18 | 7118 |
* @since 5.6.0 Added 'irc6' and 'ircs' to the protocols array. |
| 5 | 7119 |
* |
| 0 | 7120 |
* @see wp_kses() |
7121 |
* @see esc_url() |
|
7122 |
* |
|
| 9 | 7123 |
* @return string[] Array of allowed protocols. Defaults to an array containing 'http', 'https', |
| 18 | 7124 |
* 'ftp', 'ftps', 'mailto', 'news', 'irc', 'irc6', 'ircs', 'gopher', 'nntp', 'feed', |
7125 |
* 'telnet', 'mms', 'rtsp', 'sms', 'svn', 'tel', 'fax', 'xmpp', 'webcal', and 'urn'. |
|
| 16 | 7126 |
* This covers all common link protocols, except for 'javascript' which should not |
7127 |
* be allowed for untrusted users. |
|
| 0 | 7128 |
*/ |
7129 |
function wp_allowed_protocols() {
|
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7130 |
static $protocols = array(); |
| 0 | 7131 |
|
7132 |
if ( empty( $protocols ) ) {
|
|
| 18 | 7133 |
$protocols = array( 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'irc6', 'ircs', 'gopher', 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'sms', 'svn', 'tel', 'fax', 'xmpp', 'webcal', 'urn' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7134 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7135 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7136 |
if ( ! did_action( 'wp_loaded' ) ) {
|
| 5 | 7137 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7138 |
* Filters the list of protocols allowed in HTML attributes. |
| 5 | 7139 |
* |
7140 |
* @since 3.0.0 |
|
7141 |
* |
|
| 16 | 7142 |
* @param string[] $protocols Array of allowed protocols e.g. 'http', 'ftp', 'tel', and more. |
| 5 | 7143 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7144 |
$protocols = array_unique( (array) apply_filters( 'kses_allowed_protocols', $protocols ) ); |
| 0 | 7145 |
} |
7146 |
||
7147 |
return $protocols; |
|
7148 |
} |
|
7149 |
||
7150 |
/** |
|
| 19 | 7151 |
* Returns a comma-separated string or array of functions that have been called to get |
| 5 | 7152 |
* to the current point in code. |
7153 |
* |
|
7154 |
* @since 3.4.0 |
|
7155 |
* |
|
7156 |
* @see https://core.trac.wordpress.org/ticket/19589 |
|
7157 |
* |
|
7158 |
* @param string $ignore_class Optional. A class to ignore all function calls within - useful |
|
7159 |
* when you want to just give info about the callee. Default null. |
|
7160 |
* @param int $skip_frames Optional. A number of stack frames to skip - useful for unwinding |
|
7161 |
* back to the source of the issue. Default 0. |
|
| 19 | 7162 |
* @param bool $pretty Optional. Whether you want a comma separated string instead of |
7163 |
* the raw array returned. Default true. |
|
| 5 | 7164 |
* @return string|array Either a string containing a reversed comma separated trace or an array |
7165 |
* of individual calls. |
|
| 0 | 7166 |
*/ |
7167 |
function wp_debug_backtrace_summary( $ignore_class = null, $skip_frames = 0, $pretty = true ) {
|
|
| 9 | 7168 |
static $truncate_paths; |
7169 |
||
| 16 | 7170 |
$trace = debug_backtrace( false ); |
| 9 | 7171 |
$caller = array(); |
| 0 | 7172 |
$check_class = ! is_null( $ignore_class ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7173 |
++$skip_frames; // Skip this function. |
| 0 | 7174 |
|
| 9 | 7175 |
if ( ! isset( $truncate_paths ) ) {
|
7176 |
$truncate_paths = array( |
|
7177 |
wp_normalize_path( WP_CONTENT_DIR ), |
|
7178 |
wp_normalize_path( ABSPATH ), |
|
7179 |
); |
|
7180 |
} |
|
7181 |
||
| 0 | 7182 |
foreach ( $trace as $call ) {
|
7183 |
if ( $skip_frames > 0 ) {
|
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7184 |
--$skip_frames; |
| 0 | 7185 |
} elseif ( isset( $call['class'] ) ) {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7186 |
if ( $check_class && $ignore_class === $call['class'] ) {
|
| 16 | 7187 |
continue; // Filter out calls. |
| 9 | 7188 |
} |
| 0 | 7189 |
|
7190 |
$caller[] = "{$call['class']}{$call['type']}{$call['function']}";
|
|
7191 |
} else {
|
|
| 16 | 7192 |
if ( in_array( $call['function'], array( 'do_action', 'apply_filters', 'do_action_ref_array', 'apply_filters_ref_array' ), true ) ) {
|
| 0 | 7193 |
$caller[] = "{$call['function']}('{$call['args'][0]}')";
|
| 16 | 7194 |
} elseif ( in_array( $call['function'], array( 'include', 'include_once', 'require', 'require_once' ), true ) ) {
|
| 9 | 7195 |
$filename = isset( $call['args'][0] ) ? $call['args'][0] : ''; |
7196 |
$caller[] = $call['function'] . "('" . str_replace( $truncate_paths, '', wp_normalize_path( $filename ) ) . "')";
|
|
| 0 | 7197 |
} else {
|
7198 |
$caller[] = $call['function']; |
|
7199 |
} |
|
7200 |
} |
|
7201 |
} |
|
| 9 | 7202 |
if ( $pretty ) {
|
| 18 | 7203 |
return implode( ', ', array_reverse( $caller ) ); |
| 9 | 7204 |
} else {
|
| 0 | 7205 |
return $caller; |
| 9 | 7206 |
} |
7207 |
} |
|
7208 |
||
7209 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7210 |
* Retrieves IDs that are not already present in the cache. |
| 0 | 7211 |
* |
7212 |
* @since 3.4.0 |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7213 |
* @since 6.1.0 This function is no longer marked as "private". |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7214 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7215 |
* @param int[] $object_ids Array of IDs. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7216 |
* @param string $cache_group The cache group to check against. |
| 9 | 7217 |
* @return int[] Array of IDs not present in the cache. |
| 0 | 7218 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7219 |
function _get_non_cached_ids( $object_ids, $cache_group ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7220 |
$object_ids = array_filter( $object_ids, '_validate_cache_id' ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7221 |
$object_ids = array_unique( array_map( 'intval', $object_ids ), SORT_NUMERIC ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7222 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7223 |
if ( empty( $object_ids ) ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7224 |
return array(); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7225 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7226 |
|
| 16 | 7227 |
$non_cached_ids = array(); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7228 |
$cache_values = wp_cache_get_multiple( $object_ids, $cache_group ); |
| 16 | 7229 |
|
7230 |
foreach ( $cache_values as $id => $value ) {
|
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7231 |
if ( false === $value ) {
|
| 16 | 7232 |
$non_cached_ids[] = (int) $id; |
| 0 | 7233 |
} |
7234 |
} |
|
7235 |
||
| 16 | 7236 |
return $non_cached_ids; |
| 0 | 7237 |
} |
7238 |
||
7239 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7240 |
* Checks whether the given cache ID is either an integer or an integer-like string. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7241 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7242 |
* Both `16` and `"16"` are considered valid, other numeric types and numeric strings |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7243 |
* (`16.3` and `"16.3"`) are considered invalid. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7244 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7245 |
* @since 6.3.0 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7246 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7247 |
* @param mixed $object_id The cache ID to validate. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7248 |
* @return bool Whether the given $object_id is a valid cache ID. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7249 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7250 |
function _validate_cache_id( $object_id ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7251 |
/* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7252 |
* filter_var() could be used here, but the `filter` PHP extension |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7253 |
* is considered optional and may not be available. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7254 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7255 |
if ( is_int( $object_id ) |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7256 |
|| ( is_string( $object_id ) && (string) (int) $object_id === $object_id ) ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7257 |
return true; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7258 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7259 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7260 |
/* translators: %s: The type of the given object ID. */ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7261 |
$message = sprintf( __( 'Object ID must be an integer, %s given.' ), gettype( $object_id ) ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7262 |
_doing_it_wrong( '_get_non_cached_ids', $message, '6.3.0' ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7263 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7264 |
return false; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7265 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7266 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7267 |
/** |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7268 |
* Tests if the current device has the capability to upload files. |
| 0 | 7269 |
* |
7270 |
* @since 3.4.0 |
|
7271 |
* @access private |
|
7272 |
* |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7273 |
* @return bool Whether the device is able to upload files. |
| 0 | 7274 |
*/ |
7275 |
function _device_can_upload() {
|
|
| 9 | 7276 |
if ( ! wp_is_mobile() ) {
|
| 0 | 7277 |
return true; |
| 9 | 7278 |
} |
| 0 | 7279 |
|
7280 |
$ua = $_SERVER['HTTP_USER_AGENT']; |
|
7281 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7282 |
if ( str_contains( $ua, 'iPhone' ) |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7283 |
|| str_contains( $ua, 'iPad' ) |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7284 |
|| str_contains( $ua, 'iPod' ) ) {
|
| 0 | 7285 |
return preg_match( '#OS ([\d_]+) like Mac OS X#', $ua, $version ) && version_compare( $version[1], '6', '>=' ); |
7286 |
} |
|
7287 |
||
7288 |
return true; |
|
7289 |
} |
|
7290 |
||
7291 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7292 |
* Tests if a given path is a stream URL |
| 0 | 7293 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7294 |
* @since 3.5.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7295 |
* |
| 5 | 7296 |
* @param string $path The resource path or URL. |
7297 |
* @return bool True if the path is a stream URL. |
|
| 0 | 7298 |
*/ |
7299 |
function wp_is_stream( $path ) {
|
|
| 9 | 7300 |
$scheme_separator = strpos( $path, '://' ); |
7301 |
||
7302 |
if ( false === $scheme_separator ) {
|
|
| 16 | 7303 |
// $path isn't a stream. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7304 |
return false; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7305 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7306 |
|
| 9 | 7307 |
$stream = substr( $path, 0, $scheme_separator ); |
7308 |
||
7309 |
return in_array( $stream, stream_get_wrappers(), true ); |
|
| 0 | 7310 |
} |
7311 |
||
7312 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7313 |
* Tests if the supplied date is valid for the Gregorian calendar. |
| 0 | 7314 |
* |
7315 |
* @since 3.5.0 |
|
7316 |
* |
|
| 16 | 7317 |
* @link https://www.php.net/manual/en/function.checkdate.php |
7318 |
* |
|
7319 |
* @param int $month Month number. |
|
7320 |
* @param int $day Day number. |
|
7321 |
* @param int $year Year number. |
|
7322 |
* @param string $source_date The date to filter. |
|
| 5 | 7323 |
* @return bool True if valid date, false if not valid date. |
| 0 | 7324 |
*/ |
7325 |
function wp_checkdate( $month, $day, $year, $source_date ) {
|
|
| 5 | 7326 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7327 |
* Filters whether the given date is valid for the Gregorian calendar. |
| 5 | 7328 |
* |
7329 |
* @since 3.5.0 |
|
7330 |
* |
|
7331 |
* @param bool $checkdate Whether the given date is valid. |
|
7332 |
* @param string $source_date Date to check. |
|
7333 |
*/ |
|
| 0 | 7334 |
return apply_filters( 'wp_checkdate', checkdate( $month, $day, $year ), $source_date ); |
7335 |
} |
|
7336 |
||
7337 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7338 |
* Loads the auth check for monitoring whether the user is still logged in. |
| 0 | 7339 |
* |
7340 |
* Can be disabled with remove_action( 'admin_enqueue_scripts', 'wp_auth_check_load' ); |
|
7341 |
* |
|
7342 |
* This is disabled for certain screens where a login screen could cause an |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7343 |
* inconvenient interruption. A filter called {@see 'wp_auth_check_load'} can be used
|
| 0 | 7344 |
* for fine-grained control. |
7345 |
* |
|
7346 |
* @since 3.6.0 |
|
7347 |
*/ |
|
7348 |
function wp_auth_check_load() {
|
|
| 9 | 7349 |
if ( ! is_admin() && ! is_user_logged_in() ) {
|
| 0 | 7350 |
return; |
| 9 | 7351 |
} |
7352 |
||
7353 |
if ( defined( 'IFRAME_REQUEST' ) ) {
|
|
| 0 | 7354 |
return; |
| 9 | 7355 |
} |
| 0 | 7356 |
|
7357 |
$screen = get_current_screen(); |
|
7358 |
$hidden = array( 'update', 'update-network', 'update-core', 'update-core-network', 'upgrade', 'upgrade-network', 'network' ); |
|
| 16 | 7359 |
$show = ! in_array( $screen->id, $hidden, true ); |
| 0 | 7360 |
|
| 5 | 7361 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7362 |
* Filters whether to load the authentication check. |
| 5 | 7363 |
* |
| 16 | 7364 |
* Returning a falsey value from the filter will effectively short-circuit |
| 5 | 7365 |
* loading the authentication check. |
7366 |
* |
|
7367 |
* @since 3.6.0 |
|
7368 |
* |
|
7369 |
* @param bool $show Whether to load the authentication check. |
|
7370 |
* @param WP_Screen $screen The current screen object. |
|
7371 |
*/ |
|
| 0 | 7372 |
if ( apply_filters( 'wp_auth_check_load', $show, $screen ) ) {
|
7373 |
wp_enqueue_style( 'wp-auth-check' ); |
|
7374 |
wp_enqueue_script( 'wp-auth-check' ); |
|
7375 |
||
7376 |
add_action( 'admin_print_footer_scripts', 'wp_auth_check_html', 5 ); |
|
7377 |
add_action( 'wp_print_footer_scripts', 'wp_auth_check_html', 5 ); |
|
7378 |
} |
|
7379 |
} |
|
7380 |
||
7381 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7382 |
* Outputs the HTML that shows the wp-login dialog when the user is no longer logged in. |
| 0 | 7383 |
* |
7384 |
* @since 3.6.0 |
|
7385 |
*/ |
|
7386 |
function wp_auth_check_html() {
|
|
| 9 | 7387 |
$login_url = wp_login_url(); |
| 0 | 7388 |
$current_domain = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST']; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7389 |
$same_domain = str_starts_with( $login_url, $current_domain ); |
| 0 | 7390 |
|
| 5 | 7391 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7392 |
* Filters whether the authentication check originated at the same domain. |
| 5 | 7393 |
* |
7394 |
* @since 3.6.0 |
|
7395 |
* |
|
7396 |
* @param bool $same_domain Whether the authentication check originated at the same domain. |
|
7397 |
*/ |
|
| 0 | 7398 |
$same_domain = apply_filters( 'wp_auth_check_same_domain', $same_domain ); |
| 9 | 7399 |
$wrap_class = $same_domain ? 'hidden' : 'hidden fallback'; |
| 0 | 7400 |
|
7401 |
?> |
|
7402 |
<div id="wp-auth-check-wrap" class="<?php echo $wrap_class; ?>"> |
|
7403 |
<div id="wp-auth-check-bg"></div> |
|
7404 |
<div id="wp-auth-check"> |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7405 |
<button type="button" class="wp-auth-check-close button-link"><span class="screen-reader-text"> |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7406 |
<?php |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7407 |
/* translators: Hidden accessibility text. */ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7408 |
_e( 'Close dialog' ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7409 |
?> |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7410 |
</span></button> |
| 0 | 7411 |
<?php |
7412 |
||
7413 |
if ( $same_domain ) {
|
|
| 9 | 7414 |
$login_src = add_query_arg( |
7415 |
array( |
|
7416 |
'interim-login' => '1', |
|
7417 |
'wp_lang' => get_user_locale(), |
|
7418 |
), |
|
7419 |
$login_url |
|
7420 |
); |
|
| 0 | 7421 |
?> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7422 |
<div id="wp-auth-check-form" class="loading" data-src="<?php echo esc_url( $login_src ); ?>"></div> |
| 0 | 7423 |
<?php |
7424 |
} |
|
7425 |
||
7426 |
?> |
|
7427 |
<div class="wp-auth-fallback"> |
|
| 9 | 7428 |
<p><b class="wp-auth-fallback-expired" tabindex="0"><?php _e( 'Session expired' ); ?></b></p> |
7429 |
<p><a href="<?php echo esc_url( $login_url ); ?>" target="_blank"><?php _e( 'Please log in again.' ); ?></a> |
|
7430 |
<?php _e( 'The login page will open in a new tab. After logging in you can close it and return to this page.' ); ?></p> |
|
| 0 | 7431 |
</div> |
7432 |
</div> |
|
7433 |
</div> |
|
7434 |
<?php |
|
7435 |
} |
|
7436 |
||
7437 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7438 |
* Checks whether a user is still logged in, for the heartbeat. |
| 0 | 7439 |
* |
7440 |
* Send a result that shows a log-in box if the user is no longer logged in, |
|
7441 |
* or if their cookie is within the grace period. |
|
7442 |
* |
|
7443 |
* @since 3.6.0 |
|
| 5 | 7444 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7445 |
* @global int $login_grace_period |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7446 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7447 |
* @param array $response The Heartbeat response. |
| 16 | 7448 |
* @return array The Heartbeat response with 'wp-auth-check' value set. |
| 0 | 7449 |
*/ |
| 5 | 7450 |
function wp_auth_check( $response ) {
|
| 0 | 7451 |
$response['wp-auth-check'] = is_user_logged_in() && empty( $GLOBALS['login_grace_period'] ); |
7452 |
return $response; |
|
7453 |
} |
|
7454 |
||
7455 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7456 |
* Returns RegEx body to liberally match an opening HTML tag. |
| 5 | 7457 |
* |
7458 |
* Matches an opening HTML tag that: |
|
| 0 | 7459 |
* 1. Is self-closing or |
7460 |
* 2. Has no body but has a closing tag of the same name or |
|
7461 |
* 3. Contains a body and a closing tag of the same name |
|
7462 |
* |
|
| 5 | 7463 |
* Note: this RegEx does not balance inner tags and does not attempt |
7464 |
* to produce valid HTML |
|
| 0 | 7465 |
* |
7466 |
* @since 3.6.0 |
|
7467 |
* |
|
| 5 | 7468 |
* @param string $tag An HTML tag name. Example: 'video'. |
7469 |
* @return string Tag RegEx. |
|
| 0 | 7470 |
*/ |
7471 |
function get_tag_regex( $tag ) {
|
|
| 9 | 7472 |
if ( empty( $tag ) ) {
|
| 16 | 7473 |
return ''; |
| 9 | 7474 |
} |
| 0 | 7475 |
return sprintf( '<%1$s[^<]*(?:>[\s\S]*<\/%1$s>|\s*\/>)', tag_escape( $tag ) ); |
7476 |
} |
|
7477 |
||
7478 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7479 |
* Indicates if a given slug for a character set represents the UTF-8 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7480 |
* text encoding. If not provided, examines the current blog's charset. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7481 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7482 |
* A charset is considered to represent UTF-8 if it is a case-insensitive |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7483 |
* match of "UTF-8" with or without the hyphen. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7484 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7485 |
* Example: |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7486 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7487 |
* true === is_utf8_charset( 'UTF-8' ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7488 |
* true === is_utf8_charset( 'utf8' ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7489 |
* false === is_utf8_charset( 'latin1' ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7490 |
* false === is_utf8_charset( 'UTF 8' ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7491 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7492 |
* // Only strings match. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7493 |
* false === is_utf8_charset( [ 'charset' => 'utf-8' ] ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7494 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7495 |
* // Without a given charset, it depends on the site option "blog_charset". |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7496 |
* $is_utf8 = is_utf8_charset(); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7497 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7498 |
* @since 6.6.0 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7499 |
* @since 6.6.1 A wrapper for _is_utf8_charset |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7500 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7501 |
* @see _is_utf8_charset |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7502 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7503 |
* @param string|null $blog_charset Optional. Slug representing a text character encoding, or "charset". |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7504 |
* E.g. "UTF-8", "Windows-1252", "ISO-8859-1", "SJIS". |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7505 |
* Default value is to infer from "blog_charset" option. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7506 |
* @return bool Whether the slug represents the UTF-8 encoding. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7507 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7508 |
function is_utf8_charset( $blog_charset = null ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7509 |
return _is_utf8_charset( $blog_charset ?? get_option( 'blog_charset' ) ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7510 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7511 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7512 |
/** |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7513 |
* Retrieves a canonical form of the provided charset appropriate for passing to PHP |
| 16 | 7514 |
* functions such as htmlspecialchars() and charset HTML attributes. |
| 0 | 7515 |
* |
7516 |
* @since 3.6.0 |
|
| 5 | 7517 |
* @access private |
7518 |
* |
|
7519 |
* @see https://core.trac.wordpress.org/ticket/23688 |
|
7520 |
* |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7521 |
* @param string $charset A charset name, e.g. "UTF-8", "Windows-1252", "SJIS". |
| 5 | 7522 |
* @return string The canonical form of the charset. |
| 0 | 7523 |
*/ |
7524 |
function _canonical_charset( $charset ) {
|
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7525 |
if ( is_utf8_charset( $charset ) ) {
|
| 0 | 7526 |
return 'UTF-8'; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7527 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7528 |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7529 |
/* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7530 |
* Normalize the ISO-8859-1 family of languages. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7531 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7532 |
* This is not required for htmlspecialchars(), as it properly recognizes all of |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7533 |
* the input character sets that here are transformed into "ISO-8859-1". |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7534 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7535 |
* @todo Should this entire check be removed since it's not required for the stated purpose? |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7536 |
* @todo Should WordPress transform other potential charset equivalents, such as "latin1"? |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7537 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7538 |
if ( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7539 |
( 0 === strcasecmp( 'iso-8859-1', $charset ) ) || |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7540 |
( 0 === strcasecmp( 'iso8859-1', $charset ) ) |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7541 |
) {
|
| 0 | 7542 |
return 'ISO-8859-1'; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7543 |
} |
| 0 | 7544 |
|
7545 |
return $charset; |
|
7546 |
} |
|
7547 |
||
7548 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7549 |
* Sets the mbstring internal encoding to a binary safe encoding when func_overload |
| 5 | 7550 |
* is enabled. |
7551 |
* |
|
7552 |
* When mbstring.func_overload is in use for multi-byte encodings, the results from |
|
7553 |
* strlen() and similar functions respect the utf8 characters, causing binary data |
|
7554 |
* to return incorrect lengths. |
|
7555 |
* |
|
7556 |
* This function overrides the mbstring encoding to a binary-safe encoding, and |
|
7557 |
* resets it to the users expected encoding afterwards through the |
|
7558 |
* `reset_mbstring_encoding` function. |
|
7559 |
* |
|
7560 |
* It is safe to recursively call this function, however each |
|
7561 |
* `mbstring_binary_safe_encoding()` call must be followed up with an equal number |
|
7562 |
* of `reset_mbstring_encoding()` calls. |
|
7563 |
* |
|
7564 |
* @since 3.7.0 |
|
| 0 | 7565 |
* |
7566 |
* @see reset_mbstring_encoding() |
|
7567 |
* |
|
| 5 | 7568 |
* @param bool $reset Optional. Whether to reset the encoding back to a previously-set encoding. |
7569 |
* Default false. |
|
| 0 | 7570 |
*/ |
7571 |
function mbstring_binary_safe_encoding( $reset = false ) {
|
|
| 9 | 7572 |
static $encodings = array(); |
| 0 | 7573 |
static $overloaded = null; |
7574 |
||
| 9 | 7575 |
if ( is_null( $overloaded ) ) {
|
| 18 | 7576 |
if ( function_exists( 'mb_internal_encoding' ) |
7577 |
&& ( (int) ini_get( 'mbstring.func_overload' ) & 2 ) // phpcs:ignore PHPCompatibility.IniDirectives.RemovedIniDirectives.mbstring_func_overloadDeprecated |
|
7578 |
) {
|
|
7579 |
$overloaded = true; |
|
7580 |
} else {
|
|
7581 |
$overloaded = false; |
|
7582 |
} |
|
| 9 | 7583 |
} |
7584 |
||
7585 |
if ( false === $overloaded ) {
|
|
| 0 | 7586 |
return; |
| 9 | 7587 |
} |
| 0 | 7588 |
|
7589 |
if ( ! $reset ) {
|
|
7590 |
$encoding = mb_internal_encoding(); |
|
7591 |
array_push( $encodings, $encoding ); |
|
7592 |
mb_internal_encoding( 'ISO-8859-1' ); |
|
7593 |
} |
|
7594 |
||
7595 |
if ( $reset && $encodings ) {
|
|
7596 |
$encoding = array_pop( $encodings ); |
|
7597 |
mb_internal_encoding( $encoding ); |
|
7598 |
} |
|
7599 |
} |
|
7600 |
||
7601 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7602 |
* Resets the mbstring internal encoding to a users previously set encoding. |
| 0 | 7603 |
* |
7604 |
* @see mbstring_binary_safe_encoding() |
|
7605 |
* |
|
7606 |
* @since 3.7.0 |
|
7607 |
*/ |
|
7608 |
function reset_mbstring_encoding() {
|
|
7609 |
mbstring_binary_safe_encoding( true ); |
|
7610 |
} |
|
| 5 | 7611 |
|
7612 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7613 |
* Filters/validates a variable as a boolean. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7614 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7615 |
* Alternative to `filter_var( $value, FILTER_VALIDATE_BOOLEAN )`. |
| 5 | 7616 |
* |
7617 |
* @since 4.0.0 |
|
7618 |
* |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7619 |
* @param mixed $value Boolean value to validate. |
| 5 | 7620 |
* @return bool Whether the value is validated. |
7621 |
*/ |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7622 |
function wp_validate_boolean( $value ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7623 |
if ( is_bool( $value ) ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7624 |
return $value; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7625 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7626 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7627 |
if ( is_string( $value ) && 'false' === strtolower( $value ) ) {
|
| 5 | 7628 |
return false; |
7629 |
} |
|
7630 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7631 |
return (bool) $value; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7632 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7633 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7634 |
/** |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7635 |
* Deletes a file. |
| 5 | 7636 |
* |
7637 |
* @since 4.2.0 |
|
7638 |
* |
|
7639 |
* @param string $file The path to the file to delete. |
|
7640 |
*/ |
|
7641 |
function wp_delete_file( $file ) {
|
|
7642 |
/** |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7643 |
* Filters the path of the file to delete. |
| 5 | 7644 |
* |
7645 |
* @since 2.1.0 |
|
7646 |
* |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7647 |
* @param string $file Path to the file to delete. |
| 5 | 7648 |
*/ |
7649 |
$delete = apply_filters( 'wp_delete_file', $file ); |
|
7650 |
if ( ! empty( $delete ) ) {
|
|
7651 |
@unlink( $delete ); |
|
7652 |
} |
|
7653 |
} |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7654 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7655 |
/** |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7656 |
* Deletes a file if its path is within the given directory. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7657 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7658 |
* @since 4.9.7 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7659 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7660 |
* @param string $file Absolute path to the file to delete. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7661 |
* @param string $directory Absolute path to a directory. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7662 |
* @return bool True on success, false on failure. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7663 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7664 |
function wp_delete_file_from_directory( $file, $directory ) {
|
| 9 | 7665 |
if ( wp_is_stream( $file ) ) {
|
7666 |
$real_file = $file; |
|
7667 |
$real_directory = $directory; |
|
7668 |
} else {
|
|
7669 |
$real_file = realpath( wp_normalize_path( $file ) ); |
|
7670 |
$real_directory = realpath( wp_normalize_path( $directory ) ); |
|
7671 |
} |
|
7672 |
||
7673 |
if ( false !== $real_file ) {
|
|
7674 |
$real_file = wp_normalize_path( $real_file ); |
|
7675 |
} |
|
7676 |
||
7677 |
if ( false !== $real_directory ) {
|
|
7678 |
$real_directory = wp_normalize_path( $real_directory ); |
|
7679 |
} |
|
7680 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7681 |
if ( false === $real_file || false === $real_directory || ! str_starts_with( $real_file, trailingslashit( $real_directory ) ) ) {
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7682 |
return false; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7683 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7684 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7685 |
wp_delete_file( $file ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7686 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7687 |
return true; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7688 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7689 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7690 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7691 |
* Outputs a small JS snippet on preview tabs/windows to remove `window.name` when a user is navigating to another page. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7692 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7693 |
* This prevents reusing the same tab for a preview when the user has navigated away. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7694 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7695 |
* @since 4.3.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7696 |
* |
| 16 | 7697 |
* @global WP_Post $post Global post object. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7698 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7699 |
function wp_post_preview_js() {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7700 |
global $post; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7701 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7702 |
if ( ! is_preview() || empty( $post ) ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7703 |
return; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7704 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7705 |
|
| 16 | 7706 |
// Has to match the window name used in post_submit_meta_box(). |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7707 |
$name = 'wp-preview-' . (int) $post->ID; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7708 |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7709 |
ob_start(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7710 |
?> |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7711 |
<script> |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7712 |
( function() {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7713 |
var query = document.location.search; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7714 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7715 |
if ( query && query.indexOf( 'preview=true' ) !== -1 ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7716 |
window.name = '<?php echo $name; ?>'; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7717 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7718 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7719 |
if ( window.addEventListener ) {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7720 |
window.addEventListener( 'pagehide', function() { window.name = ''; } );
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7721 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7722 |
}()); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7723 |
</script> |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7724 |
<?php |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7725 |
wp_print_inline_script_tag( wp_remove_surrounding_empty_script_tags( ob_get_clean() ) ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7726 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7727 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7728 |
/** |
| 9 | 7729 |
* Parses and formats a MySQL datetime (Y-m-d H:i:s) for ISO8601 (Y-m-d\TH:i:s). |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7730 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7731 |
* Explicitly strips timezones, as datetimes are not saved with any timezone |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7732 |
* information. Including any information on the offset could be misleading. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7733 |
* |
| 9 | 7734 |
* Despite historical function name, the output does not conform to RFC3339 format, |
7735 |
* which must contain timezone. |
|
7736 |
* |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7737 |
* @since 4.4.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7738 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7739 |
* @param string $date_string Date string to parse and format. |
| 9 | 7740 |
* @return string Date formatted for ISO8601 without time zone. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7741 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7742 |
function mysql_to_rfc3339( $date_string ) {
|
| 9 | 7743 |
return mysql2date( 'Y-m-d\TH:i:s', $date_string, false ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7744 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7745 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7746 |
/** |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7747 |
* Attempts to raise the PHP memory limit for memory intensive processes. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7748 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7749 |
* Only allows raising the existing limit and prevents lowering it. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7750 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7751 |
* @since 4.6.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7752 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7753 |
* @param string $context Optional. Context in which the function is called. Accepts either 'admin', |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7754 |
* 'image', 'cron', or an arbitrary other context. If an arbitrary context is passed, |
| 18 | 7755 |
* the similarly arbitrary {@see '$context_memory_limit'} filter will be
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7756 |
* invoked. Default 'admin'. |
| 18 | 7757 |
* @return int|string|false The limit that was set or false on failure. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7758 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7759 |
function wp_raise_memory_limit( $context = 'admin' ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7760 |
// Exit early if the limit cannot be changed. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7761 |
if ( false === wp_is_ini_value_changeable( 'memory_limit' ) ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7762 |
return false; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7763 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7764 |
|
| 16 | 7765 |
$current_limit = ini_get( 'memory_limit' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7766 |
$current_limit_int = wp_convert_hr_to_bytes( $current_limit ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7767 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7768 |
if ( -1 === $current_limit_int ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7769 |
return false; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7770 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7771 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7772 |
$wp_max_limit = WP_MAX_MEMORY_LIMIT; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7773 |
$wp_max_limit_int = wp_convert_hr_to_bytes( $wp_max_limit ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7774 |
$filtered_limit = $wp_max_limit; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7775 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7776 |
switch ( $context ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7777 |
case 'admin': |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7778 |
/** |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7779 |
* Filters the maximum memory limit available for administration screens. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7780 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7781 |
* This only applies to administrators, who may require more memory for tasks |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7782 |
* like updates. Memory limits when processing images (uploaded or edited by |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7783 |
* users of any role) are handled separately. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7784 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7785 |
* The `WP_MAX_MEMORY_LIMIT` constant specifically defines the maximum memory |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7786 |
* limit available when in the administration back end. The default is 256M |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7787 |
* (256 megabytes of memory) or the original `memory_limit` php.ini value if |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7788 |
* this is higher. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7789 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7790 |
* @since 3.0.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7791 |
* @since 4.6.0 The default now takes the original `memory_limit` into account. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7792 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7793 |
* @param int|string $filtered_limit The maximum WordPress memory limit. Accepts an integer |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7794 |
* (bytes), or a shorthand string notation, such as '256M'. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7795 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7796 |
$filtered_limit = apply_filters( 'admin_memory_limit', $filtered_limit ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7797 |
break; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7798 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7799 |
case 'image': |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7800 |
/** |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7801 |
* Filters the memory limit allocated for image manipulation. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7802 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7803 |
* @since 3.5.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7804 |
* @since 4.6.0 The default now takes the original `memory_limit` into account. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7805 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7806 |
* @param int|string $filtered_limit Maximum memory limit to allocate for image processing. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7807 |
* Default `WP_MAX_MEMORY_LIMIT` or the original |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7808 |
* php.ini `memory_limit`, whichever is higher. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7809 |
* Accepts an integer (bytes), or a shorthand string |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7810 |
* notation, such as '256M'. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7811 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7812 |
$filtered_limit = apply_filters( 'image_memory_limit', $filtered_limit ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7813 |
break; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7814 |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7815 |
case 'cron': |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7816 |
/** |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7817 |
* Filters the memory limit allocated for WP-Cron event processing. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7818 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7819 |
* @since 6.3.0 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7820 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7821 |
* @param int|string $filtered_limit Maximum memory limit to allocate for WP-Cron. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7822 |
* Default `WP_MAX_MEMORY_LIMIT` or the original |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7823 |
* php.ini `memory_limit`, whichever is higher. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7824 |
* Accepts an integer (bytes), or a shorthand string |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7825 |
* notation, such as '256M'. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7826 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7827 |
$filtered_limit = apply_filters( 'cron_memory_limit', $filtered_limit ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7828 |
break; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7829 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7830 |
default: |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7831 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7832 |
* Filters the memory limit allocated for an arbitrary context. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7833 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7834 |
* The dynamic portion of the hook name, `$context`, refers to an arbitrary |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7835 |
* context passed on calling the function. This allows for plugins to define |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7836 |
* their own contexts for raising the memory limit. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7837 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7838 |
* @since 4.6.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7839 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7840 |
* @param int|string $filtered_limit Maximum memory limit to allocate for this context. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7841 |
* Default WP_MAX_MEMORY_LIMIT` or the original php.ini `memory_limit`, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7842 |
* whichever is higher. Accepts an integer (bytes), or a |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7843 |
* shorthand string notation, such as '256M'. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7844 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7845 |
$filtered_limit = apply_filters( "{$context}_memory_limit", $filtered_limit );
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7846 |
break; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7847 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7848 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7849 |
$filtered_limit_int = wp_convert_hr_to_bytes( $filtered_limit ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7850 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7851 |
if ( -1 === $filtered_limit_int || ( $filtered_limit_int > $wp_max_limit_int && $filtered_limit_int > $current_limit_int ) ) {
|
| 16 | 7852 |
if ( false !== ini_set( 'memory_limit', $filtered_limit ) ) {
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7853 |
return $filtered_limit; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7854 |
} else {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7855 |
return false; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7856 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7857 |
} elseif ( -1 === $wp_max_limit_int || $wp_max_limit_int > $current_limit_int ) {
|
| 16 | 7858 |
if ( false !== ini_set( 'memory_limit', $wp_max_limit ) ) {
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7859 |
return $wp_max_limit; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7860 |
} else {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7861 |
return false; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7862 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7863 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7864 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7865 |
return false; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7866 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7867 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7868 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7869 |
* Generates a random UUID (version 4). |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7870 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7871 |
* @since 4.7.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7872 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7873 |
* @return string UUID. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7874 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7875 |
function wp_generate_uuid4() {
|
| 9 | 7876 |
return sprintf( |
7877 |
'%04x%04x-%04x-%04x-%04x-%04x%04x%04x', |
|
7878 |
mt_rand( 0, 0xffff ), |
|
7879 |
mt_rand( 0, 0xffff ), |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7880 |
mt_rand( 0, 0xffff ), |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7881 |
mt_rand( 0, 0x0fff ) | 0x4000, |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7882 |
mt_rand( 0, 0x3fff ) | 0x8000, |
| 9 | 7883 |
mt_rand( 0, 0xffff ), |
7884 |
mt_rand( 0, 0xffff ), |
|
7885 |
mt_rand( 0, 0xffff ) |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7886 |
); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7887 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7888 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7889 |
/** |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7890 |
* Validates that a UUID is valid. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7891 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7892 |
* @since 4.9.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7893 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7894 |
* @param mixed $uuid UUID to check. |
| 9 | 7895 |
* @param int $version Specify which version of UUID to check against. Default is none, |
7896 |
* to accept any UUID version. Otherwise, only version allowed is `4`. |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7897 |
* @return bool The string is a valid UUID or false on failure. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7898 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7899 |
function wp_is_uuid( $uuid, $version = null ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7900 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7901 |
if ( ! is_string( $uuid ) ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7902 |
return false; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7903 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7904 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7905 |
if ( is_numeric( $version ) ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7906 |
if ( 4 !== (int) $version ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7907 |
_doing_it_wrong( __FUNCTION__, __( 'Only UUID V4 is supported at this time.' ), '4.9.0' ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7908 |
return false; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7909 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7910 |
$regex = '/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/';
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7911 |
} else {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7912 |
$regex = '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/';
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7913 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7914 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7915 |
return (bool) preg_match( $regex, $uuid ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7916 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7917 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7918 |
/** |
| 16 | 7919 |
* Gets unique ID. |
| 9 | 7920 |
* |
7921 |
* This is a PHP implementation of Underscore's uniqueId method. A static variable |
|
7922 |
* contains an integer that is incremented with each call. This number is returned |
|
7923 |
* with the optional prefix. As such the returned value is not universally unique, |
|
7924 |
* but it is unique across the life of the PHP process. |
|
7925 |
* |
|
7926 |
* @since 5.0.3 |
|
7927 |
* |
|
7928 |
* @param string $prefix Prefix for the returned ID. |
|
7929 |
* @return string Unique ID. |
|
7930 |
*/ |
|
7931 |
function wp_unique_id( $prefix = '' ) {
|
|
7932 |
static $id_counter = 0; |
|
7933 |
return $prefix . (string) ++$id_counter; |
|
7934 |
} |
|
7935 |
||
7936 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7937 |
* Generates an incremental ID that is independent per each different prefix. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7938 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7939 |
* It is similar to `wp_unique_id`, but each prefix has its own internal ID |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7940 |
* counter to make each prefix independent from each other. The ID starts at 1 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7941 |
* and increments on each call. The returned value is not universally unique, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7942 |
* but it is unique across the life of the PHP process and it's stable per |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7943 |
* prefix. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7944 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7945 |
* @since 6.4.0 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7946 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7947 |
* @param string $prefix Optional. Prefix for the returned ID. Default empty string. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7948 |
* @return string Incremental ID per prefix. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7949 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7950 |
function wp_unique_prefixed_id( $prefix = '' ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7951 |
static $id_counters = array(); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7952 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7953 |
if ( ! is_string( $prefix ) ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7954 |
wp_trigger_error( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7955 |
__FUNCTION__, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7956 |
sprintf( 'The prefix must be a string. "%s" data type given.', gettype( $prefix ) ) |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7957 |
); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7958 |
$prefix = ''; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7959 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7960 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7961 |
if ( ! isset( $id_counters[ $prefix ] ) ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7962 |
$id_counters[ $prefix ] = 0; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7963 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7964 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7965 |
$id = ++$id_counters[ $prefix ]; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7966 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7967 |
return $prefix . (string) $id; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7968 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7969 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7970 |
/** |
| 16 | 7971 |
* Gets last changed date for the specified cache group. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7972 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7973 |
* @since 4.7.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7974 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7975 |
* @param string $group Where the cache contents are grouped. |
| 16 | 7976 |
* @return string UNIX timestamp with microseconds representing when the group was last changed. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7977 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7978 |
function wp_cache_get_last_changed( $group ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7979 |
$last_changed = wp_cache_get( 'last_changed', $group ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7980 |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7981 |
if ( $last_changed ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7982 |
return $last_changed; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7983 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7984 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7985 |
return wp_cache_set_last_changed( $group ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7986 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7987 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7988 |
/** |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7989 |
* Sets last changed date for the specified cache group to now. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7990 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7991 |
* @since 6.3.0 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7992 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7993 |
* @param string $group Where the cache contents are grouped. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7994 |
* @return string UNIX timestamp when the group was last changed. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7995 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7996 |
function wp_cache_set_last_changed( $group ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7997 |
$previous_time = wp_cache_get( 'last_changed', $group ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7998 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7999 |
$time = microtime(); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8000 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8001 |
wp_cache_set( 'last_changed', $time, $group ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8002 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8003 |
/** |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8004 |
* Fires after a cache group `last_changed` time is updated. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8005 |
* This may occur multiple times per page load and registered |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8006 |
* actions must be performant. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8007 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8008 |
* @since 6.3.0 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8009 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8010 |
* @param string $group The cache group name. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8011 |
* @param int $time The new last changed time. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8012 |
* @param int|false $previous_time The previous last changed time. False if not previously set. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8013 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8014 |
do_action( 'wp_cache_set_last_changed', $group, $time, $previous_time ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8015 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8016 |
return $time; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8017 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8018 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8019 |
/** |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8020 |
* Sends an email to the old site admin email address when the site admin email address changes. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8021 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8022 |
* @since 4.9.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8023 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8024 |
* @param string $old_email The old site admin email address. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8025 |
* @param string $new_email The new site admin email address. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8026 |
* @param string $option_name The relevant database option name. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8027 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8028 |
function wp_site_admin_email_change_notification( $old_email, $new_email, $option_name ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8029 |
$send = true; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8030 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8031 |
// Don't send the notification to the default 'admin_email' value. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8032 |
if ( 'you@example.com' === $old_email ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8033 |
$send = false; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8034 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8035 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8036 |
/** |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8037 |
* Filters whether to send the site admin email change notification email. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8038 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8039 |
* @since 4.9.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8040 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8041 |
* @param bool $send Whether to send the email notification. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8042 |
* @param string $old_email The old site admin email address. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8043 |
* @param string $new_email The new site admin email address. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8044 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8045 |
$send = apply_filters( 'send_site_admin_email_change_email', $send, $old_email, $new_email ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8046 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8047 |
if ( ! $send ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8048 |
return; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8049 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8050 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8051 |
/* translators: Do not translate OLD_EMAIL, NEW_EMAIL, SITENAME, SITEURL: those are placeholders. */ |
| 9 | 8052 |
$email_change_text = __( |
8053 |
'Hi, |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8054 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8055 |
This notice confirms that the admin email address was changed on ###SITENAME###. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8056 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8057 |
The new admin email address is ###NEW_EMAIL###. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8058 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8059 |
This email has been sent to ###OLD_EMAIL### |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8060 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8061 |
Regards, |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8062 |
All at ###SITENAME### |
| 9 | 8063 |
###SITEURL###' |
8064 |
); |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8065 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8066 |
$email_change_email = array( |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8067 |
'to' => $old_email, |
| 16 | 8068 |
/* translators: Site admin email change notification email subject. %s: Site title. */ |
| 9 | 8069 |
'subject' => __( '[%s] Admin Email Changed' ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8070 |
'message' => $email_change_text, |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8071 |
'headers' => '', |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8072 |
); |
| 16 | 8073 |
|
8074 |
// Get site name. |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8075 |
$site_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8076 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8077 |
/** |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8078 |
* Filters the contents of the email notification sent when the site admin email address is changed. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8079 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8080 |
* @since 4.9.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8081 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8082 |
* @param array $email_change_email {
|
| 18 | 8083 |
* Used to build wp_mail(). |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8084 |
* |
| 18 | 8085 |
* @type string $to The intended recipient. |
8086 |
* @type string $subject The subject of the email. |
|
8087 |
* @type string $message The content of the email. |
|
8088 |
* The following strings have a special meaning and will get replaced dynamically: |
|
8089 |
* - ###OLD_EMAIL### The old site admin email address. |
|
8090 |
* - ###NEW_EMAIL### The new site admin email address. |
|
8091 |
* - ###SITENAME### The name of the site. |
|
8092 |
* - ###SITEURL### The URL to the site. |
|
8093 |
* @type string $headers Headers. |
|
8094 |
* } |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8095 |
* @param string $old_email The old site admin email address. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8096 |
* @param string $new_email The new site admin email address. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8097 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8098 |
$email_change_email = apply_filters( 'site_admin_email_change_email', $email_change_email, $old_email, $new_email ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8099 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8100 |
$email_change_email['message'] = str_replace( '###OLD_EMAIL###', $old_email, $email_change_email['message'] ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8101 |
$email_change_email['message'] = str_replace( '###NEW_EMAIL###', $new_email, $email_change_email['message'] ); |
| 9 | 8102 |
$email_change_email['message'] = str_replace( '###SITENAME###', $site_name, $email_change_email['message'] ); |
8103 |
$email_change_email['message'] = str_replace( '###SITEURL###', home_url(), $email_change_email['message'] ); |
|
8104 |
||
8105 |
wp_mail( |
|
8106 |
$email_change_email['to'], |
|
8107 |
sprintf( |
|
8108 |
$email_change_email['subject'], |
|
8109 |
$site_name |
|
8110 |
), |
|
8111 |
$email_change_email['message'], |
|
8112 |
$email_change_email['headers'] |
|
8113 |
); |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8114 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8115 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8116 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8117 |
* Returns an anonymized IPv4 or IPv6 address. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8118 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8119 |
* @since 4.9.6 Abstracted from `WP_Community_Events::get_unsafe_client_ip()`. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8120 |
* |
| 16 | 8121 |
* @param string $ip_addr The IPv4 or IPv6 address to be anonymized. |
8122 |
* @param bool $ipv6_fallback Optional. Whether to return the original IPv6 address if the needed functions |
|
8123 |
* to anonymize it are not present. Default false, return `::` (unspecified address). |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8124 |
* @return string The anonymized IP address. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8125 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8126 |
function wp_privacy_anonymize_ip( $ip_addr, $ipv6_fallback = false ) {
|
| 19 | 8127 |
if ( empty( $ip_addr ) ) {
|
8128 |
return '0.0.0.0'; |
|
8129 |
} |
|
8130 |
||
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8131 |
// Detect what kind of IP address this is. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8132 |
$ip_prefix = ''; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8133 |
$is_ipv6 = substr_count( $ip_addr, ':' ) > 1; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8134 |
$is_ipv4 = ( 3 === substr_count( $ip_addr, '.' ) ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8135 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8136 |
if ( $is_ipv6 && $is_ipv4 ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8137 |
// IPv6 compatibility mode, temporarily strip the IPv6 part, and treat it like IPv4. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8138 |
$ip_prefix = '::ffff:'; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8139 |
$ip_addr = preg_replace( '/^\[?[0-9a-f:]*:/i', '', $ip_addr ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8140 |
$ip_addr = str_replace( ']', '', $ip_addr ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8141 |
$is_ipv6 = false; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8142 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8143 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8144 |
if ( $is_ipv6 ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8145 |
// IPv6 addresses will always be enclosed in [] if there's a port. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8146 |
$left_bracket = strpos( $ip_addr, '[' ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8147 |
$right_bracket = strpos( $ip_addr, ']' ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8148 |
$percent = strpos( $ip_addr, '%' ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8149 |
$netmask = 'ffff:ffff:ffff:ffff:0000:0000:0000:0000'; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8150 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8151 |
// Strip the port (and [] from IPv6 addresses), if they exist. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8152 |
if ( false !== $left_bracket && false !== $right_bracket ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8153 |
$ip_addr = substr( $ip_addr, $left_bracket + 1, $right_bracket - $left_bracket - 1 ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8154 |
} elseif ( false !== $left_bracket || false !== $right_bracket ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8155 |
// The IP has one bracket, but not both, so it's malformed. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8156 |
return '::'; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8157 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8158 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8159 |
// Strip the reachability scope. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8160 |
if ( false !== $percent ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8161 |
$ip_addr = substr( $ip_addr, 0, $percent ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8162 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8163 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8164 |
// No invalid characters should be left. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8165 |
if ( preg_match( '/[^0-9a-f:]/i', $ip_addr ) ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8166 |
return '::'; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8167 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8168 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8169 |
// Partially anonymize the IP by reducing it to the corresponding network ID. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8170 |
if ( function_exists( 'inet_pton' ) && function_exists( 'inet_ntop' ) ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8171 |
$ip_addr = inet_ntop( inet_pton( $ip_addr ) & inet_pton( $netmask ) ); |
| 9 | 8172 |
if ( false === $ip_addr ) {
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8173 |
return '::'; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8174 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8175 |
} elseif ( ! $ipv6_fallback ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8176 |
return '::'; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8177 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8178 |
} elseif ( $is_ipv4 ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8179 |
// Strip any port and partially anonymize the IP. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8180 |
$last_octet_position = strrpos( $ip_addr, '.' ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8181 |
$ip_addr = substr( $ip_addr, 0, $last_octet_position ) . '.0'; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8182 |
} else {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8183 |
return '0.0.0.0'; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8184 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8185 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8186 |
// Restore the IPv6 prefix to compatibility mode addresses. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8187 |
return $ip_prefix . $ip_addr; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8188 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8189 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8190 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8191 |
* Returns uniform "anonymous" data by type. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8192 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8193 |
* @since 4.9.6 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8194 |
* |
| 16 | 8195 |
* @param string $type The type of data to be anonymized. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8196 |
* @param string $data Optional. The data to be anonymized. Default empty string. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8197 |
* @return string The anonymous data for the requested type. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8198 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8199 |
function wp_privacy_anonymize_data( $type, $data = '' ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8200 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8201 |
switch ( $type ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8202 |
case 'email': |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8203 |
$anonymous = 'deleted@site.invalid'; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8204 |
break; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8205 |
case 'url': |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8206 |
$anonymous = 'https://site.invalid'; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8207 |
break; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8208 |
case 'ip': |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8209 |
$anonymous = wp_privacy_anonymize_ip( $data ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8210 |
break; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8211 |
case 'date': |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8212 |
$anonymous = '0000-00-00 00:00:00'; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8213 |
break; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8214 |
case 'text': |
| 16 | 8215 |
/* translators: Deleted text. */ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8216 |
$anonymous = __( '[deleted]' ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8217 |
break; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8218 |
case 'longtext': |
| 16 | 8219 |
/* translators: Deleted long text. */ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8220 |
$anonymous = __( 'This content was deleted by the author.' ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8221 |
break; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8222 |
default: |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8223 |
$anonymous = ''; |
| 16 | 8224 |
break; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8225 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8226 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8227 |
/** |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8228 |
* Filters the anonymous data for each type. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8229 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8230 |
* @since 4.9.6 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8231 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8232 |
* @param string $anonymous Anonymized data. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8233 |
* @param string $type Type of the data. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8234 |
* @param string $data Original data. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8235 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8236 |
return apply_filters( 'wp_privacy_anonymize_data', $anonymous, $type, $data ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8237 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8238 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8239 |
/** |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8240 |
* Returns the directory used to store personal data export files. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8241 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8242 |
* @since 4.9.6 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8243 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8244 |
* @see wp_privacy_exports_url |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8245 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8246 |
* @return string Exports directory. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8247 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8248 |
function wp_privacy_exports_dir() {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8249 |
$upload_dir = wp_upload_dir(); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8250 |
$exports_dir = trailingslashit( $upload_dir['basedir'] ) . 'wp-personal-data-exports/'; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8251 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8252 |
/** |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8253 |
* Filters the directory used to store personal data export files. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8254 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8255 |
* @since 4.9.6 |
| 18 | 8256 |
* @since 5.5.0 Exports now use relative paths, so changes to the directory |
8257 |
* via this filter should be reflected on the server. |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8258 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8259 |
* @param string $exports_dir Exports directory. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8260 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8261 |
return apply_filters( 'wp_privacy_exports_dir', $exports_dir ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8262 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8263 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8264 |
/** |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8265 |
* Returns the URL of the directory used to store personal data export files. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8266 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8267 |
* @since 4.9.6 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8268 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8269 |
* @see wp_privacy_exports_dir |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8270 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8271 |
* @return string Exports directory URL. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8272 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8273 |
function wp_privacy_exports_url() {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8274 |
$upload_dir = wp_upload_dir(); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8275 |
$exports_url = trailingslashit( $upload_dir['baseurl'] ) . 'wp-personal-data-exports/'; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8276 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8277 |
/** |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8278 |
* Filters the URL of the directory used to store personal data export files. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8279 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8280 |
* @since 4.9.6 |
| 18 | 8281 |
* @since 5.5.0 Exports now use relative paths, so changes to the directory URL |
8282 |
* via this filter should be reflected on the server. |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8283 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8284 |
* @param string $exports_url Exports directory URL. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8285 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8286 |
return apply_filters( 'wp_privacy_exports_url', $exports_url ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8287 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8288 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8289 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8290 |
* Schedules a `WP_Cron` job to delete expired export files. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8291 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8292 |
* @since 4.9.6 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8293 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8294 |
function wp_schedule_delete_old_privacy_export_files() {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8295 |
if ( wp_installing() ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8296 |
return; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8297 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8298 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8299 |
if ( ! wp_next_scheduled( 'wp_privacy_delete_old_export_files' ) ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8300 |
wp_schedule_event( time(), 'hourly', 'wp_privacy_delete_old_export_files' ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8301 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8302 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8303 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8304 |
/** |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8305 |
* Cleans up export files older than three days old. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8306 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8307 |
* The export files are stored in `wp-content/uploads`, and are therefore publicly |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8308 |
* accessible. A CSPRN is appended to the filename to mitigate the risk of an |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8309 |
* unauthorized person downloading the file, but it is still possible. Deleting |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8310 |
* the file after the data subject has had a chance to delete it adds an additional |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8311 |
* layer of protection. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8312 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8313 |
* @since 4.9.6 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8314 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8315 |
function wp_privacy_delete_old_export_files() {
|
| 9 | 8316 |
$exports_dir = wp_privacy_exports_dir(); |
8317 |
if ( ! is_dir( $exports_dir ) ) {
|
|
8318 |
return; |
|
8319 |
} |
|
8320 |
||
| 16 | 8321 |
require_once ABSPATH . 'wp-admin/includes/file.php'; |
| 18 | 8322 |
$export_files = list_files( $exports_dir, 100, array( 'index.php' ) ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8323 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8324 |
/** |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8325 |
* Filters the lifetime, in seconds, of a personal data export file. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8326 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8327 |
* By default, the lifetime is 3 days. Once the file reaches that age, it will automatically |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8328 |
* be deleted by a cron job. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8329 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8330 |
* @since 4.9.6 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8331 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8332 |
* @param int $expiration The expiration age of the export, in seconds. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8333 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8334 |
$expiration = apply_filters( 'wp_privacy_export_expiration', 3 * DAY_IN_SECONDS ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8335 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8336 |
foreach ( (array) $export_files as $export_file ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8337 |
$file_age_in_seconds = time() - filemtime( $export_file ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8338 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8339 |
if ( $expiration < $file_age_in_seconds ) {
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8340 |
unlink( $export_file ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8341 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8342 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8343 |
} |
| 9 | 8344 |
|
8345 |
/** |
|
8346 |
* Gets the URL to learn more about updating the PHP version the site is running on. |
|
8347 |
* |
|
8348 |
* This URL can be overridden by specifying an environment variable `WP_UPDATE_PHP_URL` or by using the |
|
8349 |
* {@see 'wp_update_php_url'} filter. Providing an empty string is not allowed and will result in the
|
|
8350 |
* default URL being used. Furthermore the page the URL links to should preferably be localized in the |
|
8351 |
* site language. |
|
8352 |
* |
|
8353 |
* @since 5.1.0 |
|
8354 |
* |
|
8355 |
* @return string URL to learn more about updating PHP. |
|
8356 |
*/ |
|
8357 |
function wp_get_update_php_url() {
|
|
8358 |
$default_url = wp_get_default_update_php_url(); |
|
8359 |
||
8360 |
$update_url = $default_url; |
|
8361 |
if ( false !== getenv( 'WP_UPDATE_PHP_URL' ) ) {
|
|
8362 |
$update_url = getenv( 'WP_UPDATE_PHP_URL' ); |
|
8363 |
} |
|
8364 |
||
8365 |
/** |
|
8366 |
* Filters the URL to learn more about updating the PHP version the site is running on. |
|
8367 |
* |
|
8368 |
* Providing an empty string is not allowed and will result in the default URL being used. Furthermore |
|
8369 |
* the page the URL links to should preferably be localized in the site language. |
|
8370 |
* |
|
8371 |
* @since 5.1.0 |
|
8372 |
* |
|
8373 |
* @param string $update_url URL to learn more about updating PHP. |
|
8374 |
*/ |
|
8375 |
$update_url = apply_filters( 'wp_update_php_url', $update_url ); |
|
8376 |
||
8377 |
if ( empty( $update_url ) ) {
|
|
8378 |
$update_url = $default_url; |
|
8379 |
} |
|
8380 |
||
8381 |
return $update_url; |
|
8382 |
} |
|
8383 |
||
8384 |
/** |
|
8385 |
* Gets the default URL to learn more about updating the PHP version the site is running on. |
|
8386 |
* |
|
8387 |
* Do not use this function to retrieve this URL. Instead, use {@see wp_get_update_php_url()} when relying on the URL.
|
|
8388 |
* This function does not allow modifying the returned URL, and is only used to compare the actually used URL with the |
|
8389 |
* default one. |
|
8390 |
* |
|
8391 |
* @since 5.1.0 |
|
8392 |
* @access private |
|
8393 |
* |
|
8394 |
* @return string Default URL to learn more about updating PHP. |
|
8395 |
*/ |
|
8396 |
function wp_get_default_update_php_url() {
|
|
8397 |
return _x( 'https://wordpress.org/support/update-php/', 'localized PHP upgrade information page' ); |
|
8398 |
} |
|
8399 |
||
8400 |
/** |
|
8401 |
* Prints the default annotation for the web host altering the "Update PHP" page URL. |
|
8402 |
* |
|
8403 |
* This function is to be used after {@see wp_get_update_php_url()} to display a consistent
|
|
8404 |
* annotation if the web host has altered the default "Update PHP" page URL. |
|
8405 |
* |
|
8406 |
* @since 5.1.0 |
|
8407 |
* @since 5.2.0 Added the `$before` and `$after` parameters. |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8408 |
* @since 6.4.0 Added the `$display` parameter. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8409 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8410 |
* @param string $before Markup to output before the annotation. Default `<p class="description">`. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8411 |
* @param string $after Markup to output after the annotation. Default `</p>`. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8412 |
* @param bool $display Whether to echo or return the markup. Default `true` for echo. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8413 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8414 |
* @return string|void |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8415 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8416 |
function wp_update_php_annotation( $before = '<p class="description">', $after = '</p>', $display = true ) {
|
| 9 | 8417 |
$annotation = wp_get_update_php_annotation(); |
8418 |
||
8419 |
if ( $annotation ) {
|
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8420 |
if ( $display ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8421 |
echo $before . $annotation . $after; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8422 |
} else {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8423 |
return $before . $annotation . $after; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8424 |
} |
| 9 | 8425 |
} |
8426 |
} |
|
8427 |
||
8428 |
/** |
|
8429 |
* Returns the default annotation for the web hosting altering the "Update PHP" page URL. |
|
8430 |
* |
|
8431 |
* This function is to be used after {@see wp_get_update_php_url()} to return a consistent
|
|
8432 |
* annotation if the web host has altered the default "Update PHP" page URL. |
|
8433 |
* |
|
8434 |
* @since 5.2.0 |
|
8435 |
* |
|
| 16 | 8436 |
* @return string Update PHP page annotation. An empty string if no custom URLs are provided. |
| 9 | 8437 |
*/ |
8438 |
function wp_get_update_php_annotation() {
|
|
8439 |
$update_url = wp_get_update_php_url(); |
|
8440 |
$default_url = wp_get_default_update_php_url(); |
|
8441 |
||
8442 |
if ( $update_url === $default_url ) {
|
|
8443 |
return ''; |
|
8444 |
} |
|
8445 |
||
8446 |
$annotation = sprintf( |
|
| 16 | 8447 |
/* translators: %s: Default Update PHP page URL. */ |
| 9 | 8448 |
__( 'This resource is provided by your web host, and is specific to your site. For more information, <a href="%s" target="_blank">see the official WordPress documentation</a>.' ), |
8449 |
esc_url( $default_url ) |
|
8450 |
); |
|
8451 |
||
8452 |
return $annotation; |
|
8453 |
} |
|
8454 |
||
8455 |
/** |
|
8456 |
* Gets the URL for directly updating the PHP version the site is running on. |
|
8457 |
* |
|
8458 |
* A URL will only be returned if the `WP_DIRECT_UPDATE_PHP_URL` environment variable is specified or |
|
8459 |
* by using the {@see 'wp_direct_php_update_url'} filter. This allows hosts to send users directly to
|
|
8460 |
* the page where they can update PHP to a newer version. |
|
8461 |
* |
|
8462 |
* @since 5.1.1 |
|
8463 |
* |
|
8464 |
* @return string URL for directly updating PHP or empty string. |
|
8465 |
*/ |
|
8466 |
function wp_get_direct_php_update_url() {
|
|
8467 |
$direct_update_url = ''; |
|
8468 |
||
8469 |
if ( false !== getenv( 'WP_DIRECT_UPDATE_PHP_URL' ) ) {
|
|
8470 |
$direct_update_url = getenv( 'WP_DIRECT_UPDATE_PHP_URL' ); |
|
8471 |
} |
|
8472 |
||
8473 |
/** |
|
8474 |
* Filters the URL for directly updating the PHP version the site is running on from the host. |
|
8475 |
* |
|
8476 |
* @since 5.1.1 |
|
8477 |
* |
|
8478 |
* @param string $direct_update_url URL for directly updating PHP. |
|
8479 |
*/ |
|
8480 |
$direct_update_url = apply_filters( 'wp_direct_php_update_url', $direct_update_url ); |
|
8481 |
||
8482 |
return $direct_update_url; |
|
8483 |
} |
|
8484 |
||
8485 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8486 |
* Displays a button directly linking to a PHP update process. |
| 9 | 8487 |
* |
8488 |
* This provides hosts with a way for users to be sent directly to their PHP update process. |
|
8489 |
* |
|
8490 |
* The button is only displayed if a URL is returned by `wp_get_direct_php_update_url()`. |
|
8491 |
* |
|
8492 |
* @since 5.1.1 |
|
8493 |
*/ |
|
8494 |
function wp_direct_php_update_button() {
|
|
8495 |
$direct_update_url = wp_get_direct_php_update_url(); |
|
8496 |
||
8497 |
if ( empty( $direct_update_url ) ) {
|
|
8498 |
return; |
|
8499 |
} |
|
8500 |
||
8501 |
echo '<p class="button-container">'; |
|
8502 |
printf( |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8503 |
'<a class="button button-primary" href="%1$s" target="_blank" rel="noopener">%2$s<span class="screen-reader-text"> %3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>', |
| 9 | 8504 |
esc_url( $direct_update_url ), |
8505 |
__( 'Update PHP' ), |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8506 |
/* translators: Hidden accessibility text. */ |
| 9 | 8507 |
__( '(opens in a new tab)' ) |
8508 |
); |
|
8509 |
echo '</p>'; |
|
8510 |
} |
|
8511 |
||
8512 |
/** |
|
| 18 | 8513 |
* Gets the URL to learn more about updating the site to use HTTPS. |
8514 |
* |
|
8515 |
* This URL can be overridden by specifying an environment variable `WP_UPDATE_HTTPS_URL` or by using the |
|
8516 |
* {@see 'wp_update_https_url'} filter. Providing an empty string is not allowed and will result in the
|
|
8517 |
* default URL being used. Furthermore the page the URL links to should preferably be localized in the |
|
8518 |
* site language. |
|
8519 |
* |
|
8520 |
* @since 5.7.0 |
|
8521 |
* |
|
8522 |
* @return string URL to learn more about updating to HTTPS. |
|
8523 |
*/ |
|
8524 |
function wp_get_update_https_url() {
|
|
8525 |
$default_url = wp_get_default_update_https_url(); |
|
8526 |
||
8527 |
$update_url = $default_url; |
|
8528 |
if ( false !== getenv( 'WP_UPDATE_HTTPS_URL' ) ) {
|
|
8529 |
$update_url = getenv( 'WP_UPDATE_HTTPS_URL' ); |
|
8530 |
} |
|
8531 |
||
8532 |
/** |
|
8533 |
* Filters the URL to learn more about updating the HTTPS version the site is running on. |
|
8534 |
* |
|
8535 |
* Providing an empty string is not allowed and will result in the default URL being used. Furthermore |
|
8536 |
* the page the URL links to should preferably be localized in the site language. |
|
8537 |
* |
|
8538 |
* @since 5.7.0 |
|
8539 |
* |
|
8540 |
* @param string $update_url URL to learn more about updating HTTPS. |
|
8541 |
*/ |
|
8542 |
$update_url = apply_filters( 'wp_update_https_url', $update_url ); |
|
8543 |
if ( empty( $update_url ) ) {
|
|
8544 |
$update_url = $default_url; |
|
8545 |
} |
|
8546 |
||
8547 |
return $update_url; |
|
8548 |
} |
|
8549 |
||
8550 |
/** |
|
8551 |
* Gets the default URL to learn more about updating the site to use HTTPS. |
|
8552 |
* |
|
8553 |
* Do not use this function to retrieve this URL. Instead, use {@see wp_get_update_https_url()} when relying on the URL.
|
|
8554 |
* This function does not allow modifying the returned URL, and is only used to compare the actually used URL with the |
|
8555 |
* default one. |
|
8556 |
* |
|
8557 |
* @since 5.7.0 |
|
8558 |
* @access private |
|
8559 |
* |
|
8560 |
* @return string Default URL to learn more about updating to HTTPS. |
|
8561 |
*/ |
|
8562 |
function wp_get_default_update_https_url() {
|
|
8563 |
/* translators: Documentation explaining HTTPS and why it should be used. */ |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8564 |
return __( 'https://developer.wordpress.org/advanced-administration/security/https/' ); |
| 18 | 8565 |
} |
8566 |
||
8567 |
/** |
|
8568 |
* Gets the URL for directly updating the site to use HTTPS. |
|
8569 |
* |
|
8570 |
* A URL will only be returned if the `WP_DIRECT_UPDATE_HTTPS_URL` environment variable is specified or |
|
8571 |
* by using the {@see 'wp_direct_update_https_url'} filter. This allows hosts to send users directly to
|
|
8572 |
* the page where they can update their site to use HTTPS. |
|
8573 |
* |
|
8574 |
* @since 5.7.0 |
|
8575 |
* |
|
8576 |
* @return string URL for directly updating to HTTPS or empty string. |
|
8577 |
*/ |
|
8578 |
function wp_get_direct_update_https_url() {
|
|
8579 |
$direct_update_url = ''; |
|
8580 |
||
8581 |
if ( false !== getenv( 'WP_DIRECT_UPDATE_HTTPS_URL' ) ) {
|
|
8582 |
$direct_update_url = getenv( 'WP_DIRECT_UPDATE_HTTPS_URL' ); |
|
8583 |
} |
|
8584 |
||
8585 |
/** |
|
8586 |
* Filters the URL for directly updating the PHP version the site is running on from the host. |
|
8587 |
* |
|
8588 |
* @since 5.7.0 |
|
8589 |
* |
|
8590 |
* @param string $direct_update_url URL for directly updating PHP. |
|
8591 |
*/ |
|
8592 |
$direct_update_url = apply_filters( 'wp_direct_update_https_url', $direct_update_url ); |
|
8593 |
||
8594 |
return $direct_update_url; |
|
8595 |
} |
|
8596 |
||
8597 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8598 |
* Gets the size of a directory. |
| 9 | 8599 |
* |
8600 |
* A helper function that is used primarily to check whether |
|
8601 |
* a blog has exceeded its allowed upload space. |
|
8602 |
* |
|
8603 |
* @since MU (3.0.0) |
|
8604 |
* @since 5.2.0 $max_execution_time parameter added. |
|
8605 |
* |
|
8606 |
* @param string $directory Full path of a directory. |
|
8607 |
* @param int $max_execution_time Maximum time to run before giving up. In seconds. |
|
8608 |
* The timeout is global and is measured from the moment WordPress started to load. |
|
8609 |
* @return int|false|null Size in bytes if a valid directory. False if not. Null if timeout. |
|
8610 |
*/ |
|
8611 |
function get_dirsize( $directory, $max_execution_time = null ) {
|
|
8612 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8613 |
/* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8614 |
* Exclude individual site directories from the total when checking the main site of a network, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8615 |
* as they are subdirectories and should not be counted. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8616 |
*/ |
| 9 | 8617 |
if ( is_multisite() && is_main_site() ) {
|
| 18 | 8618 |
$size = recurse_dirsize( $directory, $directory . '/sites', $max_execution_time ); |
| 9 | 8619 |
} else {
|
| 18 | 8620 |
$size = recurse_dirsize( $directory, null, $max_execution_time ); |
8621 |
} |
|
8622 |
||
8623 |
return $size; |
|
| 9 | 8624 |
} |
8625 |
||
8626 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8627 |
* Gets the size of a directory recursively. |
| 9 | 8628 |
* |
| 18 | 8629 |
* Used by get_dirsize() to get a directory size when it contains other directories. |
| 9 | 8630 |
* |
8631 |
* @since MU (3.0.0) |
|
| 18 | 8632 |
* @since 4.3.0 The `$exclude` parameter was added. |
8633 |
* @since 5.2.0 The `$max_execution_time` parameter was added. |
|
8634 |
* @since 5.6.0 The `$directory_cache` parameter was added. |
|
| 9 | 8635 |
* |
| 19 | 8636 |
* @param string $directory Full path of a directory. |
8637 |
* @param string|string[] $exclude Optional. Full path of a subdirectory to exclude from the total, |
|
8638 |
* or array of paths. Expected without trailing slash(es). |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8639 |
* Default null. |
| 19 | 8640 |
* @param int $max_execution_time Optional. Maximum time to run before giving up. In seconds. |
8641 |
* The timeout is global and is measured from the moment |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8642 |
* WordPress started to load. Defaults to the value of |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8643 |
* `max_execution_time` PHP setting. |
| 19 | 8644 |
* @param array $directory_cache Optional. Array of cached directory paths. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8645 |
* Defaults to the value of `dirsize_cache` transient. |
| 9 | 8646 |
* @return int|false|null Size in bytes if a valid directory. False if not. Null if timeout. |
8647 |
*/ |
|
| 18 | 8648 |
function recurse_dirsize( $directory, $exclude = null, $max_execution_time = null, &$directory_cache = null ) {
|
8649 |
$directory = untrailingslashit( $directory ); |
|
8650 |
$save_cache = false; |
|
8651 |
||
8652 |
if ( ! isset( $directory_cache ) ) {
|
|
8653 |
$directory_cache = get_transient( 'dirsize_cache' ); |
|
8654 |
$save_cache = true; |
|
8655 |
} |
|
8656 |
||
8657 |
if ( isset( $directory_cache[ $directory ] ) && is_int( $directory_cache[ $directory ] ) ) {
|
|
8658 |
return $directory_cache[ $directory ]; |
|
8659 |
} |
|
| 9 | 8660 |
|
8661 |
if ( ! file_exists( $directory ) || ! is_dir( $directory ) || ! is_readable( $directory ) ) {
|
|
8662 |
return false; |
|
8663 |
} |
|
8664 |
||
8665 |
if ( |
|
8666 |
( is_string( $exclude ) && $directory === $exclude ) || |
|
8667 |
( is_array( $exclude ) && in_array( $directory, $exclude, true ) ) |
|
8668 |
) {
|
|
8669 |
return false; |
|
8670 |
} |
|
8671 |
||
| 16 | 8672 |
if ( null === $max_execution_time ) {
|
| 9 | 8673 |
// Keep the previous behavior but attempt to prevent fatal errors from timeout if possible. |
8674 |
if ( function_exists( 'ini_get' ) ) {
|
|
8675 |
$max_execution_time = ini_get( 'max_execution_time' ); |
|
8676 |
} else {
|
|
8677 |
// Disable... |
|
8678 |
$max_execution_time = 0; |
|
8679 |
} |
|
8680 |
||
8681 |
// Leave 1 second "buffer" for other operations if $max_execution_time has reasonable value. |
|
8682 |
if ( $max_execution_time > 10 ) {
|
|
8683 |
$max_execution_time -= 1; |
|
8684 |
} |
|
8685 |
} |
|
8686 |
||
| 18 | 8687 |
/** |
8688 |
* Filters the amount of storage space used by one directory and all its children, in megabytes. |
|
8689 |
* |
|
8690 |
* Return the actual used space to short-circuit the recursive PHP file size calculation |
|
8691 |
* and use something else, like a CDN API or native operating system tools for better performance. |
|
8692 |
* |
|
8693 |
* @since 5.6.0 |
|
8694 |
* |
|
| 19 | 8695 |
* @param int|false $space_used The amount of used space, in bytes. Default false. |
8696 |
* @param string $directory Full path of a directory. |
|
8697 |
* @param string|string[]|null $exclude Full path of a subdirectory to exclude from the total, |
|
8698 |
* or array of paths. |
|
8699 |
* @param int $max_execution_time Maximum time to run before giving up. In seconds. |
|
8700 |
* @param array $directory_cache Array of cached directory paths. |
|
| 18 | 8701 |
*/ |
8702 |
$size = apply_filters( 'pre_recurse_dirsize', false, $directory, $exclude, $max_execution_time, $directory_cache ); |
|
8703 |
||
8704 |
if ( false === $size ) {
|
|
8705 |
$size = 0; |
|
8706 |
||
8707 |
$handle = opendir( $directory ); |
|
8708 |
if ( $handle ) {
|
|
8709 |
while ( ( $file = readdir( $handle ) ) !== false ) {
|
|
8710 |
$path = $directory . '/' . $file; |
|
8711 |
if ( '.' !== $file && '..' !== $file ) {
|
|
8712 |
if ( is_file( $path ) ) {
|
|
8713 |
$size += filesize( $path ); |
|
8714 |
} elseif ( is_dir( $path ) ) {
|
|
8715 |
$handlesize = recurse_dirsize( $path, $exclude, $max_execution_time, $directory_cache ); |
|
8716 |
if ( $handlesize > 0 ) {
|
|
8717 |
$size += $handlesize; |
|
8718 |
} |
|
8719 |
} |
|
8720 |
||
| 19 | 8721 |
if ( $max_execution_time > 0 && |
8722 |
( microtime( true ) - WP_START_TIMESTAMP ) > $max_execution_time |
|
8723 |
) {
|
|
| 18 | 8724 |
// Time exceeded. Give up instead of risking a fatal timeout. |
8725 |
$size = null; |
|
8726 |
break; |
|
| 9 | 8727 |
} |
8728 |
} |
|
8729 |
} |
|
| 18 | 8730 |
closedir( $handle ); |
8731 |
} |
|
8732 |
} |
|
8733 |
||
| 19 | 8734 |
if ( ! is_array( $directory_cache ) ) {
|
8735 |
$directory_cache = array(); |
|
8736 |
} |
|
8737 |
||
| 18 | 8738 |
$directory_cache[ $directory ] = $size; |
8739 |
||
8740 |
// Only write the transient on the top level call and not on recursive calls. |
|
8741 |
if ( $save_cache ) {
|
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8742 |
$expiration = ( wp_using_ext_object_cache() ) ? 0 : 10 * YEAR_IN_SECONDS; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8743 |
set_transient( 'dirsize_cache', $directory_cache, $expiration ); |
| 18 | 8744 |
} |
8745 |
||
| 9 | 8746 |
return $size; |
8747 |
} |
|
8748 |
||
8749 |
/** |
|
| 18 | 8750 |
* Cleans directory size cache used by recurse_dirsize(). |
8751 |
* |
|
8752 |
* Removes the current directory and all parent directories from the `dirsize_cache` transient. |
|
8753 |
* |
|
8754 |
* @since 5.6.0 |
|
| 19 | 8755 |
* @since 5.9.0 Added input validation with a notice for invalid input. |
| 18 | 8756 |
* |
8757 |
* @param string $path Full path of a directory or file. |
|
8758 |
*/ |
|
8759 |
function clean_dirsize_cache( $path ) {
|
|
| 19 | 8760 |
if ( ! is_string( $path ) || empty( $path ) ) {
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8761 |
wp_trigger_error( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8762 |
'', |
| 19 | 8763 |
sprintf( |
8764 |
/* translators: 1: Function name, 2: A variable type, like "boolean" or "integer". */ |
|
8765 |
__( '%1$s only accepts a non-empty path string, received %2$s.' ), |
|
8766 |
'<code>clean_dirsize_cache()</code>', |
|
8767 |
'<code>' . gettype( $path ) . '</code>' |
|
8768 |
) |
|
8769 |
); |
|
8770 |
return; |
|
8771 |
} |
|
8772 |
||
| 18 | 8773 |
$directory_cache = get_transient( 'dirsize_cache' ); |
8774 |
||
8775 |
if ( empty( $directory_cache ) ) {
|
|
8776 |
return; |
|
8777 |
} |
|
8778 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8779 |
$expiration = ( wp_using_ext_object_cache() ) ? 0 : 10 * YEAR_IN_SECONDS; |
| 19 | 8780 |
if ( |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8781 |
! str_contains( $path, '/' ) && |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8782 |
! str_contains( $path, '\\' ) |
| 19 | 8783 |
) {
|
8784 |
unset( $directory_cache[ $path ] ); |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8785 |
set_transient( 'dirsize_cache', $directory_cache, $expiration ); |
| 19 | 8786 |
return; |
8787 |
} |
|
8788 |
||
8789 |
$last_path = null; |
|
8790 |
$path = untrailingslashit( $path ); |
|
| 18 | 8791 |
unset( $directory_cache[ $path ] ); |
8792 |
||
| 19 | 8793 |
while ( |
8794 |
$last_path !== $path && |
|
8795 |
DIRECTORY_SEPARATOR !== $path && |
|
8796 |
'.' !== $path && |
|
8797 |
'..' !== $path |
|
8798 |
) {
|
|
8799 |
$last_path = $path; |
|
8800 |
$path = dirname( $path ); |
|
| 18 | 8801 |
unset( $directory_cache[ $path ] ); |
8802 |
} |
|
8803 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8804 |
set_transient( 'dirsize_cache', $directory_cache, $expiration ); |
| 18 | 8805 |
} |
8806 |
||
8807 |
/** |
|
| 16 | 8808 |
* Checks compatibility with the current WordPress version. |
8809 |
* |
|
8810 |
* @since 5.2.0 |
|
8811 |
* |
|
| 19 | 8812 |
* @global string $wp_version The WordPress version string. |
8813 |
* |
|
| 16 | 8814 |
* @param string $required Minimum required WordPress version. |
8815 |
* @return bool True if required version is compatible or empty, false if not. |
|
8816 |
*/ |
|
| 9 | 8817 |
function is_wp_version_compatible( $required ) {
|
| 19 | 8818 |
global $wp_version; |
8819 |
||
8820 |
// Strip off any -alpha, -RC, -beta, -src suffixes. |
|
8821 |
list( $version ) = explode( '-', $wp_version ); |
|
8822 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8823 |
if ( is_string( $required ) ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8824 |
$trimmed = trim( $required ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8825 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8826 |
if ( substr_count( $trimmed, '.' ) > 1 && str_ends_with( $trimmed, '.0' ) ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8827 |
$required = substr( $trimmed, 0, -2 ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8828 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8829 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8830 |
|
| 19 | 8831 |
return empty( $required ) || version_compare( $version, $required, '>=' ); |
| 9 | 8832 |
} |
8833 |
||
8834 |
/** |
|
8835 |
* Checks compatibility with the current PHP version. |
|
8836 |
* |
|
8837 |
* @since 5.2.0 |
|
8838 |
* |
|
8839 |
* @param string $required Minimum required PHP version. |
|
8840 |
* @return bool True if required version is compatible or empty, false if not. |
|
8841 |
*/ |
|
8842 |
function is_php_version_compatible( $required ) {
|
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8843 |
return empty( $required ) || version_compare( PHP_VERSION, $required, '>=' ); |
| 9 | 8844 |
} |
| 16 | 8845 |
|
8846 |
/** |
|
| 19 | 8847 |
* Checks if two numbers are nearly the same. |
| 16 | 8848 |
* |
8849 |
* This is similar to using `round()` but the precision is more fine-grained. |
|
8850 |
* |
|
8851 |
* @since 5.3.0 |
|
8852 |
* |
|
8853 |
* @param int|float $expected The expected value. |
|
8854 |
* @param int|float $actual The actual number. |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8855 |
* @param int|float $precision Optional. The allowed variation. Default 1. |
| 19 | 8856 |
* @return bool Whether the numbers match within the specified precision. |
| 16 | 8857 |
*/ |
8858 |
function wp_fuzzy_number_match( $expected, $actual, $precision = 1 ) {
|
|
8859 |
return abs( (float) $expected - (float) $actual ) <= $precision; |
|
8860 |
} |
|
| 19 | 8861 |
|
8862 |
/** |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8863 |
* Creates and returns the markup for an admin notice. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8864 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8865 |
* @since 6.4.0 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8866 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8867 |
* @param string $message The message. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8868 |
* @param array $args {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8869 |
* Optional. An array of arguments for the admin notice. Default empty array. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8870 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8871 |
* @type string $type Optional. The type of admin notice. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8872 |
* For example, 'error', 'success', 'warning', 'info'. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8873 |
* Default empty string. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8874 |
* @type bool $dismissible Optional. Whether the admin notice is dismissible. Default false. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8875 |
* @type string $id Optional. The value of the admin notice's ID attribute. Default empty string. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8876 |
* @type string[] $additional_classes Optional. A string array of class names. Default empty array. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8877 |
* @type string[] $attributes Optional. Additional attributes for the notice div. Default empty array. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8878 |
* @type bool $paragraph_wrap Optional. Whether to wrap the message in paragraph tags. Default true. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8879 |
* } |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8880 |
* @return string The markup for an admin notice. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8881 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8882 |
function wp_get_admin_notice( $message, $args = array() ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8883 |
$defaults = array( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8884 |
'type' => '', |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8885 |
'dismissible' => false, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8886 |
'id' => '', |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8887 |
'additional_classes' => array(), |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8888 |
'attributes' => array(), |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8889 |
'paragraph_wrap' => true, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8890 |
); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8891 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8892 |
$args = wp_parse_args( $args, $defaults ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8893 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8894 |
/** |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8895 |
* Filters the arguments for an admin notice. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8896 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8897 |
* @since 6.4.0 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8898 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8899 |
* @param array $args The arguments for the admin notice. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8900 |
* @param string $message The message for the admin notice. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8901 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8902 |
$args = apply_filters( 'wp_admin_notice_args', $args, $message ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8903 |
$id = ''; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8904 |
$classes = 'notice'; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8905 |
$attributes = ''; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8906 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8907 |
if ( is_string( $args['id'] ) ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8908 |
$trimmed_id = trim( $args['id'] ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8909 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8910 |
if ( '' !== $trimmed_id ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8911 |
$id = 'id="' . $trimmed_id . '" '; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8912 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8913 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8914 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8915 |
if ( is_string( $args['type'] ) ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8916 |
$type = trim( $args['type'] ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8917 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8918 |
if ( str_contains( $type, ' ' ) ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8919 |
_doing_it_wrong( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8920 |
__FUNCTION__, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8921 |
sprintf( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8922 |
/* translators: %s: The "type" key. */ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8923 |
__( 'The %s key must be a string without spaces.' ), |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8924 |
'<code>type</code>' |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8925 |
), |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8926 |
'6.4.0' |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8927 |
); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8928 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8929 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8930 |
if ( '' !== $type ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8931 |
$classes .= ' notice-' . $type; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8932 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8933 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8934 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8935 |
if ( true === $args['dismissible'] ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8936 |
$classes .= ' is-dismissible'; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8937 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8938 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8939 |
if ( is_array( $args['additional_classes'] ) && ! empty( $args['additional_classes'] ) ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8940 |
$classes .= ' ' . implode( ' ', $args['additional_classes'] ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8941 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8942 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8943 |
if ( is_array( $args['attributes'] ) && ! empty( $args['attributes'] ) ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8944 |
$attributes = ''; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8945 |
foreach ( $args['attributes'] as $attr => $val ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8946 |
if ( is_bool( $val ) ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8947 |
$attributes .= $val ? ' ' . $attr : ''; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8948 |
} elseif ( is_int( $attr ) ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8949 |
$attributes .= ' ' . esc_attr( trim( $val ) ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8950 |
} elseif ( $val ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8951 |
$attributes .= ' ' . $attr . '="' . esc_attr( trim( $val ) ) . '"'; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8952 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8953 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8954 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8955 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8956 |
if ( false !== $args['paragraph_wrap'] ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8957 |
$message = "<p>$message</p>"; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8958 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8959 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8960 |
$markup = sprintf( '<div %1$sclass="%2$s"%3$s>%4$s</div>', $id, $classes, $attributes, $message ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8961 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8962 |
/** |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8963 |
* Filters the markup for an admin notice. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8964 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8965 |
* @since 6.4.0 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8966 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8967 |
* @param string $markup The HTML markup for the admin notice. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8968 |
* @param string $message The message for the admin notice. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8969 |
* @param array $args The arguments for the admin notice. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8970 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8971 |
return apply_filters( 'wp_admin_notice_markup', $markup, $message, $args ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8972 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8973 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8974 |
/** |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8975 |
* Outputs an admin notice. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8976 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8977 |
* @since 6.4.0 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8978 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8979 |
* @param string $message The message to output. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8980 |
* @param array $args {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8981 |
* Optional. An array of arguments for the admin notice. Default empty array. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8982 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8983 |
* @type string $type Optional. The type of admin notice. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8984 |
* For example, 'error', 'success', 'warning', 'info'. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8985 |
* Default empty string. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8986 |
* @type bool $dismissible Optional. Whether the admin notice is dismissible. Default false. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8987 |
* @type string $id Optional. The value of the admin notice's ID attribute. Default empty string. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8988 |
* @type string[] $additional_classes Optional. A string array of class names. Default empty array. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8989 |
* @type string[] $attributes Optional. Additional attributes for the notice div. Default empty array. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8990 |
* @type bool $paragraph_wrap Optional. Whether to wrap the message in paragraph tags. Default true. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8991 |
* } |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8992 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8993 |
function wp_admin_notice( $message, $args = array() ) {
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8994 |
/** |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8995 |
* Fires before an admin notice is output. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8996 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8997 |
* @since 6.4.0 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8998 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8999 |
* @param string $message The message for the admin notice. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
9000 |
* @param array $args The arguments for the admin notice. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
9001 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
9002 |
do_action( 'wp_admin_notice', $message, $args ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
9003 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
9004 |
echo wp_kses_post( wp_get_admin_notice( $message, $args ) ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
9005 |
} |