44 /** |
44 /** |
45 * Retrieve the current time based on specified type. |
45 * Retrieve the current time based on specified type. |
46 * |
46 * |
47 * The 'mysql' type will return the time in the format for MySQL DATETIME field. |
47 * The 'mysql' type will return the time in the format for MySQL DATETIME field. |
48 * The 'timestamp' type will return the current timestamp. |
48 * The 'timestamp' type will return the current timestamp. |
|
49 * Other strings will be interpreted as PHP date formats (e.g. 'Y-m-d'). |
49 * |
50 * |
50 * If $gmt is set to either '1' or 'true', then both types will use GMT time. |
51 * If $gmt is set to either '1' or 'true', then both types will use GMT time. |
51 * if $gmt is false, the output is adjusted with the GMT offset in the WordPress option. |
52 * if $gmt is false, the output is adjusted with the GMT offset in the WordPress option. |
52 * |
53 * |
53 * @since 1.0.0 |
54 * @since 1.0.0 |
54 * |
55 * |
55 * @param string $type Either 'mysql' or 'timestamp'. |
56 * @param string $type Type of time to retrieve. Accepts 'mysql', 'timestamp', or PHP date |
56 * @param int|bool $gmt Optional. Whether to use GMT timezone. Default is false. |
57 * format string (e.g. 'Y-m-d'). |
57 * @return int|string String if $type is 'gmt', int if $type is 'timestamp'. |
58 * @param int|bool $gmt Optional. Whether to use GMT timezone. Default false. |
|
59 * @return int|string Integer if $type is 'timestamp', string otherwise. |
58 */ |
60 */ |
59 function current_time( $type, $gmt = 0 ) { |
61 function current_time( $type, $gmt = 0 ) { |
60 switch ( $type ) { |
62 switch ( $type ) { |
61 case 'mysql': |
63 case 'mysql': |
62 return ( $gmt ) ? gmdate( 'Y-m-d H:i:s' ) : gmdate( 'Y-m-d H:i:s', ( time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ) ); |
64 return ( $gmt ) ? gmdate( 'Y-m-d H:i:s' ) : gmdate( 'Y-m-d H:i:s', ( time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ) ); |
63 break; |
|
64 case 'timestamp': |
65 case 'timestamp': |
65 return ( $gmt ) ? time() : time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); |
66 return ( $gmt ) ? time() : time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); |
66 break; |
67 default: |
|
68 return ( $gmt ) ? date( $type ) : date( $type, time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ); |
67 } |
69 } |
68 } |
70 } |
69 |
71 |
70 /** |
72 /** |
71 * Retrieve the date in localized format, based on timestamp. |
73 * Retrieve the date in localized format, based on timestamp. |
134 } |
139 } |
135 } |
140 } |
136 } |
141 } |
137 } |
142 } |
138 $j = @$datefunc( $dateformatstring, $i ); |
143 $j = @$datefunc( $dateformatstring, $i ); |
139 // allow plugins to redo this entirely for languages with untypical grammars |
144 |
140 $j = apply_filters('date_i18n', $j, $req_format, $i, $gmt); |
145 /** |
|
146 * Filter the date formatted based on the locale. |
|
147 * |
|
148 * @since 2.8.0 |
|
149 * |
|
150 * @param string $j Formatted date string. |
|
151 * @param string $req_format Format to display the date. |
|
152 * @param int $i Unix timestamp. |
|
153 * @param bool $gmt Whether to convert to GMT for time. Default false. |
|
154 */ |
|
155 $j = apply_filters( 'date_i18n', $j, $req_format, $i, $gmt ); |
141 return $j; |
156 return $j; |
142 } |
157 } |
143 |
158 |
144 /** |
159 /** |
145 * Convert integer number to format based on the locale. |
160 * Convert integer number to format based on the locale. |
146 * |
161 * |
147 * @since 2.3.0 |
162 * @since 2.3.0 |
148 * |
163 * |
149 * @param int $number The number to convert based on locale. |
164 * @param int $number The number to convert based on locale. |
150 * @param int $decimals Precision of the number of decimal places. |
165 * @param int $decimals Optional. Precision of the number of decimal places. Default 0. |
151 * @return string Converted number in string format. |
166 * @return string Converted number in string format. |
152 */ |
167 */ |
153 function number_format_i18n( $number, $decimals = 0 ) { |
168 function number_format_i18n( $number, $decimals = 0 ) { |
154 global $wp_locale; |
169 global $wp_locale; |
155 $formatted = number_format( $number, absint( $decimals ), $wp_locale->number_format['decimal_point'], $wp_locale->number_format['thousands_sep'] ); |
170 $formatted = number_format( $number, absint( $decimals ), $wp_locale->number_format['decimal_point'], $wp_locale->number_format['thousands_sep'] ); |
|
171 |
|
172 /** |
|
173 * Filter the number formatted based on the locale. |
|
174 * |
|
175 * @since 2.8.0 |
|
176 * |
|
177 * @param string $formatted Converted number in string format. |
|
178 */ |
156 return apply_filters( 'number_format_i18n', $formatted ); |
179 return apply_filters( 'number_format_i18n', $formatted ); |
157 } |
180 } |
158 |
181 |
159 /** |
182 /** |
160 * Convert number of bytes largest unit bytes will fit into. |
183 * Convert number of bytes largest unit bytes will fit into. |
161 * |
184 * |
162 * It is easier to read 1kB than 1024 bytes and 1MB than 1048576 bytes. Converts |
185 * It is easier to read 1 kB than 1024 bytes and 1 MB than 1048576 bytes. Converts |
163 * number of bytes to human readable number by taking the number of that unit |
186 * number of bytes to human readable number by taking the number of that unit |
164 * that the bytes will go into it. Supports TB value. |
187 * that the bytes will go into it. Supports TB value. |
165 * |
188 * |
166 * Please note that integers in PHP are limited to 32 bits, unless they are on |
189 * Please note that integers in PHP are limited to 32 bits, unless they are on |
167 * 64 bit architecture, then they have 64 bit size. If you need to place the |
190 * 64 bit architecture, then they have 64 bit size. If you need to place the |
168 * larger size then what PHP integer type will hold, then use a string. It will |
191 * larger size then what PHP integer type will hold, then use a string. It will |
169 * be converted to a double, which should always have 64 bit length. |
192 * be converted to a double, which should always have 64 bit length. |
170 * |
193 * |
171 * Technically the correct unit names for powers of 1024 are KiB, MiB etc. |
194 * Technically the correct unit names for powers of 1024 are KiB, MiB etc. |
172 * @link http://en.wikipedia.org/wiki/Byte |
|
173 * |
195 * |
174 * @since 2.3.0 |
196 * @since 2.3.0 |
175 * |
197 * |
176 * @param int|string $bytes Number of bytes. Note max integer size for integers. |
198 * @param int|string $bytes Number of bytes. Note max integer size for integers. |
177 * @param int $decimals Precision of number of decimal places. Deprecated. |
199 * @param int $decimals Optional. Precision of number of decimal places. Default 0. |
178 * @return bool|string False on failure. Number string on success. |
200 * @return string|false False on failure. Number string on success. |
179 */ |
201 */ |
180 function size_format( $bytes, $decimals = 0 ) { |
202 function size_format( $bytes, $decimals = 0 ) { |
181 $quant = array( |
203 $quant = array( |
182 // ========================= Origin ==== |
204 // ========================= Origin ==== |
183 'TB' => 1099511627776, // pow( 1024, 4) |
205 'TB' => 1099511627776, // pow( 1024, 4) |
184 'GB' => 1073741824, // pow( 1024, 3) |
206 'GB' => 1073741824, // pow( 1024, 3) |
185 'MB' => 1048576, // pow( 1024, 2) |
207 'MB' => 1048576, // pow( 1024, 2) |
186 'kB' => 1024, // pow( 1024, 1) |
208 'kB' => 1024, // pow( 1024, 1) |
187 'B ' => 1, // pow( 1024, 0) |
209 'B' => 1, // pow( 1024, 0) |
188 ); |
210 ); |
189 foreach ( $quant as $unit => $mag ) |
211 |
190 if ( doubleval($bytes) >= $mag ) |
212 foreach ( $quant as $unit => $mag ) { |
|
213 if ( doubleval( $bytes ) >= $mag ) { |
191 return number_format_i18n( $bytes / $mag, $decimals ) . ' ' . $unit; |
214 return number_format_i18n( $bytes / $mag, $decimals ) . ' ' . $unit; |
|
215 } |
|
216 } |
192 |
217 |
193 return false; |
218 return false; |
194 } |
219 } |
195 |
220 |
196 /** |
221 /** |
197 * Get the week start and end from the datetime or date string from mysql. |
222 * Get the week start and end from the datetime or date string from MySQL. |
198 * |
223 * |
199 * @since 0.71 |
224 * @since 0.71 |
200 * |
225 * |
201 * @param string $mysqlstring Date or datetime field type from mysql. |
226 * @param string $mysqlstring Date or datetime field type from MySQL. |
202 * @param int $start_of_week Optional. Start of the week as an integer. |
227 * @param int|string $start_of_week Optional. Start of the week as an integer. Default empty string. |
203 * @return array Keys are 'start' and 'end'. |
228 * @return array Keys are 'start' and 'end'. |
204 */ |
229 */ |
205 function get_weekstartend( $mysqlstring, $start_of_week = '' ) { |
230 function get_weekstartend( $mysqlstring, $start_of_week = '' ) { |
206 $my = substr( $mysqlstring, 0, 4 ); // Mysql string Year |
231 // MySQL string year. |
207 $mm = substr( $mysqlstring, 8, 2 ); // Mysql string Month |
232 $my = substr( $mysqlstring, 0, 4 ); |
208 $md = substr( $mysqlstring, 5, 2 ); // Mysql string day |
233 |
209 $day = mktime( 0, 0, 0, $md, $mm, $my ); // The timestamp for mysqlstring day. |
234 // MySQL string month. |
210 $weekday = date( 'w', $day ); // The day of the week from the timestamp |
235 $mm = substr( $mysqlstring, 8, 2 ); |
|
236 |
|
237 // MySQL string day. |
|
238 $md = substr( $mysqlstring, 5, 2 ); |
|
239 |
|
240 // The timestamp for MySQL string day. |
|
241 $day = mktime( 0, 0, 0, $md, $mm, $my ); |
|
242 |
|
243 // The day of the week from the timestamp. |
|
244 $weekday = date( 'w', $day ); |
|
245 |
211 if ( !is_numeric($start_of_week) ) |
246 if ( !is_numeric($start_of_week) ) |
212 $start_of_week = get_option( 'start_of_week' ); |
247 $start_of_week = get_option( 'start_of_week' ); |
213 |
248 |
214 if ( $weekday < $start_of_week ) |
249 if ( $weekday < $start_of_week ) |
215 $weekday += 7; |
250 $weekday += 7; |
216 |
251 |
217 $start = $day - DAY_IN_SECONDS * ( $weekday - $start_of_week ); // The most recent week start day on or before $day |
252 // The most recent week start day on or before $day. |
218 $end = $start + 7 * DAY_IN_SECONDS - 1; // $start + 7 days - 1 second |
253 $start = $day - DAY_IN_SECONDS * ( $weekday - $start_of_week ); |
|
254 |
|
255 // $start + 7 days - 1 second. |
|
256 $end = $start + 7 * DAY_IN_SECONDS - 1; |
219 return compact( 'start', 'end' ); |
257 return compact( 'start', 'end' ); |
220 } |
258 } |
221 |
259 |
222 /** |
260 /** |
223 * Unserialize value only if it was serialized. |
261 * Unserialize value only if it was serialized. |
239 * If $data is not an string, then returned value will always be false. |
277 * If $data is not an string, then returned value will always be false. |
240 * Serialized data is always a string. |
278 * Serialized data is always a string. |
241 * |
279 * |
242 * @since 2.0.5 |
280 * @since 2.0.5 |
243 * |
281 * |
244 * @param mixed $data Value to check to see if was serialized. |
282 * @param string $data Value to check to see if was serialized. |
245 * @param bool $strict Optional. Whether to be strict about the end of the string. Defaults true. |
283 * @param bool $strict Optional. Whether to be strict about the end of the string. Default true. |
246 * @return bool False if not serialized and true if it was. |
284 * @return bool False if not serialized and true if it was. |
247 */ |
285 */ |
248 function is_serialized( $data, $strict = true ) { |
286 function is_serialized( $data, $strict = true ) { |
249 // if it isn't a string, it isn't serialized |
287 // if it isn't a string, it isn't serialized. |
250 if ( ! is_string( $data ) ) |
288 if ( ! is_string( $data ) ) { |
251 return false; |
289 return false; |
|
290 } |
252 $data = trim( $data ); |
291 $data = trim( $data ); |
253 if ( 'N;' == $data ) |
292 if ( 'N;' == $data ) { |
254 return true; |
293 return true; |
255 $length = strlen( $data ); |
294 } |
256 if ( $length < 4 ) |
295 if ( strlen( $data ) < 4 ) { |
257 return false; |
296 return false; |
258 if ( ':' !== $data[1] ) |
297 } |
|
298 if ( ':' !== $data[1] ) { |
259 return false; |
299 return false; |
|
300 } |
260 if ( $strict ) { |
301 if ( $strict ) { |
261 $lastc = $data[ $length - 1 ]; |
302 $lastc = substr( $data, -1 ); |
262 if ( ';' !== $lastc && '}' !== $lastc ) |
303 if ( ';' !== $lastc && '}' !== $lastc ) { |
263 return false; |
304 return false; |
|
305 } |
264 } else { |
306 } else { |
265 $semicolon = strpos( $data, ';' ); |
307 $semicolon = strpos( $data, ';' ); |
266 $brace = strpos( $data, '}' ); |
308 $brace = strpos( $data, '}' ); |
267 // Either ; or } must exist. |
309 // Either ; or } must exist. |
268 if ( false === $semicolon && false === $brace ) |
310 if ( false === $semicolon && false === $brace ) |
298 /** |
341 /** |
299 * Check whether serialized data is of string type. |
342 * Check whether serialized data is of string type. |
300 * |
343 * |
301 * @since 2.0.5 |
344 * @since 2.0.5 |
302 * |
345 * |
303 * @param mixed $data Serialized data |
346 * @param string $data Serialized data. |
304 * @return bool False if not a serialized string, true if it is. |
347 * @return bool False if not a serialized string, true if it is. |
305 */ |
348 */ |
306 function is_serialized_string( $data ) { |
349 function is_serialized_string( $data ) { |
307 // if it isn't a string, it isn't a serialized string |
350 // if it isn't a string, it isn't a serialized string. |
308 if ( !is_string( $data ) ) |
351 if ( ! is_string( $data ) ) { |
309 return false; |
352 return false; |
|
353 } |
310 $data = trim( $data ); |
354 $data = trim( $data ); |
311 $length = strlen( $data ); |
355 if ( strlen( $data ) < 4 ) { |
312 if ( $length < 4 ) |
|
313 return false; |
356 return false; |
314 elseif ( ':' !== $data[1] ) |
357 } elseif ( ':' !== $data[1] ) { |
315 return false; |
358 return false; |
316 elseif ( ';' !== $data[$length-1] ) |
359 } elseif ( ';' !== substr( $data, -1 ) ) { |
317 return false; |
360 return false; |
318 elseif ( $data[0] !== 's' ) |
361 } elseif ( $data[0] !== 's' ) { |
319 return false; |
362 return false; |
320 elseif ( '"' !== $data[$length-2] ) |
363 } elseif ( '"' !== substr( $data, -2, 1 ) ) { |
321 return false; |
364 return false; |
322 else |
365 } else { |
323 return true; |
366 return true; |
|
367 } |
324 } |
368 } |
325 |
369 |
326 /** |
370 /** |
327 * Serialize data, if needed. |
371 * Serialize data, if needed. |
328 * |
372 * |
329 * @since 2.0.5 |
373 * @since 2.0.5 |
330 * |
374 * |
331 * @param mixed $data Data that might be serialized. |
375 * @param string|array|object $data Data that might be serialized. |
332 * @return mixed A scalar data |
376 * @return mixed A scalar data |
333 */ |
377 */ |
334 function maybe_serialize( $data ) { |
378 function maybe_serialize( $data ) { |
335 if ( is_array( $data ) || is_object( $data ) ) |
379 if ( is_array( $data ) || is_object( $data ) ) |
336 return serialize( $data ); |
380 return serialize( $data ); |
337 |
381 |
338 // Double serialization is required for backward compatibility. |
382 // Double serialization is required for backward compatibility. |
339 // See http://core.trac.wordpress.org/ticket/12930 |
383 // See https://core.trac.wordpress.org/ticket/12930 |
340 if ( is_serialized( $data, false ) ) |
384 if ( is_serialized( $data, false ) ) |
341 return serialize( $data ); |
385 return serialize( $data ); |
342 |
386 |
343 return $data; |
387 return $data; |
344 } |
388 } |
396 } |
436 } |
397 |
437 |
398 /** |
438 /** |
399 * XMLRPC XML content without title and category elements. |
439 * XMLRPC XML content without title and category elements. |
400 * |
440 * |
401 * @package WordPress |
|
402 * @subpackage XMLRPC |
|
403 * @since 0.71 |
441 * @since 0.71 |
404 * |
442 * |
405 * @param string $content XMLRPC XML Request content |
443 * @param string $content XML-RPC XML Request content. |
406 * @return string XMLRPC XML Request content without title and category elements. |
444 * @return string XMLRPC XML Request content without title and category elements. |
407 */ |
445 */ |
408 function xmlrpc_removepostdata( $content ) { |
446 function xmlrpc_removepostdata( $content ) { |
409 $content = preg_replace( '/<title>(.+?)<\/title>/si', '', $content ); |
447 $content = preg_replace( '/<title>(.+?)<\/title>/si', '', $content ); |
410 $content = preg_replace( '/<category>(.+?)<\/category>/si', '', $content ); |
448 $content = preg_replace( '/<category>(.+?)<\/category>/si', '', $content ); |
411 $content = trim( $content ); |
449 $content = trim( $content ); |
412 return $content; |
450 return $content; |
413 } |
451 } |
414 |
452 |
415 /** |
453 /** |
416 * Use RegEx to extract URLs from arbitrary content |
454 * Use RegEx to extract URLs from arbitrary content. |
417 * |
455 * |
418 * @since 3.7.0 |
456 * @since 3.7.0 |
419 * |
457 * |
420 * @param string $content |
458 * @param string $content Content to extract URLs from. |
421 * @return array URLs found in passed string |
459 * @return array URLs found in passed string. |
422 */ |
460 */ |
423 function wp_extract_urls( $content ) { |
461 function wp_extract_urls( $content ) { |
424 preg_match_all( |
462 preg_match_all( |
425 "#((?:[\w-]+://?|[\w\d]+[.])[^\s()<>]+[.](?:\([\w\d]+\)|(?:[^`!()\[\]{};:'\".,<>?«»“”‘’\s]|(?:[:]\d+)?/?)+))#", |
463 "#([\"']?)(" |
|
464 . "(?:([\w-]+:)?//?)" |
|
465 . "[^\s()<>]+" |
|
466 . "[.]" |
|
467 . "(?:" |
|
468 . "\([\w\d]+\)|" |
|
469 . "(?:" |
|
470 . "[^`!()\[\]{};:'\".,<>«»“”‘’\s]|" |
|
471 . "(?:[:]\d+)?/?" |
|
472 . ")+" |
|
473 . ")" |
|
474 . ")\\1#", |
426 $content, |
475 $content, |
427 $post_links |
476 $post_links |
428 ); |
477 ); |
429 |
478 |
430 $post_links = array_unique( array_map( 'html_entity_decode', $post_links[0] ) ); |
479 $post_links = array_unique( array_map( 'html_entity_decode', $post_links[2] ) ); |
431 |
480 |
432 return array_values( $post_links ); |
481 return array_values( $post_links ); |
433 } |
482 } |
434 |
483 |
435 /** |
484 /** |
607 * Build URL query based on an associative and, or indexed array. |
658 * Build URL query based on an associative and, or indexed array. |
608 * |
659 * |
609 * This is a convenient function for easily building url queries. It sets the |
660 * This is a convenient function for easily building url queries. It sets the |
610 * separator to '&' and uses _http_build_query() function. |
661 * separator to '&' and uses _http_build_query() function. |
611 * |
662 * |
|
663 * @since 2.3.0 |
|
664 * |
612 * @see _http_build_query() Used to build the query |
665 * @see _http_build_query() Used to build the query |
613 * @link http://us2.php.net/manual/en/function.http-build-query.php more on what |
666 * @see http://us2.php.net/manual/en/function.http-build-query.php for more on what |
614 * http_build_query() does. |
667 * http_build_query() does. |
615 * |
668 * |
616 * @since 2.3.0 |
|
617 * |
|
618 * @param array $data URL-encode key/value pairs. |
669 * @param array $data URL-encode key/value pairs. |
619 * @return string URL encoded string |
670 * @return string URL-encoded string. |
620 */ |
671 */ |
621 function build_query( $data ) { |
672 function build_query( $data ) { |
622 return _http_build_query( $data, null, '&', '', false ); |
673 return _http_build_query( $data, null, '&', '', false ); |
623 } |
674 } |
624 |
675 |
625 // from php.net (modified by Mark Jaquith to behave like the native PHP5 function) |
676 /** |
626 function _http_build_query($data, $prefix=null, $sep=null, $key='', $urlencode=true) { |
677 * From php.net (modified by Mark Jaquith to behave like the native PHP5 function). |
|
678 * |
|
679 * @since 3.2.0 |
|
680 * @access private |
|
681 * |
|
682 * @see http://us1.php.net/manual/en/function.http-build-query.php |
|
683 * |
|
684 * @param array|object $data An array or object of data. Converted to array. |
|
685 * @param string $prefix Optional. Numeric index. If set, start parameter numbering with it. |
|
686 * Default null. |
|
687 * @param string $sep Optional. Argument separator; defaults to 'arg_separator.output'. |
|
688 * Default null. |
|
689 * @param string $key Optional. Used to prefix key name. Default empty. |
|
690 * @param bool $urlencode Optional. Whether to use urlencode() in the result. Default true. |
|
691 * |
|
692 * @return string The query string. |
|
693 */ |
|
694 function _http_build_query( $data, $prefix = null, $sep = null, $key = '', $urlencode = true ) { |
627 $ret = array(); |
695 $ret = array(); |
628 |
696 |
629 foreach ( (array) $data as $k => $v ) { |
697 foreach ( (array) $data as $k => $v ) { |
630 if ( $urlencode) |
698 if ( $urlencode) |
631 $k = urlencode($k); |
699 $k = urlencode($k); |
865 413 => 'Request Entity Too Large', |
934 413 => 'Request Entity Too Large', |
866 414 => 'Request-URI Too Long', |
935 414 => 'Request-URI Too Long', |
867 415 => 'Unsupported Media Type', |
936 415 => 'Unsupported Media Type', |
868 416 => 'Requested Range Not Satisfiable', |
937 416 => 'Requested Range Not Satisfiable', |
869 417 => 'Expectation Failed', |
938 417 => 'Expectation Failed', |
|
939 418 => 'I\'m a teapot', |
870 422 => 'Unprocessable Entity', |
940 422 => 'Unprocessable Entity', |
871 423 => 'Locked', |
941 423 => 'Locked', |
872 424 => 'Failed Dependency', |
942 424 => 'Failed Dependency', |
873 426 => 'Upgrade Required', |
943 426 => 'Upgrade Required', |
|
944 428 => 'Precondition Required', |
|
945 429 => 'Too Many Requests', |
|
946 431 => 'Request Header Fields Too Large', |
874 |
947 |
875 500 => 'Internal Server Error', |
948 500 => 'Internal Server Error', |
876 501 => 'Not Implemented', |
949 501 => 'Not Implemented', |
877 502 => 'Bad Gateway', |
950 502 => 'Bad Gateway', |
878 503 => 'Service Unavailable', |
951 503 => 'Service Unavailable', |
879 504 => 'Gateway Timeout', |
952 504 => 'Gateway Timeout', |
880 505 => 'HTTP Version Not Supported', |
953 505 => 'HTTP Version Not Supported', |
881 506 => 'Variant Also Negotiates', |
954 506 => 'Variant Also Negotiates', |
882 507 => 'Insufficient Storage', |
955 507 => 'Insufficient Storage', |
883 510 => 'Not Extended' |
956 510 => 'Not Extended', |
|
957 511 => 'Network Authentication Required', |
884 ); |
958 ); |
885 } |
959 } |
886 |
960 |
887 if ( isset( $wp_header_to_desc[$code] ) ) |
961 if ( isset( $wp_header_to_desc[$code] ) ) |
888 return $wp_header_to_desc[$code]; |
962 return $wp_header_to_desc[$code]; |
892 |
966 |
893 /** |
967 /** |
894 * Set HTTP status header. |
968 * Set HTTP status header. |
895 * |
969 * |
896 * @since 2.0.0 |
970 * @since 2.0.0 |
897 * @uses apply_filters() Calls 'status_header' on status header string, HTTP |
971 * |
898 * HTTP code, HTTP code description, and protocol string as separate |
972 * @see get_status_header_desc() |
899 * parameters. |
973 * |
900 * |
974 * @param int $code HTTP status code. |
901 * @param int $header HTTP status code |
975 */ |
902 * @return unknown |
976 function status_header( $code ) { |
903 */ |
977 $description = get_status_header_desc( $code ); |
904 function status_header( $header ) { |
978 |
905 $text = get_status_header_desc( $header ); |
979 if ( empty( $description ) ) |
906 |
980 return; |
907 if ( empty( $text ) ) |
981 |
908 return false; |
982 $protocol = $_SERVER['SERVER_PROTOCOL']; |
909 |
|
910 $protocol = $_SERVER["SERVER_PROTOCOL"]; |
|
911 if ( 'HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol ) |
983 if ( 'HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol ) |
912 $protocol = 'HTTP/1.0'; |
984 $protocol = 'HTTP/1.0'; |
913 $status_header = "$protocol $header $text"; |
985 $status_header = "$protocol $code $description"; |
914 if ( function_exists( 'apply_filters' ) ) |
986 if ( function_exists( 'apply_filters' ) ) |
915 $status_header = apply_filters( 'status_header', $status_header, $header, $text, $protocol ); |
987 |
916 |
988 /** |
917 return @header( $status_header, true, $header ); |
989 * Filter an HTTP status header. |
918 } |
990 * |
919 |
991 * @since 2.2.0 |
920 /** |
992 * |
921 * Gets the header information to prevent caching. |
993 * @param string $status_header HTTP status header. |
922 * |
994 * @param int $code HTTP status code. |
923 * The several different headers cover the different ways cache prevention is handled |
995 * @param string $description Description for the status code. |
924 * by different browsers |
996 * @param string $protocol Server protocol. |
|
997 */ |
|
998 $status_header = apply_filters( 'status_header', $status_header, $code, $description, $protocol ); |
|
999 |
|
1000 @header( $status_header, true, $code ); |
|
1001 } |
|
1002 |
|
1003 /** |
|
1004 * Get the header information to prevent caching. |
|
1005 * |
|
1006 * The several different headers cover the different ways cache prevention |
|
1007 * is handled by different browsers |
925 * |
1008 * |
926 * @since 2.8.0 |
1009 * @since 2.8.0 |
927 * |
1010 * |
928 * @uses apply_filters() |
|
929 * @return array The associative array of header names and field values. |
1011 * @return array The associative array of header names and field values. |
930 */ |
1012 */ |
931 function wp_get_nocache_headers() { |
1013 function wp_get_nocache_headers() { |
932 $headers = array( |
1014 $headers = array( |
933 'Expires' => 'Wed, 11 Jan 1984 05:00:00 GMT', |
1015 'Expires' => 'Wed, 11 Jan 1984 05:00:00 GMT', |
934 'Cache-Control' => 'no-cache, must-revalidate, max-age=0', |
1016 'Cache-Control' => 'no-cache, must-revalidate, max-age=0', |
935 'Pragma' => 'no-cache', |
1017 'Pragma' => 'no-cache', |
936 ); |
1018 ); |
937 |
1019 |
938 if ( function_exists('apply_filters') ) { |
1020 if ( function_exists('apply_filters') ) { |
939 $headers = (array) apply_filters('nocache_headers', $headers); |
1021 /** |
|
1022 * Filter the cache-controlling headers. |
|
1023 * |
|
1024 * @since 2.8.0 |
|
1025 * |
|
1026 * @see wp_get_nocache_headers() |
|
1027 * |
|
1028 * @param array $headers { |
|
1029 * Header names and field values. |
|
1030 * |
|
1031 * @type string $Expires Expires header. |
|
1032 * @type string $Cache-Control Cache-Control header. |
|
1033 * @type string $Pragma Pragma header. |
|
1034 * } |
|
1035 */ |
|
1036 $headers = (array) apply_filters( 'nocache_headers', $headers ); |
940 } |
1037 } |
941 $headers['Last-Modified'] = false; |
1038 $headers['Last-Modified'] = false; |
942 return $headers; |
1039 return $headers; |
943 } |
1040 } |
944 |
1041 |
945 /** |
1042 /** |
946 * Sets the headers to prevent caching for the different browsers. |
1043 * Set the headers to prevent caching for the different browsers. |
947 * |
1044 * |
948 * Different browsers support different nocache headers, so several headers must |
1045 * Different browsers support different nocache headers, so several |
949 * be sent so that all of them get the point that no caching should occur. |
1046 * headers must be sent so that all of them get the point that no |
|
1047 * caching should occur. |
950 * |
1048 * |
951 * @since 2.0.0 |
1049 * @since 2.0.0 |
952 * @uses wp_get_nocache_headers() |
1050 * |
|
1051 * @see wp_get_nocache_headers() |
953 */ |
1052 */ |
954 function nocache_headers() { |
1053 function nocache_headers() { |
955 $headers = wp_get_nocache_headers(); |
1054 $headers = wp_get_nocache_headers(); |
956 |
1055 |
957 unset( $headers['Last-Modified'] ); |
1056 unset( $headers['Last-Modified'] ); |
979 * |
1078 * |
980 * @since 2.1.0 |
1079 * @since 2.1.0 |
981 */ |
1080 */ |
982 function cache_javascript_headers() { |
1081 function cache_javascript_headers() { |
983 $expiresOffset = 10 * DAY_IN_SECONDS; |
1082 $expiresOffset = 10 * DAY_IN_SECONDS; |
|
1083 |
984 header( "Content-Type: text/javascript; charset=" . get_bloginfo( 'charset' ) ); |
1084 header( "Content-Type: text/javascript; charset=" . get_bloginfo( 'charset' ) ); |
985 header( "Vary: Accept-Encoding" ); // Handle proxies |
1085 header( "Vary: Accept-Encoding" ); // Handle proxies |
986 header( "Expires: " . gmdate( "D, d M Y H:i:s", time() + $expiresOffset ) . " GMT" ); |
1086 header( "Expires: " . gmdate( "D, d M Y H:i:s", time() + $expiresOffset ) . " GMT" ); |
987 } |
1087 } |
988 |
1088 |
989 /** |
1089 /** |
990 * Retrieve the number of database queries during the WordPress execution. |
1090 * Retrieve the number of database queries during the WordPress execution. |
991 * |
1091 * |
992 * @since 2.0.0 |
1092 * @since 2.0.0 |
993 * |
1093 * |
994 * @return int Number of database queries |
1094 * @global wpdb $wpdb WordPress database abstraction object. |
|
1095 * |
|
1096 * @return int Number of database queries. |
995 */ |
1097 */ |
996 function get_num_queries() { |
1098 function get_num_queries() { |
997 global $wpdb; |
1099 global $wpdb; |
998 return $wpdb->num_queries; |
1100 return $wpdb->num_queries; |
999 } |
1101 } |
1000 |
1102 |
1001 /** |
1103 /** |
1002 * Whether input is yes or no. Must be 'y' to be true. |
1104 * Whether input is yes or no. |
|
1105 * |
|
1106 * Must be 'y' to be true. |
1003 * |
1107 * |
1004 * @since 1.0.0 |
1108 * @since 1.0.0 |
1005 * |
1109 * |
1006 * @param string $yn Character string containing either 'y' or 'n' |
1110 * @param string $yn Character string containing either 'y' (yes) or 'n' (no). |
1007 * @return bool True if yes, false on anything else |
1111 * @return bool True if yes, false on anything else. |
1008 */ |
1112 */ |
1009 function bool_from_yn( $yn ) { |
1113 function bool_from_yn( $yn ) { |
1010 return ( strtolower( $yn ) == 'y' ); |
1114 return ( strtolower( $yn ) == 'y' ); |
1011 } |
1115 } |
1012 |
1116 |
1013 /** |
1117 /** |
1014 * Loads the feed template from the use of an action hook. |
1118 * Load the feed template from the use of an action hook. |
1015 * |
1119 * |
1016 * If the feed action does not have a hook, then the function will die with a |
1120 * If the feed action does not have a hook, then the function will die with a |
1017 * message telling the visitor that the feed is not valid. |
1121 * message telling the visitor that the feed is not valid. |
1018 * |
1122 * |
1019 * It is better to only have one hook for each feed. |
1123 * It is better to only have one hook for each feed. |
1020 * |
1124 * |
1021 * @since 2.1.0 |
1125 * @since 2.1.0 |
|
1126 * |
1022 * @uses $wp_query Used to tell if the use a comment feed. |
1127 * @uses $wp_query Used to tell if the use a comment feed. |
1023 * @uses do_action() Calls 'do_feed_$feed' hook, if a hook exists for the feed. |
|
1024 */ |
1128 */ |
1025 function do_feed() { |
1129 function do_feed() { |
1026 global $wp_query; |
1130 global $wp_query; |
1027 |
1131 |
1028 $feed = get_query_var( 'feed' ); |
1132 $feed = get_query_var( 'feed' ); |
1035 |
1139 |
1036 $hook = 'do_feed_' . $feed; |
1140 $hook = 'do_feed_' . $feed; |
1037 if ( ! has_action( $hook ) ) |
1141 if ( ! has_action( $hook ) ) |
1038 wp_die( __( 'ERROR: This is not a valid feed template.' ), '', array( 'response' => 404 ) ); |
1142 wp_die( __( 'ERROR: This is not a valid feed template.' ), '', array( 'response' => 404 ) ); |
1039 |
1143 |
|
1144 /** |
|
1145 * Fires once the given feed is loaded. |
|
1146 * |
|
1147 * The dynamic hook name, $hook, refers to the feed name. |
|
1148 * |
|
1149 * @since 2.1.0 |
|
1150 * |
|
1151 * @param bool $is_comment_feed Whether the feed is a comment feed. |
|
1152 */ |
1040 do_action( $hook, $wp_query->is_comment_feed ); |
1153 do_action( $hook, $wp_query->is_comment_feed ); |
1041 } |
1154 } |
1042 |
1155 |
1043 /** |
1156 /** |
1044 * Load the RDF RSS 0.91 Feed template. |
1157 * Load the RDF RSS 0.91 Feed template. |
1045 * |
1158 * |
1046 * @since 2.1.0 |
1159 * @since 2.1.0 |
|
1160 * |
|
1161 * @see load_template() |
1047 */ |
1162 */ |
1048 function do_feed_rdf() { |
1163 function do_feed_rdf() { |
1049 load_template( ABSPATH . WPINC . '/feed-rdf.php' ); |
1164 load_template( ABSPATH . WPINC . '/feed-rdf.php' ); |
1050 } |
1165 } |
1051 |
1166 |
1052 /** |
1167 /** |
1053 * Load the RSS 1.0 Feed Template. |
1168 * Load the RSS 1.0 Feed Template. |
1054 * |
1169 * |
1055 * @since 2.1.0 |
1170 * @since 2.1.0 |
|
1171 * |
|
1172 * @see load_template() |
1056 */ |
1173 */ |
1057 function do_feed_rss() { |
1174 function do_feed_rss() { |
1058 load_template( ABSPATH . WPINC . '/feed-rss.php' ); |
1175 load_template( ABSPATH . WPINC . '/feed-rss.php' ); |
1059 } |
1176 } |
1060 |
1177 |
1061 /** |
1178 /** |
1062 * Load either the RSS2 comment feed or the RSS2 posts feed. |
1179 * Load either the RSS2 comment feed or the RSS2 posts feed. |
1063 * |
1180 * |
1064 * @since 2.1.0 |
1181 * @since 2.1.0 |
|
1182 * |
|
1183 * @see load_template() |
1065 * |
1184 * |
1066 * @param bool $for_comments True for the comment feed, false for normal feed. |
1185 * @param bool $for_comments True for the comment feed, false for normal feed. |
1067 */ |
1186 */ |
1068 function do_feed_rss2( $for_comments ) { |
1187 function do_feed_rss2( $for_comments ) { |
1069 if ( $for_comments ) |
1188 if ( $for_comments ) |
1091 * |
1212 * |
1092 * The echo content should be with usage of the permalinks or for creating the |
1213 * The echo content should be with usage of the permalinks or for creating the |
1093 * robots.txt file. |
1214 * robots.txt file. |
1094 * |
1215 * |
1095 * @since 2.1.0 |
1216 * @since 2.1.0 |
1096 * @uses do_action() Calls 'do_robotstxt' hook for displaying robots.txt rules. |
|
1097 */ |
1217 */ |
1098 function do_robots() { |
1218 function do_robots() { |
1099 header( 'Content-Type: text/plain; charset=utf-8' ); |
1219 header( 'Content-Type: text/plain; charset=utf-8' ); |
1100 |
1220 |
|
1221 /** |
|
1222 * Fires when displaying the robots.txt file. |
|
1223 * |
|
1224 * @since 2.1.0 |
|
1225 */ |
1101 do_action( 'do_robotstxt' ); |
1226 do_action( 'do_robotstxt' ); |
1102 |
1227 |
1103 $output = "User-agent: *\n"; |
1228 $output = "User-agent: *\n"; |
1104 $public = get_option( 'blog_public' ); |
1229 $public = get_option( 'blog_public' ); |
1105 if ( '0' == $public ) { |
1230 if ( '0' == $public ) { |
1106 $output .= "Disallow: /\n"; |
1231 $output .= "Disallow: /\n"; |
1107 } else { |
1232 } else { |
1108 $site_url = parse_url( site_url() ); |
1233 $site_url = parse_url( site_url() ); |
1109 $path = ( !empty( $site_url['path'] ) ) ? $site_url['path'] : ''; |
1234 $path = ( !empty( $site_url['path'] ) ) ? $site_url['path'] : ''; |
1110 $output .= "Disallow: $path/wp-admin/\n"; |
1235 $output .= "Disallow: $path/wp-admin/\n"; |
1111 $output .= "Disallow: $path/wp-includes/\n"; |
1236 } |
1112 } |
1237 |
1113 |
1238 /** |
1114 echo apply_filters('robots_txt', $output, $public); |
1239 * Filter the robots.txt output. |
|
1240 * |
|
1241 * @since 3.0.0 |
|
1242 * |
|
1243 * @param string $output Robots.txt output. |
|
1244 * @param bool $public Whether the site is considered "public". |
|
1245 */ |
|
1246 echo apply_filters( 'robots_txt', $output, $public ); |
1115 } |
1247 } |
1116 |
1248 |
1117 /** |
1249 /** |
1118 * Test whether blog is already installed. |
1250 * Test whether blog is already installed. |
1119 * |
1251 * |
1120 * The cache will be checked first. If you have a cache plugin, which saves the |
1252 * The cache will be checked first. If you have a cache plugin, which saves |
1121 * cache values, then this will work. If you use the default WordPress cache, |
1253 * the cache values, then this will work. If you use the default WordPress |
1122 * and the database goes away, then you might have problems. |
1254 * cache, and the database goes away, then you might have problems. |
1123 * |
1255 * |
1124 * Checks for the option siteurl for whether WordPress is installed. |
1256 * Checks for the 'siteurl' option for whether WordPress is installed. |
1125 * |
1257 * |
1126 * @since 2.1.0 |
1258 * @since 2.1.0 |
1127 * @uses $wpdb |
1259 * |
1128 * |
1260 * @global wpdb $wpdb WordPress database abstraction object. |
1129 * @return bool Whether blog is already installed. |
1261 * |
|
1262 * @return bool Whether the blog is already installed. |
1130 */ |
1263 */ |
1131 function is_blog_installed() { |
1264 function is_blog_installed() { |
1132 global $wpdb; |
1265 global $wpdb; |
1133 |
1266 |
1134 // Check cache first. If options table goes away and we have true cached, oh well. |
1267 /* |
|
1268 * Check cache first. If options table goes away and we have true |
|
1269 * cached, oh well. |
|
1270 */ |
1135 if ( wp_cache_get( 'is_blog_installed' ) ) |
1271 if ( wp_cache_get( 'is_blog_installed' ) ) |
1136 return true; |
1272 return true; |
1137 |
1273 |
1138 $suppress = $wpdb->suppress_errors(); |
1274 $suppress = $wpdb->suppress_errors(); |
1139 if ( ! defined( 'WP_INSTALLING' ) ) { |
1275 if ( ! defined( 'WP_INSTALLING' ) ) { |
1291 echo $orig_referer_field; |
1422 echo $orig_referer_field; |
1292 return $orig_referer_field; |
1423 return $orig_referer_field; |
1293 } |
1424 } |
1294 |
1425 |
1295 /** |
1426 /** |
1296 * Retrieve referer from '_wp_http_referer' or HTTP referer. If it's the same |
1427 * Retrieve referer from '_wp_http_referer' or HTTP referer. |
1297 * as the current request URL, will return false. |
1428 * |
1298 * |
1429 * If it's the same as the current request URL, will return false. |
1299 * @package WordPress |
1430 * |
1300 * @subpackage Security |
|
1301 * @since 2.0.4 |
1431 * @since 2.0.4 |
1302 * |
1432 * |
1303 * @return string|bool False on failure. Referer URL on success. |
1433 * @return false|string False on failure. Referer URL on success. |
1304 */ |
1434 */ |
1305 function wp_get_referer() { |
1435 function wp_get_referer() { |
1306 if ( ! function_exists( 'wp_validate_redirect' ) ) |
1436 if ( ! function_exists( 'wp_validate_redirect' ) ) |
1307 return false; |
1437 return false; |
1308 $ref = false; |
1438 $ref = false; |
1309 if ( ! empty( $_REQUEST['_wp_http_referer'] ) ) |
1439 if ( ! empty( $_REQUEST['_wp_http_referer'] ) ) |
1310 $ref = wp_unslash( $_REQUEST['_wp_http_referer'] ); |
1440 $ref = wp_unslash( $_REQUEST['_wp_http_referer'] ); |
1311 else if ( ! empty( $_SERVER['HTTP_REFERER'] ) ) |
1441 elseif ( ! empty( $_SERVER['HTTP_REFERER'] ) ) |
1312 $ref = wp_unslash( $_SERVER['HTTP_REFERER'] ); |
1442 $ref = wp_unslash( $_SERVER['HTTP_REFERER'] ); |
1313 |
1443 |
1314 if ( $ref && $ref !== wp_unslash( $_SERVER['REQUEST_URI'] ) ) |
1444 if ( $ref && $ref !== wp_unslash( $_SERVER['REQUEST_URI'] ) ) |
1315 return wp_validate_redirect( $ref, false ); |
1445 return wp_validate_redirect( $ref, false ); |
1316 return false; |
1446 return false; |
1317 } |
1447 } |
1318 |
1448 |
1319 /** |
1449 /** |
1320 * Retrieve original referer that was posted, if it exists. |
1450 * Retrieve original referer that was posted, if it exists. |
1321 * |
1451 * |
1322 * @package WordPress |
|
1323 * @subpackage Security |
|
1324 * @since 2.0.4 |
1452 * @since 2.0.4 |
1325 * |
1453 * |
1326 * @return string|bool False if no original referer or original referer if set. |
1454 * @return string|false False if no original referer or original referer if set. |
1327 */ |
1455 */ |
1328 function wp_get_original_referer() { |
1456 function wp_get_original_referer() { |
1329 if ( ! empty( $_REQUEST['_wp_original_http_referer'] ) && function_exists( 'wp_validate_redirect' ) ) |
1457 if ( ! empty( $_REQUEST['_wp_original_http_referer'] ) && function_exists( 'wp_validate_redirect' ) ) |
1330 return wp_validate_redirect( wp_unslash( $_REQUEST['_wp_original_http_referer'] ), false ); |
1458 return wp_validate_redirect( wp_unslash( $_REQUEST['_wp_original_http_referer'] ), false ); |
1331 return false; |
1459 return false; |
1342 * @return bool Whether the path was created. True if path already exists. |
1470 * @return bool Whether the path was created. True if path already exists. |
1343 */ |
1471 */ |
1344 function wp_mkdir_p( $target ) { |
1472 function wp_mkdir_p( $target ) { |
1345 $wrapper = null; |
1473 $wrapper = null; |
1346 |
1474 |
1347 // strip the protocol |
1475 // Strip the protocol. |
1348 if( wp_is_stream( $target ) ) { |
1476 if( wp_is_stream( $target ) ) { |
1349 list( $wrapper, $target ) = explode( '://', $target, 2 ); |
1477 list( $wrapper, $target ) = explode( '://', $target, 2 ); |
1350 } |
1478 } |
1351 |
1479 |
1352 // from php.net/mkdir user contributed notes |
1480 // From php.net/mkdir user contributed notes. |
1353 $target = str_replace( '//', '/', $target ); |
1481 $target = str_replace( '//', '/', $target ); |
1354 |
1482 |
1355 // put the wrapper back on the target |
1483 // Put the wrapper back on the target. |
1356 if( $wrapper !== null ) { |
1484 if( $wrapper !== null ) { |
1357 $target = $wrapper . '://' . $target; |
1485 $target = $wrapper . '://' . $target; |
1358 } |
1486 } |
1359 |
1487 |
1360 // safe mode fails with a trailing slash under certain PHP versions. |
1488 /* |
1361 $target = rtrim($target, '/'); // Use rtrim() instead of untrailingslashit to avoid formatting.php dependency. |
1489 * Safe mode fails with a trailing slash under certain PHP versions. |
|
1490 * Use rtrim() instead of untrailingslashit to avoid formatting.php dependency. |
|
1491 */ |
|
1492 $target = rtrim($target, '/'); |
1362 if ( empty($target) ) |
1493 if ( empty($target) ) |
1363 $target = '/'; |
1494 $target = '/'; |
1364 |
1495 |
1365 if ( file_exists( $target ) ) |
1496 if ( file_exists( $target ) ) |
1366 return @is_dir( $target ); |
1497 return @is_dir( $target ); |
1370 while ( '.' != $target_parent && ! is_dir( $target_parent ) ) { |
1501 while ( '.' != $target_parent && ! is_dir( $target_parent ) ) { |
1371 $target_parent = dirname( $target_parent ); |
1502 $target_parent = dirname( $target_parent ); |
1372 } |
1503 } |
1373 |
1504 |
1374 // Get the permission bits. |
1505 // Get the permission bits. |
1375 if ( $target_parent && '.' != $target_parent ) { |
1506 if ( $stat = @stat( $target_parent ) ) { |
1376 $stat = @stat( $target_parent ); |
|
1377 $dir_perms = $stat['mode'] & 0007777; |
1507 $dir_perms = $stat['mode'] & 0007777; |
1378 } else { |
1508 } else { |
1379 $dir_perms = 0777; |
1509 $dir_perms = 0777; |
1380 } |
1510 } |
1381 |
1511 |
1382 if ( @mkdir( $target, $dir_perms, true ) ) { |
1512 if ( @mkdir( $target, $dir_perms, true ) ) { |
|
1513 |
|
1514 /* |
|
1515 * If a umask is set that modifies $dir_perms, we'll have to re-set |
|
1516 * the $dir_perms correctly with chmod() |
|
1517 */ |
|
1518 if ( $dir_perms != ( $dir_perms & ~umask() ) ) { |
|
1519 $folder_parts = explode( '/', substr( $target, strlen( $target_parent ) + 1 ) ); |
|
1520 for ( $i = 1, $c = count( $folder_parts ); $i <= $c; $i++ ) { |
|
1521 @chmod( $target_parent . '/' . implode( '/', array_slice( $folder_parts, 0, $i ) ), $dir_perms ); |
|
1522 } |
|
1523 } |
|
1524 |
1383 return true; |
1525 return true; |
1384 } |
1526 } |
1385 |
1527 |
1386 return false; |
1528 return false; |
1387 } |
1529 } |
1388 |
1530 |
1389 /** |
1531 /** |
1390 * Test if a give filesystem path is absolute ('/foo/bar', 'c:\windows'). |
1532 * Test if a give filesystem path is absolute. |
|
1533 * |
|
1534 * For example, '/foo/bar', or 'c:\windows'. |
1391 * |
1535 * |
1392 * @since 2.5.0 |
1536 * @since 2.5.0 |
1393 * |
1537 * |
1394 * @param string $path File path |
1538 * @param string $path File path. |
1395 * @return bool True if path is absolute, false is not absolute. |
1539 * @return bool True if path is absolute, false is not absolute. |
1396 */ |
1540 */ |
1397 function path_is_absolute( $path ) { |
1541 function path_is_absolute( $path ) { |
1398 // this is definitive if true but fails if $path does not exist or contains a symbolic link |
1542 /* |
|
1543 * This is definitive if true but fails if $path does not exist or contains |
|
1544 * a symbolic link. |
|
1545 */ |
1399 if ( realpath($path) == $path ) |
1546 if ( realpath($path) == $path ) |
1400 return true; |
1547 return true; |
1401 |
1548 |
1402 if ( strlen($path) == 0 || $path[0] == '.' ) |
1549 if ( strlen($path) == 0 || $path[0] == '.' ) |
1403 return false; |
1550 return false; |
1404 |
1551 |
1405 // windows allows absolute paths like this |
1552 // Windows allows absolute paths like this. |
1406 if ( preg_match('#^[a-zA-Z]:\\\\#', $path) ) |
1553 if ( preg_match('#^[a-zA-Z]:\\\\#', $path) ) |
1407 return true; |
1554 return true; |
1408 |
1555 |
1409 // a path starting with / or \ is absolute; anything else is relative |
1556 // A path starting with / or \ is absolute; anything else is relative. |
1410 return ( $path[0] == '/' || $path[0] == '\\' ); |
1557 return ( $path[0] == '/' || $path[0] == '\\' ); |
1411 } |
1558 } |
1412 |
1559 |
1413 /** |
1560 /** |
1414 * Join two filesystem paths together (e.g. 'give me $path relative to $base'). |
1561 * Join two filesystem paths together. |
1415 * |
1562 * |
1416 * If the $path is absolute, then it the full path is returned. |
1563 * For example, 'give me $path relative to $base'. If the $path is absolute, |
|
1564 * then it the full path is returned. |
1417 * |
1565 * |
1418 * @since 2.5.0 |
1566 * @since 2.5.0 |
1419 * |
1567 * |
1420 * @param string $base |
1568 * @param string $base Base path. |
1421 * @param string $path |
1569 * @param string $path Path relative to $base. |
1422 * @return string The path with the base or absolute path. |
1570 * @return string The path with the base or absolute path. |
1423 */ |
1571 */ |
1424 function path_join( $base, $path ) { |
1572 function path_join( $base, $path ) { |
1425 if ( path_is_absolute($path) ) |
1573 if ( path_is_absolute($path) ) |
1426 return $path; |
1574 return $path; |
1427 |
1575 |
1428 return rtrim($base, '/') . '/' . ltrim($path, '/'); |
1576 return rtrim($base, '/') . '/' . ltrim($path, '/'); |
1429 } |
1577 } |
1430 |
1578 |
1431 /** |
1579 /** |
1432 * Determines a writable directory for temporary files. |
1580 * Normalize a filesystem path. |
1433 * Function's preference is the return value of <code>sys_get_temp_dir()</code>, |
1581 * |
|
1582 * Replaces backslashes with forward slashes for Windows systems, and ensures |
|
1583 * no duplicate slashes exist. |
|
1584 * |
|
1585 * @since 3.9.0 |
|
1586 * |
|
1587 * @param string $path Path to normalize. |
|
1588 * @return string Normalized path. |
|
1589 */ |
|
1590 function wp_normalize_path( $path ) { |
|
1591 $path = str_replace( '\\', '/', $path ); |
|
1592 $path = preg_replace( '|/+|','/', $path ); |
|
1593 return $path; |
|
1594 } |
|
1595 |
|
1596 /** |
|
1597 * Determine a writable directory for temporary files. |
|
1598 * |
|
1599 * Function's preference is the return value of sys_get_temp_dir(), |
1434 * followed by your PHP temporary upload directory, followed by WP_CONTENT_DIR, |
1600 * followed by your PHP temporary upload directory, followed by WP_CONTENT_DIR, |
1435 * before finally defaulting to /tmp/ |
1601 * before finally defaulting to /tmp/ |
1436 * |
1602 * |
1437 * In the event that this function does not find a writable location, |
1603 * In the event that this function does not find a writable location, |
1438 * It may be overridden by the <code>WP_TEMP_DIR</code> constant in |
1604 * It may be overridden by the WP_TEMP_DIR constant in your wp-config.php file. |
1439 * your <code>wp-config.php</code> file. |
|
1440 * |
1605 * |
1441 * @since 2.5.0 |
1606 * @since 2.5.0 |
1442 * |
1607 * |
1443 * @return string Writable temporary directory |
1608 * @return string Writable temporary directory. |
1444 */ |
1609 */ |
1445 function get_temp_dir() { |
1610 function get_temp_dir() { |
1446 static $temp; |
1611 static $temp; |
1447 if ( defined('WP_TEMP_DIR') ) |
1612 if ( defined('WP_TEMP_DIR') ) |
1448 return trailingslashit(WP_TEMP_DIR); |
1613 return trailingslashit(WP_TEMP_DIR); |
1449 |
1614 |
1450 if ( $temp ) |
1615 if ( $temp ) |
1451 return trailingslashit( rtrim( $temp, '\\' ) ); |
1616 return trailingslashit( $temp ); |
1452 |
1617 |
1453 if ( function_exists('sys_get_temp_dir') ) { |
1618 if ( function_exists('sys_get_temp_dir') ) { |
1454 $temp = sys_get_temp_dir(); |
1619 $temp = sys_get_temp_dir(); |
1455 if ( @is_dir( $temp ) && wp_is_writable( $temp ) ) |
1620 if ( @is_dir( $temp ) && wp_is_writable( $temp ) ) |
1456 return trailingslashit( rtrim( $temp, '\\' ) ); |
1621 return trailingslashit( $temp ); |
1457 } |
1622 } |
1458 |
1623 |
1459 $temp = ini_get('upload_tmp_dir'); |
1624 $temp = ini_get('upload_tmp_dir'); |
1460 if ( @is_dir( $temp ) && wp_is_writable( $temp ) ) |
1625 if ( @is_dir( $temp ) && wp_is_writable( $temp ) ) |
1461 return trailingslashit( rtrim( $temp, '\\' ) ); |
1626 return trailingslashit( $temp ); |
1462 |
1627 |
1463 $temp = WP_CONTENT_DIR . '/'; |
1628 $temp = WP_CONTENT_DIR . '/'; |
1464 if ( is_dir( $temp ) && wp_is_writable( $temp ) ) |
1629 if ( is_dir( $temp ) && wp_is_writable( $temp ) ) |
1465 return $temp; |
1630 return $temp; |
1466 |
1631 |
1494 * PHP has issues with Windows ACL's for determine if a |
1659 * PHP has issues with Windows ACL's for determine if a |
1495 * directory is writable or not, this works around them by |
1660 * directory is writable or not, this works around them by |
1496 * checking the ability to open files rather than relying |
1661 * checking the ability to open files rather than relying |
1497 * upon PHP to interprate the OS ACL. |
1662 * upon PHP to interprate the OS ACL. |
1498 * |
1663 * |
1499 * @link http://bugs.php.net/bug.php?id=27609 |
|
1500 * @link http://bugs.php.net/bug.php?id=30931 |
|
1501 * |
|
1502 * @since 2.8.0 |
1664 * @since 2.8.0 |
1503 * |
1665 * |
1504 * @param string $path |
1666 * @see http://bugs.php.net/bug.php?id=27609 |
1505 * @return bool |
1667 * @see http://bugs.php.net/bug.php?id=30931 |
|
1668 * |
|
1669 * @param string $path Windows path to check for write-ability. |
|
1670 * @return bool Whether the path is writable. |
1506 */ |
1671 */ |
1507 function win_is_writable( $path ) { |
1672 function win_is_writable( $path ) { |
1508 |
1673 |
1509 if ( $path[strlen( $path ) - 1] == '/' ) // if it looks like a directory, check a random file within the directory |
1674 if ( $path[strlen( $path ) - 1] == '/' ) { // if it looks like a directory, check a random file within the directory |
1510 return win_is_writable( $path . uniqid( mt_rand() ) . '.tmp'); |
1675 return win_is_writable( $path . uniqid( mt_rand() ) . '.tmp'); |
1511 else if ( is_dir( $path ) ) // If it's a directory (and not a file) check a random file within the directory |
1676 } elseif ( is_dir( $path ) ) { // If it's a directory (and not a file) check a random file within the directory |
1512 return win_is_writable( $path . '/' . uniqid( mt_rand() ) . '.tmp' ); |
1677 return win_is_writable( $path . '/' . uniqid( mt_rand() ) . '.tmp' ); |
1513 |
1678 } |
1514 // check tmp file for read/write capabilities |
1679 // check tmp file for read/write capabilities |
1515 $should_delete_tmp_file = !file_exists( $path ); |
1680 $should_delete_tmp_file = !file_exists( $path ); |
1516 $f = @fopen( $path, 'a' ); |
1681 $f = @fopen( $path, 'a' ); |
1517 if ( $f === false ) |
1682 if ( $f === false ) |
1518 return false; |
1683 return false; |
1573 $url = WP_CONTENT_URL . '/uploads'; |
1737 $url = WP_CONTENT_URL . '/uploads'; |
1574 else |
1738 else |
1575 $url = trailingslashit( $siteurl ) . $upload_path; |
1739 $url = trailingslashit( $siteurl ) . $upload_path; |
1576 } |
1740 } |
1577 |
1741 |
1578 // Obey the value of UPLOADS. This happens as long as ms-files rewriting is disabled. |
1742 /* |
1579 // We also sometimes obey UPLOADS when rewriting is enabled -- see the next block. |
1743 * Honor the value of UPLOADS. This happens as long as ms-files rewriting is disabled. |
|
1744 * We also sometimes obey UPLOADS when rewriting is enabled -- see the next block. |
|
1745 */ |
1580 if ( defined( 'UPLOADS' ) && ! ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) ) { |
1746 if ( defined( 'UPLOADS' ) && ! ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) ) { |
1581 $dir = ABSPATH . UPLOADS; |
1747 $dir = ABSPATH . UPLOADS; |
1582 $url = trailingslashit( $siteurl ) . UPLOADS; |
1748 $url = trailingslashit( $siteurl ) . UPLOADS; |
1583 } |
1749 } |
1584 |
1750 |
1585 // If multisite (and if not the main site in a post-MU network) |
1751 // If multisite (and if not the main site in a post-MU network) |
1586 if ( is_multisite() && ! ( is_main_network() && is_main_site() && defined( 'MULTISITE' ) ) ) { |
1752 if ( is_multisite() && ! ( is_main_network() && is_main_site() && defined( 'MULTISITE' ) ) ) { |
1587 |
1753 |
1588 if ( ! get_site_option( 'ms_files_rewriting' ) ) { |
1754 if ( ! get_site_option( 'ms_files_rewriting' ) ) { |
1589 // If ms-files rewriting is disabled (networks created post-3.5), it is fairly straightforward: |
1755 /* |
1590 // Append sites/%d if we're not on the main site (for post-MU networks). (The extra directory |
1756 * If ms-files rewriting is disabled (networks created post-3.5), it is fairly |
1591 // prevents a four-digit ID from conflicting with a year-based directory for the main site. |
1757 * straightforward: Append sites/%d if we're not on the main site (for post-MU |
1592 // But if a MU-era network has disabled ms-files rewriting manually, they don't need the extra |
1758 * networks). (The extra directory prevents a four-digit ID from conflicting with |
1593 // directory, as they never had wp-content/uploads for the main site.) |
1759 * a year-based directory for the main site. But if a MU-era network has disabled |
|
1760 * ms-files rewriting manually, they don't need the extra directory, as they never |
|
1761 * had wp-content/uploads for the main site.) |
|
1762 */ |
1594 |
1763 |
1595 if ( defined( 'MULTISITE' ) ) |
1764 if ( defined( 'MULTISITE' ) ) |
1596 $ms_dir = '/sites/' . get_current_blog_id(); |
1765 $ms_dir = '/sites/' . get_current_blog_id(); |
1597 else |
1766 else |
1598 $ms_dir = '/' . get_current_blog_id(); |
1767 $ms_dir = '/' . get_current_blog_id(); |
1599 |
1768 |
1600 $dir .= $ms_dir; |
1769 $dir .= $ms_dir; |
1601 $url .= $ms_dir; |
1770 $url .= $ms_dir; |
1602 |
1771 |
1603 } elseif ( defined( 'UPLOADS' ) && ! ms_is_switched() ) { |
1772 } elseif ( defined( 'UPLOADS' ) && ! ms_is_switched() ) { |
1604 // Handle the old-form ms-files.php rewriting if the network still has that enabled. |
1773 /* |
1605 // When ms-files rewriting is enabled, then we only listen to UPLOADS when: |
1774 * Handle the old-form ms-files.php rewriting if the network still has that enabled. |
1606 // 1) we are not on the main site in a post-MU network, |
1775 * When ms-files rewriting is enabled, then we only listen to UPLOADS when: |
1607 // as wp-content/uploads is used there, and |
1776 * 1) We are not on the main site in a post-MU network, as wp-content/uploads is used |
1608 // 2) we are not switched, as ms_upload_constants() hardcodes |
1777 * there, and |
1609 // these constants to reflect the original blog ID. |
1778 * 2) We are not switched, as ms_upload_constants() hardcodes these constants to reflect |
1610 // |
1779 * the original blog ID. |
1611 // Rather than UPLOADS, we actually use BLOGUPLOADDIR if it is set, as it is absolute. |
1780 * |
1612 // (And it will be set, see ms_upload_constants().) Otherwise, UPLOADS can be used, as |
1781 * Rather than UPLOADS, we actually use BLOGUPLOADDIR if it is set, as it is absolute. |
1613 // as it is relative to ABSPATH. For the final piece: when UPLOADS is used with ms-files |
1782 * (And it will be set, see ms_upload_constants().) Otherwise, UPLOADS can be used, as |
1614 // rewriting in multisite, the resulting URL is /files. (#WP22702 for background.) |
1783 * as it is relative to ABSPATH. For the final piece: when UPLOADS is used with ms-files |
|
1784 * rewriting in multisite, the resulting URL is /files. (#WP22702 for background.) |
|
1785 */ |
1615 |
1786 |
1616 if ( defined( 'BLOGUPLOADDIR' ) ) |
1787 if ( defined( 'BLOGUPLOADDIR' ) ) |
1617 $dir = untrailingslashit( BLOGUPLOADDIR ); |
1788 $dir = untrailingslashit( BLOGUPLOADDIR ); |
1618 else |
1789 else |
1619 $dir = ABSPATH . UPLOADS; |
1790 $dir = ABSPATH . UPLOADS; |
1671 * The callback is passed three parameters, the first one is the directory, the |
1850 * The callback is passed three parameters, the first one is the directory, the |
1672 * second is the filename, and the third is the extension. |
1851 * second is the filename, and the third is the extension. |
1673 * |
1852 * |
1674 * @since 2.5.0 |
1853 * @since 2.5.0 |
1675 * |
1854 * |
1676 * @param string $dir |
1855 * @param string $dir Directory. |
1677 * @param string $filename |
1856 * @param string $filename File name. |
1678 * @param mixed $unique_filename_callback Callback. |
1857 * @param callback $unique_filename_callback Callback. Default null. |
1679 * @return string New filename, if given wasn't unique. |
1858 * @return string New filename, if given wasn't unique. |
1680 */ |
1859 */ |
1681 function wp_unique_filename( $dir, $filename, $unique_filename_callback = null ) { |
1860 function wp_unique_filename( $dir, $filename, $unique_filename_callback = null ) { |
1682 // sanitize the file name before we begin processing |
1861 // Sanitize the file name before we begin processing. |
1683 $filename = sanitize_file_name($filename); |
1862 $filename = sanitize_file_name($filename); |
1684 |
1863 |
1685 // separate the filename into a name and extension |
1864 // Separate the filename into a name and extension. |
1686 $info = pathinfo($filename); |
1865 $info = pathinfo($filename); |
1687 $ext = !empty($info['extension']) ? '.' . $info['extension'] : ''; |
1866 $ext = !empty($info['extension']) ? '.' . $info['extension'] : ''; |
1688 $name = basename($filename, $ext); |
1867 $name = basename($filename, $ext); |
1689 |
1868 |
1690 // edge case: if file is named '.ext', treat as an empty name |
1869 // Edge case: if file is named '.ext', treat as an empty name. |
1691 if ( $name === $ext ) |
1870 if ( $name === $ext ) |
1692 $name = ''; |
1871 $name = ''; |
1693 |
1872 |
1694 // Increment the file number until we have a unique file to save in $dir. Use callback if supplied. |
1873 /* |
|
1874 * Increment the file number until we have a unique file to save in $dir. |
|
1875 * Use callback if supplied. |
|
1876 */ |
1695 if ( $unique_filename_callback && is_callable( $unique_filename_callback ) ) { |
1877 if ( $unique_filename_callback && is_callable( $unique_filename_callback ) ) { |
1696 $filename = call_user_func( $unique_filename_callback, $dir, $name, $ext ); |
1878 $filename = call_user_func( $unique_filename_callback, $dir, $name, $ext ); |
1697 } else { |
1879 } else { |
1698 $number = ''; |
1880 $number = ''; |
1699 |
1881 |
1700 // change '.ext' to lower case |
1882 // Change '.ext' to lower case. |
1701 if ( $ext && strtolower($ext) != $ext ) { |
1883 if ( $ext && strtolower($ext) != $ext ) { |
1702 $ext2 = strtolower($ext); |
1884 $ext2 = strtolower($ext); |
1703 $filename2 = preg_replace( '|' . preg_quote($ext) . '$|', $ext2, $filename ); |
1885 $filename2 = preg_replace( '|' . preg_quote($ext) . '$|', $ext2, $filename ); |
1704 |
1886 |
1705 // check for both lower and upper case extension or image sub-sizes may be overwritten |
1887 // Check for both lower and upper case extension or image sub-sizes may be overwritten. |
1706 while ( file_exists($dir . "/$filename") || file_exists($dir . "/$filename2") ) { |
1888 while ( file_exists($dir . "/$filename") || file_exists($dir . "/$filename2") ) { |
1707 $new_number = $number + 1; |
1889 $new_number = $number + 1; |
1708 $filename = str_replace( "$number$ext", "$new_number$ext", $filename ); |
1890 $filename = str_replace( "$number$ext", "$new_number$ext", $filename ); |
1709 $filename2 = str_replace( "$number$ext2", "$new_number$ext2", $filename2 ); |
1891 $filename2 = str_replace( "$number$ext2", "$new_number$ext2", $filename2 ); |
1710 $number = $new_number; |
1892 $number = $new_number; |
1803 } |
1995 } |
1804 |
1996 |
1805 /** |
1997 /** |
1806 * Retrieve the file type based on the extension name. |
1998 * Retrieve the file type based on the extension name. |
1807 * |
1999 * |
1808 * @package WordPress |
|
1809 * @since 2.5.0 |
2000 * @since 2.5.0 |
1810 * @uses apply_filters() Calls 'ext2type' hook on default supported types. |
|
1811 * |
2001 * |
1812 * @param string $ext The extension to search. |
2002 * @param string $ext The extension to search. |
1813 * @return string|null The file type, example: audio, video, document, spreadsheet, etc. Null if not found. |
2003 * @return string|null The file type, example: audio, video, document, spreadsheet, etc. |
|
2004 * Null if not found. |
1814 */ |
2005 */ |
1815 function wp_ext2type( $ext ) { |
2006 function wp_ext2type( $ext ) { |
1816 $ext = strtolower( $ext ); |
2007 $ext = strtolower( $ext ); |
|
2008 |
|
2009 /** |
|
2010 * Filter file type based on the extension name. |
|
2011 * |
|
2012 * @since 2.5.0 |
|
2013 * |
|
2014 * @see wp_ext2type() |
|
2015 * |
|
2016 * @param array $ext2type Multi-dimensional array with extensions for a default set |
|
2017 * of file types. |
|
2018 */ |
1817 $ext2type = apply_filters( 'ext2type', array( |
2019 $ext2type = apply_filters( 'ext2type', array( |
1818 'image' => array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico' ), |
2020 'image' => array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico' ), |
1819 'audio' => array( 'aac', 'ac3', 'aif', 'aiff', 'm3a', 'm4a', 'm4b', 'mka', 'mp1', 'mp2', 'mp3', 'ogg', 'oga', 'ram', 'wav', 'wma' ), |
2021 'audio' => array( 'aac', 'ac3', 'aif', 'aiff', 'm3a', 'm4a', 'm4b', 'mka', 'mp1', 'mp2', 'mp3', 'ogg', 'oga', 'ram', 'wav', 'wma' ), |
1820 'video' => array( 'asf', 'avi', 'divx', 'dv', 'flv', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'mpv', 'ogm', 'ogv', 'qt', 'rm', 'vob', 'wmv' ), |
2022 'video' => array( '3g2', '3gp', '3gpp', 'asf', 'avi', 'divx', 'dv', 'flv', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'mpv', 'ogm', 'ogv', 'qt', 'rm', 'vob', 'wmv' ), |
1821 'document' => array( 'doc', 'docx', 'docm', 'dotm', 'odt', 'pages', 'pdf', 'rtf', 'wp', 'wpd' ), |
2023 'document' => array( 'doc', 'docx', 'docm', 'dotm', 'odt', 'pages', 'pdf', 'xps', 'oxps', 'rtf', 'wp', 'wpd', 'psd', 'xcf' ), |
1822 'spreadsheet' => array( 'numbers', 'ods', 'xls', 'xlsx', 'xlsm', 'xlsb' ), |
2024 'spreadsheet' => array( 'numbers', 'ods', 'xls', 'xlsx', 'xlsm', 'xlsb' ), |
1823 'interactive' => array( 'swf', 'key', 'ppt', 'pptx', 'pptm', 'pps', 'ppsx', 'ppsm', 'sldx', 'sldm', 'odp' ), |
2025 'interactive' => array( 'swf', 'key', 'ppt', 'pptx', 'pptm', 'pps', 'ppsx', 'ppsm', 'sldx', 'sldm', 'odp' ), |
1824 'text' => array( 'asc', 'csv', 'tsv', 'txt' ), |
2026 'text' => array( 'asc', 'csv', 'tsv', 'txt' ), |
1825 'archive' => array( 'bz2', 'cab', 'dmg', 'gz', 'rar', 'sea', 'sit', 'sqx', 'tar', 'tgz', 'zip', '7z' ), |
2027 'archive' => array( 'bz2', 'cab', 'dmg', 'gz', 'rar', 'sea', 'sit', 'sqx', 'tar', 'tgz', 'zip', '7z' ), |
1826 'code' => array( 'css', 'htm', 'html', 'php', 'js' ), |
2028 'code' => array( 'css', 'htm', 'html', 'php', 'js' ), |
1862 return compact( 'ext', 'type' ); |
2064 return compact( 'ext', 'type' ); |
1863 } |
2065 } |
1864 |
2066 |
1865 /** |
2067 /** |
1866 * Attempt to determine the real file type of a file. |
2068 * Attempt to determine the real file type of a file. |
|
2069 * |
1867 * If unable to, the file name extension will be used to determine type. |
2070 * If unable to, the file name extension will be used to determine type. |
1868 * |
2071 * |
1869 * If it's determined that the extension does not match the file's real type, |
2072 * If it's determined that the extension does not match the file's real type, |
1870 * then the "proper_filename" value will be set with a proper filename and extension. |
2073 * then the "proper_filename" value will be set with a proper filename and extension. |
1871 * |
2074 * |
1872 * Currently this function only supports validating images known to getimagesize(). |
2075 * Currently this function only supports validating images known to getimagesize(). |
1873 * |
2076 * |
1874 * @since 3.0.0 |
2077 * @since 3.0.0 |
1875 * |
2078 * |
1876 * @param string $file Full path to the file. |
2079 * @param string $file Full path to the file. |
1877 * @param string $filename The name of the file (may differ from $file due to $file being in a tmp directory) |
2080 * @param string $filename The name of the file (may differ from $file due to $file being |
1878 * @param array $mimes Optional. Key is the file extension with value as the mime type. |
2081 * in a tmp directory). |
1879 * @return array Values for the extension, MIME, and either a corrected filename or false if original $filename is valid |
2082 * @param array $mimes Optional. Key is the file extension with value as the mime type. |
|
2083 * @return array Values for the extension, MIME, and either a corrected filename or false |
|
2084 * if original $filename is valid. |
1880 */ |
2085 */ |
1881 function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) { |
2086 function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) { |
1882 |
2087 |
1883 $proper_filename = false; |
2088 $proper_filename = false; |
1884 |
2089 |
1885 // Do basic extension validation and MIME mapping |
2090 // Do basic extension validation and MIME mapping |
1886 $wp_filetype = wp_check_filetype( $filename, $mimes ); |
2091 $wp_filetype = wp_check_filetype( $filename, $mimes ); |
1887 extract( $wp_filetype ); |
2092 $ext = $wp_filetype['ext']; |
|
2093 $type = $wp_filetype['type']; |
1888 |
2094 |
1889 // We can't do any further validation without a file to work with |
2095 // We can't do any further validation without a file to work with |
1890 if ( ! file_exists( $file ) ) |
2096 if ( ! file_exists( $file ) ) { |
1891 return compact( 'ext', 'type', 'proper_filename' ); |
2097 return compact( 'ext', 'type', 'proper_filename' ); |
|
2098 } |
1892 |
2099 |
1893 // We're able to validate images using GD |
2100 // We're able to validate images using GD |
1894 if ( $type && 0 === strpos( $type, 'image/' ) && function_exists('getimagesize') ) { |
2101 if ( $type && 0 === strpos( $type, 'image/' ) && function_exists('getimagesize') ) { |
1895 |
2102 |
1896 // Attempt to figure out what type of image it actually is |
2103 // Attempt to figure out what type of image it actually is |
1897 $imgstats = @getimagesize( $file ); |
2104 $imgstats = @getimagesize( $file ); |
1898 |
2105 |
1899 // If getimagesize() knows what kind of image it really is and if the real MIME doesn't match the claimed MIME |
2106 // If getimagesize() knows what kind of image it really is and if the real MIME doesn't match the claimed MIME |
1900 if ( !empty($imgstats['mime']) && $imgstats['mime'] != $type ) { |
2107 if ( !empty($imgstats['mime']) && $imgstats['mime'] != $type ) { |
1901 // This is a simplified array of MIMEs that getimagesize() can detect and their extensions |
2108 /** |
1902 // You shouldn't need to use this filter, but it's here just in case |
2109 * Filter the list mapping image mime types to their respective extensions. |
|
2110 * |
|
2111 * @since 3.0.0 |
|
2112 * |
|
2113 * @param array $mime_to_ext Array of image mime types and their matching extensions. |
|
2114 */ |
1903 $mime_to_ext = apply_filters( 'getimagesize_mimes_to_exts', array( |
2115 $mime_to_ext = apply_filters( 'getimagesize_mimes_to_exts', array( |
1904 'image/jpeg' => 'jpg', |
2116 'image/jpeg' => 'jpg', |
1905 'image/png' => 'png', |
2117 'image/png' => 'png', |
1906 'image/gif' => 'gif', |
2118 'image/gif' => 'gif', |
1907 'image/bmp' => 'bmp', |
2119 'image/bmp' => 'bmp', |
1913 $filename_parts = explode( '.', $filename ); |
2125 $filename_parts = explode( '.', $filename ); |
1914 array_pop( $filename_parts ); |
2126 array_pop( $filename_parts ); |
1915 $filename_parts[] = $mime_to_ext[ $imgstats['mime'] ]; |
2127 $filename_parts[] = $mime_to_ext[ $imgstats['mime'] ]; |
1916 $new_filename = implode( '.', $filename_parts ); |
2128 $new_filename = implode( '.', $filename_parts ); |
1917 |
2129 |
1918 if ( $new_filename != $filename ) |
2130 if ( $new_filename != $filename ) { |
1919 $proper_filename = $new_filename; // Mark that it changed |
2131 $proper_filename = $new_filename; // Mark that it changed |
1920 |
2132 } |
1921 // Redefine the extension / MIME |
2133 // Redefine the extension / MIME |
1922 $wp_filetype = wp_check_filetype( $new_filename, $mimes ); |
2134 $wp_filetype = wp_check_filetype( $new_filename, $mimes ); |
1923 extract( $wp_filetype ); |
2135 $ext = $wp_filetype['ext']; |
|
2136 $type = $wp_filetype['type']; |
1924 } |
2137 } |
1925 } |
2138 } |
1926 } |
2139 } |
1927 |
2140 |
1928 // Let plugins try and validate other types of files |
2141 /** |
1929 // Should return an array in the style of array( 'ext' => $ext, 'type' => $type, 'proper_filename' => $proper_filename ) |
2142 * Filter the "real" file type of the given file. |
|
2143 * |
|
2144 * @since 3.0.0 |
|
2145 * |
|
2146 * @param array $wp_check_filetype_and_ext File data array containing 'ext', 'type', and |
|
2147 * 'proper_filename' keys. |
|
2148 * @param string $file Full path to the file. |
|
2149 * @param string $filename The name of the file (may differ from $file due to |
|
2150 * $file being in a tmp directory). |
|
2151 * @param array $mimes Key is the file extension with value as the mime type. |
|
2152 */ |
1930 return apply_filters( 'wp_check_filetype_and_ext', compact( 'ext', 'type', 'proper_filename' ), $file, $filename, $mimes ); |
2153 return apply_filters( 'wp_check_filetype_and_ext', compact( 'ext', 'type', 'proper_filename' ), $file, $filename, $mimes ); |
1931 } |
2154 } |
1932 |
2155 |
1933 /** |
2156 /** |
1934 * Retrieve list of mime types and file extensions. |
2157 * Retrieve list of mime types and file extensions. |
1935 * |
2158 * |
1936 * @since 3.5.0 |
2159 * @since 3.5.0 |
1937 * |
2160 * @since 4.2.0 Support was added for GIMP (xcf) files. |
1938 * @uses apply_filters() Calls 'mime_types' on returned array. This filter should |
|
1939 * be used to add types, not remove them. To remove types use the upload_mimes filter. |
|
1940 * |
2161 * |
1941 * @return array Array of mime types keyed by the file extension regex corresponding to those types. |
2162 * @return array Array of mime types keyed by the file extension regex corresponding to those types. |
1942 */ |
2163 */ |
1943 function wp_get_mime_types() { |
2164 function wp_get_mime_types() { |
1944 // Accepted MIME types are set here as PCRE unless provided. |
2165 /** |
|
2166 * Filter the list of mime types and file extensions. |
|
2167 * |
|
2168 * This filter should be used to add, not remove, mime types. To remove |
|
2169 * mime types, use the 'upload_mimes' filter. |
|
2170 * |
|
2171 * @since 3.5.0 |
|
2172 * |
|
2173 * @param array $wp_get_mime_types Mime types keyed by the file extension regex |
|
2174 * corresponding to those types. |
|
2175 */ |
1945 return apply_filters( 'mime_types', array( |
2176 return apply_filters( 'mime_types', array( |
1946 // Image formats |
2177 // Image formats. |
1947 'jpg|jpeg|jpe' => 'image/jpeg', |
2178 'jpg|jpeg|jpe' => 'image/jpeg', |
1948 'gif' => 'image/gif', |
2179 'gif' => 'image/gif', |
1949 'png' => 'image/png', |
2180 'png' => 'image/png', |
1950 'bmp' => 'image/bmp', |
2181 'bmp' => 'image/bmp', |
1951 'tif|tiff' => 'image/tiff', |
2182 'tiff|tif' => 'image/tiff', |
1952 'ico' => 'image/x-icon', |
2183 'ico' => 'image/x-icon', |
1953 // Video formats |
2184 // Video formats. |
1954 'asf|asx' => 'video/x-ms-asf', |
2185 'asf|asx' => 'video/x-ms-asf', |
1955 'wmv' => 'video/x-ms-wmv', |
2186 'wmv' => 'video/x-ms-wmv', |
1956 'wmx' => 'video/x-ms-wmx', |
2187 'wmx' => 'video/x-ms-wmx', |
1957 'wm' => 'video/x-ms-wm', |
2188 'wm' => 'video/x-ms-wm', |
1958 'avi' => 'video/avi', |
2189 'avi' => 'video/avi', |
1962 'mpeg|mpg|mpe' => 'video/mpeg', |
2193 'mpeg|mpg|mpe' => 'video/mpeg', |
1963 'mp4|m4v' => 'video/mp4', |
2194 'mp4|m4v' => 'video/mp4', |
1964 'ogv' => 'video/ogg', |
2195 'ogv' => 'video/ogg', |
1965 'webm' => 'video/webm', |
2196 'webm' => 'video/webm', |
1966 'mkv' => 'video/x-matroska', |
2197 'mkv' => 'video/x-matroska', |
1967 // Text formats |
2198 '3gp|3gpp' => 'video/3gpp', // Can also be audio |
1968 'txt|asc|c|cc|h' => 'text/plain', |
2199 '3g2|3gp2' => 'video/3gpp2', // Can also be audio |
|
2200 // Text formats. |
|
2201 'txt|asc|c|cc|h|srt' => 'text/plain', |
1969 'csv' => 'text/csv', |
2202 'csv' => 'text/csv', |
1970 'tsv' => 'text/tab-separated-values', |
2203 'tsv' => 'text/tab-separated-values', |
1971 'ics' => 'text/calendar', |
2204 'ics' => 'text/calendar', |
1972 'rtx' => 'text/richtext', |
2205 'rtx' => 'text/richtext', |
1973 'css' => 'text/css', |
2206 'css' => 'text/css', |
1974 'htm|html' => 'text/html', |
2207 'htm|html' => 'text/html', |
1975 // Audio formats |
2208 'vtt' => 'text/vtt', |
|
2209 'dfxp' => 'application/ttaf+xml', |
|
2210 // Audio formats. |
1976 'mp3|m4a|m4b' => 'audio/mpeg', |
2211 'mp3|m4a|m4b' => 'audio/mpeg', |
1977 'ra|ram' => 'audio/x-realaudio', |
2212 'ra|ram' => 'audio/x-realaudio', |
1978 'wav' => 'audio/wav', |
2213 'wav' => 'audio/wav', |
1979 'ogg|oga' => 'audio/ogg', |
2214 'ogg|oga' => 'audio/ogg', |
1980 'mid|midi' => 'audio/midi', |
2215 'mid|midi' => 'audio/midi', |
1981 'wma' => 'audio/x-ms-wma', |
2216 'wma' => 'audio/x-ms-wma', |
1982 'wax' => 'audio/x-ms-wax', |
2217 'wax' => 'audio/x-ms-wax', |
1983 'mka' => 'audio/x-matroska', |
2218 'mka' => 'audio/x-matroska', |
1984 // Misc application formats |
2219 // Misc application formats. |
1985 'rtf' => 'application/rtf', |
2220 'rtf' => 'application/rtf', |
1986 'js' => 'application/javascript', |
2221 'js' => 'application/javascript', |
1987 'pdf' => 'application/pdf', |
2222 'pdf' => 'application/pdf', |
1988 'swf' => 'application/x-shockwave-flash', |
2223 'swf' => 'application/x-shockwave-flash', |
1989 'class' => 'application/java', |
2224 'class' => 'application/java', |
1991 'zip' => 'application/zip', |
2226 'zip' => 'application/zip', |
1992 'gz|gzip' => 'application/x-gzip', |
2227 'gz|gzip' => 'application/x-gzip', |
1993 'rar' => 'application/rar', |
2228 'rar' => 'application/rar', |
1994 '7z' => 'application/x-7z-compressed', |
2229 '7z' => 'application/x-7z-compressed', |
1995 'exe' => 'application/x-msdownload', |
2230 'exe' => 'application/x-msdownload', |
1996 // MS Office formats |
2231 'psd' => 'application/octet-stream', |
|
2232 'xcf' => 'application/octet-stream', |
|
2233 // MS Office formats. |
1997 'doc' => 'application/msword', |
2234 'doc' => 'application/msword', |
1998 'pot|pps|ppt' => 'application/vnd.ms-powerpoint', |
2235 'pot|pps|ppt' => 'application/vnd.ms-powerpoint', |
1999 'wri' => 'application/vnd.ms-write', |
2236 'wri' => 'application/vnd.ms-write', |
2000 'xla|xls|xlt|xlw' => 'application/vnd.ms-excel', |
2237 'xla|xls|xlt|xlw' => 'application/vnd.ms-excel', |
2001 'mdb' => 'application/vnd.ms-access', |
2238 'mdb' => 'application/vnd.ms-access', |
2018 'potm' => 'application/vnd.ms-powerpoint.template.macroEnabled.12', |
2255 'potm' => 'application/vnd.ms-powerpoint.template.macroEnabled.12', |
2019 'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12', |
2256 'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12', |
2020 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide', |
2257 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide', |
2021 'sldm' => 'application/vnd.ms-powerpoint.slide.macroEnabled.12', |
2258 'sldm' => 'application/vnd.ms-powerpoint.slide.macroEnabled.12', |
2022 'onetoc|onetoc2|onetmp|onepkg' => 'application/onenote', |
2259 'onetoc|onetoc2|onetmp|onepkg' => 'application/onenote', |
2023 // OpenOffice formats |
2260 'oxps' => 'application/oxps', |
|
2261 'xps' => 'application/vnd.ms-xpsdocument', |
|
2262 // OpenOffice formats. |
2024 'odt' => 'application/vnd.oasis.opendocument.text', |
2263 'odt' => 'application/vnd.oasis.opendocument.text', |
2025 'odp' => 'application/vnd.oasis.opendocument.presentation', |
2264 'odp' => 'application/vnd.oasis.opendocument.presentation', |
2026 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', |
2265 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', |
2027 'odg' => 'application/vnd.oasis.opendocument.graphics', |
2266 'odg' => 'application/vnd.oasis.opendocument.graphics', |
2028 'odc' => 'application/vnd.oasis.opendocument.chart', |
2267 'odc' => 'application/vnd.oasis.opendocument.chart', |
2029 'odb' => 'application/vnd.oasis.opendocument.database', |
2268 'odb' => 'application/vnd.oasis.opendocument.database', |
2030 'odf' => 'application/vnd.oasis.opendocument.formula', |
2269 'odf' => 'application/vnd.oasis.opendocument.formula', |
2031 // WordPerfect formats |
2270 // WordPerfect formats. |
2032 'wp|wpd' => 'application/wordperfect', |
2271 'wp|wpd' => 'application/wordperfect', |
2033 // iWork formats |
2272 // iWork formats. |
2034 'key' => 'application/vnd.apple.keynote', |
2273 'key' => 'application/vnd.apple.keynote', |
2035 'numbers' => 'application/vnd.apple.numbers', |
2274 'numbers' => 'application/vnd.apple.numbers', |
2036 'pages' => 'application/vnd.apple.pages', |
2275 'pages' => 'application/vnd.apple.pages', |
2037 ) ); |
2276 ) ); |
2038 } |
2277 } |
2039 /** |
2278 /** |
2040 * Retrieve list of allowed mime types and file extensions. |
2279 * Retrieve list of allowed mime types and file extensions. |
2041 * |
2280 * |
2042 * @since 2.8.6 |
2281 * @since 2.8.6 |
2043 * |
2282 * |
2044 * @uses apply_filters() Calls 'upload_mimes' on returned array |
|
2045 * @uses wp_get_upload_mime_types() to fetch the list of mime types |
|
2046 * |
|
2047 * @param int|WP_User $user Optional. User to check. Defaults to current user. |
2283 * @param int|WP_User $user Optional. User to check. Defaults to current user. |
2048 * @return array Array of mime types keyed by the file extension regex corresponding to those types. |
2284 * @return array Array of mime types keyed by the file extension regex corresponding |
|
2285 * to those types. |
2049 */ |
2286 */ |
2050 function get_allowed_mime_types( $user = null ) { |
2287 function get_allowed_mime_types( $user = null ) { |
2051 $t = wp_get_mime_types(); |
2288 $t = wp_get_mime_types(); |
2052 |
2289 |
2053 unset( $t['swf'], $t['exe'] ); |
2290 unset( $t['swf'], $t['exe'] ); |
2055 $unfiltered = $user ? user_can( $user, 'unfiltered_html' ) : current_user_can( 'unfiltered_html' ); |
2292 $unfiltered = $user ? user_can( $user, 'unfiltered_html' ) : current_user_can( 'unfiltered_html' ); |
2056 |
2293 |
2057 if ( empty( $unfiltered ) ) |
2294 if ( empty( $unfiltered ) ) |
2058 unset( $t['htm|html'] ); |
2295 unset( $t['htm|html'] ); |
2059 |
2296 |
|
2297 /** |
|
2298 * Filter list of allowed mime types and file extensions. |
|
2299 * |
|
2300 * @since 2.0.0 |
|
2301 * |
|
2302 * @param array $t Mime types keyed by the file extension regex corresponding to |
|
2303 * those types. 'swf' and 'exe' removed from full list. 'htm|html' also |
|
2304 * removed depending on '$user' capabilities. |
|
2305 * @param int|WP_User|null $user User ID, User object or null if not provided (indicates current user). |
|
2306 */ |
2060 return apply_filters( 'upload_mimes', $t, $user ); |
2307 return apply_filters( 'upload_mimes', $t, $user ); |
2061 } |
2308 } |
2062 |
2309 |
2063 /** |
2310 /** |
2064 * Display "Are You Sure" message to confirm the action being taken. |
2311 * Display "Are You Sure" message to confirm the action being taken. |
2065 * |
2312 * |
2066 * If the action has the nonce explain message, then it will be displayed along |
2313 * If the action has the nonce explain message, then it will be displayed |
2067 * with the "Are you sure?" message. |
2314 * along with the "Are you sure?" message. |
2068 * |
2315 * |
2069 * @package WordPress |
|
2070 * @subpackage Security |
|
2071 * @since 2.0.4 |
2316 * @since 2.0.4 |
2072 * |
2317 * |
2073 * @param string $action The nonce action. |
2318 * @param string $action The nonce action. |
2074 */ |
2319 */ |
2075 function wp_nonce_ays( $action ) { |
2320 function wp_nonce_ays( $action ) { |
2076 $title = __( 'WordPress Failure Notice' ); |
|
2077 if ( 'log-out' == $action ) { |
2321 if ( 'log-out' == $action ) { |
2078 $html = sprintf( __( 'You are attempting to log out of %s' ), get_bloginfo( 'name' ) ) . '</p><p>'; |
2322 $html = sprintf( __( 'You are attempting to log out of %s' ), get_bloginfo( 'name' ) ) . '</p><p>'; |
2079 $html .= sprintf( __( "Do you really want to <a href='%s'>log out</a>?"), wp_logout_url() ); |
2323 $redirect_to = isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : ''; |
|
2324 $html .= sprintf( __( "Do you really want to <a href='%s'>log out</a>?"), wp_logout_url( $redirect_to ) ); |
2080 } else { |
2325 } else { |
2081 $html = __( 'Are you sure you want to do this?' ); |
2326 $html = __( 'Are you sure you want to do this?' ); |
2082 if ( wp_get_referer() ) |
2327 if ( wp_get_referer() ) |
2083 $html .= "</p><p><a href='" . esc_url( remove_query_arg( 'updated', wp_get_referer() ) ) . "'>" . __( 'Please try again.' ) . "</a>"; |
2328 $html .= "</p><p><a href='" . esc_url( remove_query_arg( 'updated', wp_get_referer() ) ) . "'>" . __( 'Please try again.' ) . "</a>"; |
2084 } |
2329 } |
2085 |
2330 |
2086 wp_die( $html, $title, array('response' => 403) ); |
2331 wp_die( $html, __( 'WordPress Failure Notice' ), 403 ); |
2087 } |
2332 } |
2088 |
2333 |
2089 /** |
2334 /** |
2090 * Kill WordPress execution and display HTML message with error message. |
2335 * Kill WordPress execution and display HTML message with error message. |
2091 * |
2336 * |
2092 * This function complements the die() PHP function. The difference is that |
2337 * This function complements the `die()` PHP function. The difference is that |
2093 * HTML will be displayed to the user. It is recommended to use this function |
2338 * HTML will be displayed to the user. It is recommended to use this function |
2094 * only, when the execution should not continue any further. It is not |
2339 * only when the execution should not continue any further. It is not recommended |
2095 * recommended to call this function very often and try to handle as many errors |
2340 * to call this function very often, and try to handle as many errors as possible |
2096 * as possible silently. |
2341 * silently or more gracefully. |
|
2342 * |
|
2343 * As a shorthand, the desired HTTP response code may be passed as an integer to |
|
2344 * the `$title` parameter (the default title would apply) or the `$args` parameter. |
2097 * |
2345 * |
2098 * @since 2.0.4 |
2346 * @since 2.0.4 |
2099 * |
2347 * @since 4.1.0 The `$title` and `$args` parameters were changed to optionally accept |
2100 * @param string $message Error message. |
2348 * an integer to be used as the response code. |
2101 * @param string $title Error title. |
2349 * |
2102 * @param string|array $args Optional arguments to control behavior. |
2350 * @param string|WP_Error $message Optional. Error message. If this is a {@see WP_Error} object, |
|
2351 * the error's messages are used. Default empty. |
|
2352 * @param string|int $title Optional. Error title. If `$message` is a `WP_Error` object, |
|
2353 * error data with the key 'title' may be used to specify the title. |
|
2354 * If `$title` is an integer, then it is treated as the response |
|
2355 * code. Default empty. |
|
2356 * @param string|array|int $args { |
|
2357 * Optional. Arguments to control behavior. If `$args` is an integer, then it is treated |
|
2358 * as the response code. Default empty array. |
|
2359 * |
|
2360 * @type int $response The HTTP response code. Default 500. |
|
2361 * @type bool $back_link Whether to include a link to go back. Default false. |
|
2362 * @type string $text_direction The text direction. This is only useful internally, when WordPress |
|
2363 * is still loading and the site's locale is not set up yet. Accepts 'rtl'. |
|
2364 * Default is the value of {@see is_rtl()}. |
|
2365 * } |
2103 */ |
2366 */ |
2104 function wp_die( $message = '', $title = '', $args = array() ) { |
2367 function wp_die( $message = '', $title = '', $args = array() ) { |
2105 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) |
2368 |
|
2369 if ( is_int( $args ) ) { |
|
2370 $args = array( 'response' => $args ); |
|
2371 } elseif ( is_int( $title ) ) { |
|
2372 $args = array( 'response' => $title ); |
|
2373 $title = ''; |
|
2374 } |
|
2375 |
|
2376 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
|
2377 /** |
|
2378 * Filter callback for killing WordPress execution for AJAX requests. |
|
2379 * |
|
2380 * @since 3.4.0 |
|
2381 * |
|
2382 * @param callback $function Callback function name. |
|
2383 */ |
2106 $function = apply_filters( 'wp_die_ajax_handler', '_ajax_wp_die_handler' ); |
2384 $function = apply_filters( 'wp_die_ajax_handler', '_ajax_wp_die_handler' ); |
2107 elseif ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) |
2385 } elseif ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) { |
|
2386 /** |
|
2387 * Filter callback for killing WordPress execution for XML-RPC requests. |
|
2388 * |
|
2389 * @since 3.4.0 |
|
2390 * |
|
2391 * @param callback $function Callback function name. |
|
2392 */ |
2108 $function = apply_filters( 'wp_die_xmlrpc_handler', '_xmlrpc_wp_die_handler' ); |
2393 $function = apply_filters( 'wp_die_xmlrpc_handler', '_xmlrpc_wp_die_handler' ); |
2109 else |
2394 } else { |
|
2395 /** |
|
2396 * Filter callback for killing WordPress execution for all non-AJAX, non-XML-RPC requests. |
|
2397 * |
|
2398 * @since 3.0.0 |
|
2399 * |
|
2400 * @param callback $function Callback function name. |
|
2401 */ |
2110 $function = apply_filters( 'wp_die_handler', '_default_wp_die_handler' ); |
2402 $function = apply_filters( 'wp_die_handler', '_default_wp_die_handler' ); |
|
2403 } |
2111 |
2404 |
2112 call_user_func( $function, $message, $title, $args ); |
2405 call_user_func( $function, $message, $title, $args ); |
2113 } |
2406 } |
2114 |
2407 |
2115 /** |
2408 /** |
2226 } |
2518 } |
2227 a:hover { |
2519 a:hover { |
2228 color: #D54E21; |
2520 color: #D54E21; |
2229 } |
2521 } |
2230 .button { |
2522 .button { |
|
2523 background: #f7f7f7; |
|
2524 border: 1px solid #cccccc; |
|
2525 color: #555; |
2231 display: inline-block; |
2526 display: inline-block; |
2232 text-decoration: none; |
2527 text-decoration: none; |
2233 font-size: 14px; |
2528 font-size: 13px; |
2234 line-height: 23px; |
2529 line-height: 26px; |
2235 height: 24px; |
2530 height: 28px; |
2236 margin: 0; |
2531 margin: 0; |
2237 padding: 0 10px 1px; |
2532 padding: 0 10px 1px; |
2238 cursor: pointer; |
2533 cursor: pointer; |
2239 border-width: 1px; |
|
2240 border-style: solid; |
|
2241 -webkit-border-radius: 3px; |
2534 -webkit-border-radius: 3px; |
|
2535 -webkit-appearance: none; |
2242 border-radius: 3px; |
2536 border-radius: 3px; |
2243 white-space: nowrap; |
2537 white-space: nowrap; |
2244 -webkit-box-sizing: border-box; |
2538 -webkit-box-sizing: border-box; |
2245 -moz-box-sizing: border-box; |
2539 -moz-box-sizing: border-box; |
2246 box-sizing: border-box; |
2540 box-sizing: border-box; |
2247 background: #f3f3f3; |
2541 |
2248 background-image: -webkit-gradient(linear, left top, left bottom, from(#fefefe), to(#f4f4f4)); |
2542 -webkit-box-shadow: inset 0 1px 0 #fff, 0 1px 0 rgba(0,0,0,.08); |
2249 background-image: -webkit-linear-gradient(top, #fefefe, #f4f4f4); |
2543 box-shadow: inset 0 1px 0 #fff, 0 1px 0 rgba(0,0,0,.08); |
2250 background-image: -moz-linear-gradient(top, #fefefe, #f4f4f4); |
2544 vertical-align: top; |
2251 background-image: -o-linear-gradient(top, #fefefe, #f4f4f4); |
|
2252 background-image: linear-gradient(to bottom, #fefefe, #f4f4f4); |
|
2253 border-color: #bbb; |
|
2254 color: #333; |
|
2255 text-shadow: 0 1px 0 #fff; |
|
2256 } |
2545 } |
2257 |
2546 |
2258 .button.button-large { |
2547 .button.button-large { |
2259 height: 29px; |
2548 height: 29px; |
2260 line-height: 28px; |
2549 line-height: 28px; |
2261 padding: 0 12px; |
2550 padding: 0 12px; |
2262 } |
2551 } |
2263 |
2552 |
2264 .button:hover, |
2553 .button:hover, |
2265 .button:focus { |
2554 .button:focus { |
2266 background: #f3f3f3; |
2555 background: #fafafa; |
2267 background-image: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#f3f3f3)); |
|
2268 background-image: -webkit-linear-gradient(top, #fff, #f3f3f3); |
|
2269 background-image: -moz-linear-gradient(top, #fff, #f3f3f3); |
|
2270 background-image: -ms-linear-gradient(top, #fff, #f3f3f3); |
|
2271 background-image: -o-linear-gradient(top, #fff, #f3f3f3); |
|
2272 background-image: linear-gradient(to bottom, #fff, #f3f3f3); |
|
2273 border-color: #999; |
2556 border-color: #999; |
2274 color: #222; |
2557 color: #222; |
2275 } |
2558 } |
2276 |
2559 |
2277 .button:focus { |
2560 .button:focus { |
2278 -webkit-box-shadow: 1px 1px 1px rgba(0,0,0,.2); |
2561 -webkit-box-shadow: 1px 1px 1px rgba(0,0,0,.2); |
2279 box-shadow: 1px 1px 1px rgba(0,0,0,.2); |
2562 box-shadow: 1px 1px 1px rgba(0,0,0,.2); |
2280 } |
2563 } |
2281 |
2564 |
2282 .button:active { |
2565 .button:active { |
2283 outline: none; |
|
2284 background: #eee; |
2566 background: #eee; |
2285 background-image: -webkit-gradient(linear, left top, left bottom, from(#f4f4f4), to(#fefefe)); |
|
2286 background-image: -webkit-linear-gradient(top, #f4f4f4, #fefefe); |
|
2287 background-image: -moz-linear-gradient(top, #f4f4f4, #fefefe); |
|
2288 background-image: -ms-linear-gradient(top, #f4f4f4, #fefefe); |
|
2289 background-image: -o-linear-gradient(top, #f4f4f4, #fefefe); |
|
2290 background-image: linear-gradient(to bottom, #f4f4f4, #fefefe); |
|
2291 border-color: #999; |
2567 border-color: #999; |
2292 color: #333; |
2568 color: #333; |
2293 text-shadow: 0 -1px 0 #fff; |
|
2294 -webkit-box-shadow: inset 0 2px 5px -3px rgba( 0, 0, 0, 0.5 ); |
2569 -webkit-box-shadow: inset 0 2px 5px -3px rgba( 0, 0, 0, 0.5 ); |
2295 box-shadow: inset 0 2px 5px -3px rgba( 0, 0, 0, 0.5 ); |
2570 box-shadow: inset 0 2px 5px -3px rgba( 0, 0, 0, 0.5 ); |
2296 } |
2571 } |
2297 |
2572 |
2298 <?php if ( 'rtl' == $text_direction ) : ?> |
2573 <?php if ( 'rtl' == $text_direction ) : ?> |
2356 * This is the handler for wp_die when processing APP requests. |
2631 * This is the handler for wp_die when processing APP requests. |
2357 * |
2632 * |
2358 * @since 3.4.0 |
2633 * @since 3.4.0 |
2359 * @access private |
2634 * @access private |
2360 * |
2635 * |
2361 * @param string $message Optional. Response to print. |
2636 * @param string $message Optional. Response to print. Default empty. |
2362 */ |
2637 */ |
2363 function _scalar_wp_die_handler( $message = '' ) { |
2638 function _scalar_wp_die_handler( $message = '' ) { |
2364 if ( is_scalar( $message ) ) |
2639 if ( is_scalar( $message ) ) |
2365 die( (string) $message ); |
2640 die( (string) $message ); |
2366 die(); |
2641 die(); |
2367 } |
2642 } |
2368 |
2643 |
2369 /** |
2644 /** |
|
2645 * Encode a variable into JSON, with some sanity checks. |
|
2646 * |
|
2647 * @since 4.1.0 |
|
2648 * |
|
2649 * @param mixed $data Variable (usually an array or object) to encode as JSON. |
|
2650 * @param int $options Optional. Options to be passed to json_encode(). Default 0. |
|
2651 * @param int $depth Optional. Maximum depth to walk through $data. Must be |
|
2652 * greater than 0. Default 512. |
|
2653 * @return bool|string The JSON encoded string, or false if it cannot be encoded. |
|
2654 */ |
|
2655 function wp_json_encode( $data, $options = 0, $depth = 512 ) { |
|
2656 /* |
|
2657 * json_encode() has had extra params added over the years. |
|
2658 * $options was added in 5.3, and $depth in 5.5. |
|
2659 * We need to make sure we call it with the correct arguments. |
|
2660 */ |
|
2661 if ( version_compare( PHP_VERSION, '5.5', '>=' ) ) { |
|
2662 $args = array( $data, $options, $depth ); |
|
2663 } elseif ( version_compare( PHP_VERSION, '5.3', '>=' ) ) { |
|
2664 $args = array( $data, $options ); |
|
2665 } else { |
|
2666 $args = array( $data ); |
|
2667 } |
|
2668 |
|
2669 $json = call_user_func_array( 'json_encode', $args ); |
|
2670 |
|
2671 // If json_encode() was successful, no need to do more sanity checking. |
|
2672 // ... unless we're in an old version of PHP, and json_encode() returned |
|
2673 // a string containing 'null'. Then we need to do more sanity checking. |
|
2674 if ( false !== $json && ( version_compare( PHP_VERSION, '5.5', '>=' ) || false === strpos( $json, 'null' ) ) ) { |
|
2675 return $json; |
|
2676 } |
|
2677 |
|
2678 try { |
|
2679 $args[0] = _wp_json_sanity_check( $data, $depth ); |
|
2680 } catch ( Exception $e ) { |
|
2681 return false; |
|
2682 } |
|
2683 |
|
2684 return call_user_func_array( 'json_encode', $args ); |
|
2685 } |
|
2686 |
|
2687 /** |
|
2688 * Perform sanity checks on data that shall be encoded to JSON. |
|
2689 * |
|
2690 * @ignore |
|
2691 * @since 4.1.0 |
|
2692 * @access private |
|
2693 * |
|
2694 * @see wp_json_encode() |
|
2695 * |
|
2696 * @param mixed $data Variable (usually an array or object) to encode as JSON. |
|
2697 * @param int $depth Maximum depth to walk through $data. Must be greater than 0. |
|
2698 * @return mixed The sanitized data that shall be encoded to JSON. |
|
2699 */ |
|
2700 function _wp_json_sanity_check( $data, $depth ) { |
|
2701 if ( $depth < 0 ) { |
|
2702 throw new Exception( 'Reached depth limit' ); |
|
2703 } |
|
2704 |
|
2705 if ( is_array( $data ) ) { |
|
2706 $output = array(); |
|
2707 foreach ( $data as $id => $el ) { |
|
2708 // Don't forget to sanitize the ID! |
|
2709 if ( is_string( $id ) ) { |
|
2710 $clean_id = _wp_json_convert_string( $id ); |
|
2711 } else { |
|
2712 $clean_id = $id; |
|
2713 } |
|
2714 |
|
2715 // Check the element type, so that we're only recursing if we really have to. |
|
2716 if ( is_array( $el ) || is_object( $el ) ) { |
|
2717 $output[ $clean_id ] = _wp_json_sanity_check( $el, $depth - 1 ); |
|
2718 } elseif ( is_string( $el ) ) { |
|
2719 $output[ $clean_id ] = _wp_json_convert_string( $el ); |
|
2720 } else { |
|
2721 $output[ $clean_id ] = $el; |
|
2722 } |
|
2723 } |
|
2724 } elseif ( is_object( $data ) ) { |
|
2725 $output = new stdClass; |
|
2726 foreach ( $data as $id => $el ) { |
|
2727 if ( is_string( $id ) ) { |
|
2728 $clean_id = _wp_json_convert_string( $id ); |
|
2729 } else { |
|
2730 $clean_id = $id; |
|
2731 } |
|
2732 |
|
2733 if ( is_array( $el ) || is_object( $el ) ) { |
|
2734 $output->$clean_id = _wp_json_sanity_check( $el, $depth - 1 ); |
|
2735 } elseif ( is_string( $el ) ) { |
|
2736 $output->$clean_id = _wp_json_convert_string( $el ); |
|
2737 } else { |
|
2738 $output->$clean_id = $el; |
|
2739 } |
|
2740 } |
|
2741 } elseif ( is_string( $data ) ) { |
|
2742 return _wp_json_convert_string( $data ); |
|
2743 } else { |
|
2744 return $data; |
|
2745 } |
|
2746 |
|
2747 return $output; |
|
2748 } |
|
2749 |
|
2750 /** |
|
2751 * Convert a string to UTF-8, so that it can be safely encoded to JSON. |
|
2752 * |
|
2753 * @ignore |
|
2754 * @since 4.1.0 |
|
2755 * @access private |
|
2756 * |
|
2757 * @see _wp_json_sanity_check() |
|
2758 * |
|
2759 * @param string $string The string which is to be converted. |
|
2760 * @return string The checked string. |
|
2761 */ |
|
2762 function _wp_json_convert_string( $string ) { |
|
2763 static $use_mb = null; |
|
2764 if ( is_null( $use_mb ) ) { |
|
2765 $use_mb = function_exists( 'mb_convert_encoding' ); |
|
2766 } |
|
2767 |
|
2768 if ( $use_mb ) { |
|
2769 $encoding = mb_detect_encoding( $string, mb_detect_order(), true ); |
|
2770 if ( $encoding ) { |
|
2771 return mb_convert_encoding( $string, 'UTF-8', $encoding ); |
|
2772 } else { |
|
2773 return mb_convert_encoding( $string, 'UTF-8', 'UTF-8' ); |
|
2774 } |
|
2775 } else { |
|
2776 return wp_check_invalid_utf8( $string, true ); |
|
2777 } |
|
2778 } |
|
2779 |
|
2780 /** |
2370 * Send a JSON response back to an Ajax request. |
2781 * Send a JSON response back to an Ajax request. |
2371 * |
2782 * |
2372 * @since 3.5.0 |
2783 * @since 3.5.0 |
2373 * |
2784 * |
2374 * @param mixed $response Variable (usually an array or object) to encode as JSON, then print and die. |
2785 * @param mixed $response Variable (usually an array or object) to encode as JSON, |
|
2786 * then print and die. |
2375 */ |
2787 */ |
2376 function wp_send_json( $response ) { |
2788 function wp_send_json( $response ) { |
2377 @header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) ); |
2789 @header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) ); |
2378 echo json_encode( $response ); |
2790 echo wp_json_encode( $response ); |
2379 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) |
2791 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) |
2380 wp_die(); |
2792 wp_die(); |
2381 else |
2793 else |
2382 die; |
2794 die; |
2383 } |
2795 } |
2399 } |
2811 } |
2400 |
2812 |
2401 /** |
2813 /** |
2402 * Send a JSON response back to an Ajax request, indicating failure. |
2814 * Send a JSON response back to an Ajax request, indicating failure. |
2403 * |
2815 * |
|
2816 * If the `$data` parameter is a {@see WP_Error} object, the errors |
|
2817 * within the object are processed and output as an array of error |
|
2818 * codes and corresponding messages. All other types are output |
|
2819 * without further processing. |
|
2820 * |
2404 * @since 3.5.0 |
2821 * @since 3.5.0 |
|
2822 * @since 4.1.0 The `$data` parameter is now processed if a {@see WP_Error} |
|
2823 * object is passed in. |
2405 * |
2824 * |
2406 * @param mixed $data Data to encode as JSON, then print and die. |
2825 * @param mixed $data Data to encode as JSON, then print and die. |
2407 */ |
2826 */ |
2408 function wp_send_json_error( $data = null ) { |
2827 function wp_send_json_error( $data = null ) { |
2409 $response = array( 'success' => false ); |
2828 $response = array( 'success' => false ); |
2410 |
2829 |
2411 if ( isset( $data ) ) |
2830 if ( isset( $data ) ) { |
2412 $response['data'] = $data; |
2831 if ( is_wp_error( $data ) ) { |
|
2832 $result = array(); |
|
2833 foreach ( $data->errors as $code => $messages ) { |
|
2834 foreach ( $messages as $message ) { |
|
2835 $result[] = array( 'code' => $code, 'message' => $message ); |
|
2836 } |
|
2837 } |
|
2838 |
|
2839 $response['data'] = $result; |
|
2840 } else { |
|
2841 $response['data'] = $data; |
|
2842 } |
|
2843 } |
2413 |
2844 |
2414 wp_send_json( $response ); |
2845 wp_send_json( $response ); |
2415 } |
2846 } |
2416 |
2847 |
2417 /** |
2848 /** |
2418 * Retrieve the WordPress home page URL. |
2849 * Retrieve the WordPress home page URL. |
2419 * |
2850 * |
2420 * If the constant named 'WP_HOME' exists, then it will be used and returned by |
2851 * If the constant named 'WP_HOME' exists, then it will be used and returned |
2421 * the function. This can be used to counter the redirection on your local |
2852 * by the function. This can be used to counter the redirection on your local |
2422 * development environment. |
2853 * development environment. |
2423 * |
2854 * |
|
2855 * @since 2.2.0 |
2424 * @access private |
2856 * @access private |
2425 * @package WordPress |
2857 * |
2426 * @since 2.2.0 |
2858 * @see WP_HOME |
2427 * |
2859 * |
2428 * @param string $url URL for the home location |
2860 * @param string $url URL for the home location. |
2429 * @return string Homepage location. |
2861 * @return string Homepage location. |
2430 */ |
2862 */ |
2431 function _config_wp_home( $url = '' ) { |
2863 function _config_wp_home( $url = '' ) { |
2432 if ( defined( 'WP_HOME' ) ) |
2864 if ( defined( 'WP_HOME' ) ) |
2433 return untrailingslashit( WP_HOME ); |
2865 return untrailingslashit( WP_HOME ); |
2436 |
2868 |
2437 /** |
2869 /** |
2438 * Retrieve the WordPress site URL. |
2870 * Retrieve the WordPress site URL. |
2439 * |
2871 * |
2440 * If the constant named 'WP_SITEURL' is defined, then the value in that |
2872 * If the constant named 'WP_SITEURL' is defined, then the value in that |
2441 * constant will always be returned. This can be used for debugging a site on |
2873 * constant will always be returned. This can be used for debugging a site |
2442 * your localhost while not having to change the database to your URL. |
2874 * on your localhost while not having to change the database to your URL. |
2443 * |
2875 * |
|
2876 * @since 2.2.0 |
2444 * @access private |
2877 * @access private |
2445 * @package WordPress |
2878 * |
2446 * @since 2.2.0 |
2879 * @see WP_SITEURL |
2447 * |
2880 * |
2448 * @param string $url URL to set the WordPress site location. |
2881 * @param string $url URL to set the WordPress site location. |
2449 * @return string The WordPress Site URL |
2882 * @return string The WordPress Site URL. |
2450 */ |
2883 */ |
2451 function _config_wp_siteurl( $url = '' ) { |
2884 function _config_wp_siteurl( $url = '' ) { |
2452 if ( defined( 'WP_SITEURL' ) ) |
2885 if ( defined( 'WP_SITEURL' ) ) |
2453 return untrailingslashit( WP_SITEURL ); |
2886 return untrailingslashit( WP_SITEURL ); |
2454 return $url; |
2887 return $url; |
2455 } |
2888 } |
2456 |
2889 |
2457 /** |
2890 /** |
2458 * Set the localized direction for MCE plugin. |
2891 * Set the localized direction for MCE plugin. |
2459 * |
2892 * |
2460 * Will only set the direction to 'rtl', if the WordPress locale has the text |
2893 * Will only set the direction to 'rtl', if the WordPress locale has |
2461 * direction set to 'rtl'. |
2894 * the text direction set to 'rtl'. |
2462 * |
2895 * |
2463 * Fills in the 'directionality', 'plugins', and 'theme_advanced_button1' array |
2896 * Fills in the 'directionality' setting, enables the 'directionality' |
2464 * keys. These keys are then returned in the $input array. |
2897 * plugin, and adds the 'ltr' button to 'toolbar1', formerly |
2465 * |
2898 * 'theme_advanced_buttons1' array keys. These keys are then returned |
|
2899 * in the $input (TinyMCE settings) array. |
|
2900 * |
|
2901 * @since 2.1.0 |
2466 * @access private |
2902 * @access private |
2467 * @package WordPress |
2903 * |
2468 * @subpackage MCE |
2904 * @param array $input MCE settings array. |
2469 * @since 2.1.0 |
|
2470 * |
|
2471 * @param array $input MCE plugin array. |
|
2472 * @return array Direction set for 'rtl', if needed by locale. |
2905 * @return array Direction set for 'rtl', if needed by locale. |
2473 */ |
2906 */ |
2474 function _mce_set_direction( $input ) { |
2907 function _mce_set_direction( $input ) { |
2475 if ( is_rtl() ) { |
2908 if ( is_rtl() ) { |
2476 $input['directionality'] = 'rtl'; |
2909 $input['directionality'] = 'rtl'; |
2477 $input['plugins'] .= ',directionality'; |
2910 |
2478 $input['theme_advanced_buttons1'] .= ',ltr'; |
2911 if ( ! empty( $input['plugins'] ) && strpos( $input['plugins'], 'directionality' ) === false ) { |
|
2912 $input['plugins'] .= ',directionality'; |
|
2913 } |
|
2914 |
|
2915 if ( ! empty( $input['toolbar1'] ) && ! preg_match( '/\bltr\b/', $input['toolbar1'] ) ) { |
|
2916 $input['toolbar1'] .= ',ltr'; |
|
2917 } |
2479 } |
2918 } |
2480 |
2919 |
2481 return $input; |
2920 return $input; |
2482 } |
2921 } |
|
2922 |
2483 |
2923 |
2484 /** |
2924 /** |
2485 * Convert smiley code to the icon graphic file equivalent. |
2925 * Convert smiley code to the icon graphic file equivalent. |
2486 * |
2926 * |
2487 * You can turn off smilies, by going to the write setting screen and unchecking |
2927 * You can turn off smilies, by going to the write setting screen and unchecking |
2509 if ( !get_option( 'use_smilies' ) ) |
2950 if ( !get_option( 'use_smilies' ) ) |
2510 return; |
2951 return; |
2511 |
2952 |
2512 if ( !isset( $wpsmiliestrans ) ) { |
2953 if ( !isset( $wpsmiliestrans ) ) { |
2513 $wpsmiliestrans = array( |
2954 $wpsmiliestrans = array( |
2514 ':mrgreen:' => 'icon_mrgreen.gif', |
2955 ':mrgreen:' => 'mrgreen.png', |
2515 ':neutral:' => 'icon_neutral.gif', |
2956 ':neutral:' => "\xf0\x9f\x98\x90", |
2516 ':twisted:' => 'icon_twisted.gif', |
2957 ':twisted:' => "\xf0\x9f\x98\x88", |
2517 ':arrow:' => 'icon_arrow.gif', |
2958 ':arrow:' => "\xe2\x9e\xa1", |
2518 ':shock:' => 'icon_eek.gif', |
2959 ':shock:' => "\xf0\x9f\x98\xaf", |
2519 ':smile:' => 'icon_smile.gif', |
2960 ':smile:' => 'simple-smile.png', |
2520 ':???:' => 'icon_confused.gif', |
2961 ':???:' => "\xf0\x9f\x98\x95", |
2521 ':cool:' => 'icon_cool.gif', |
2962 ':cool:' => "\xf0\x9f\x98\x8e", |
2522 ':evil:' => 'icon_evil.gif', |
2963 ':evil:' => "\xf0\x9f\x91\xbf", |
2523 ':grin:' => 'icon_biggrin.gif', |
2964 ':grin:' => "\xf0\x9f\x98\x80", |
2524 ':idea:' => 'icon_idea.gif', |
2965 ':idea:' => "\xf0\x9f\x92\xa1", |
2525 ':oops:' => 'icon_redface.gif', |
2966 ':oops:' => "\xf0\x9f\x98\xb3", |
2526 ':razz:' => 'icon_razz.gif', |
2967 ':razz:' => "\xf0\x9f\x98\x9b", |
2527 ':roll:' => 'icon_rolleyes.gif', |
2968 ':roll:' => 'rolleyes.png', |
2528 ':wink:' => 'icon_wink.gif', |
2969 ':wink:' => "\xf0\x9f\x98\x89", |
2529 ':cry:' => 'icon_cry.gif', |
2970 ':cry:' => "\xf0\x9f\x98\xa5", |
2530 ':eek:' => 'icon_surprised.gif', |
2971 ':eek:' => "\xf0\x9f\x98\xae", |
2531 ':lol:' => 'icon_lol.gif', |
2972 ':lol:' => "\xf0\x9f\x98\x86", |
2532 ':mad:' => 'icon_mad.gif', |
2973 ':mad:' => "\xf0\x9f\x98\xa1", |
2533 ':sad:' => 'icon_sad.gif', |
2974 ':sad:' => 'frownie.png', |
2534 '8-)' => 'icon_cool.gif', |
2975 '8-)' => "\xf0\x9f\x98\x8e", |
2535 '8-O' => 'icon_eek.gif', |
2976 '8-O' => "\xf0\x9f\x98\xaf", |
2536 ':-(' => 'icon_sad.gif', |
2977 ':-(' => 'frownie.png', |
2537 ':-)' => 'icon_smile.gif', |
2978 ':-)' => 'simple-smile.png', |
2538 ':-?' => 'icon_confused.gif', |
2979 ':-?' => "\xf0\x9f\x98\x95", |
2539 ':-D' => 'icon_biggrin.gif', |
2980 ':-D' => "\xf0\x9f\x98\x80", |
2540 ':-P' => 'icon_razz.gif', |
2981 ':-P' => "\xf0\x9f\x98\x9b", |
2541 ':-o' => 'icon_surprised.gif', |
2982 ':-o' => "\xf0\x9f\x98\xae", |
2542 ':-x' => 'icon_mad.gif', |
2983 ':-x' => "\xf0\x9f\x98\xa1", |
2543 ':-|' => 'icon_neutral.gif', |
2984 ':-|' => "\xf0\x9f\x98\x90", |
2544 ';-)' => 'icon_wink.gif', |
2985 ';-)' => "\xf0\x9f\x98\x89", |
2545 // This one transformation breaks regular text with frequency. |
2986 // This one transformation breaks regular text with frequency. |
2546 // '8)' => 'icon_cool.gif', |
2987 // '8)' => "\xf0\x9f\x98\x8e", |
2547 '8O' => 'icon_eek.gif', |
2988 '8O' => "\xf0\x9f\x98\xaf", |
2548 ':(' => 'icon_sad.gif', |
2989 ':(' => 'frownie.png', |
2549 ':)' => 'icon_smile.gif', |
2990 ':)' => 'simple-smile.png', |
2550 ':?' => 'icon_confused.gif', |
2991 ':?' => "\xf0\x9f\x98\x95", |
2551 ':D' => 'icon_biggrin.gif', |
2992 ':D' => "\xf0\x9f\x98\x80", |
2552 ':P' => 'icon_razz.gif', |
2993 ':P' => "\xf0\x9f\x98\x9b", |
2553 ':o' => 'icon_surprised.gif', |
2994 ':o' => "\xf0\x9f\x98\xae", |
2554 ':x' => 'icon_mad.gif', |
2995 ':x' => "\xf0\x9f\x98\xa1", |
2555 ':|' => 'icon_neutral.gif', |
2996 ':|' => "\xf0\x9f\x98\x90", |
2556 ';)' => 'icon_wink.gif', |
2997 ';)' => "\xf0\x9f\x98\x89", |
2557 ':!:' => 'icon_exclaim.gif', |
2998 ':!:' => "\xe2\x9d\x97", |
2558 ':?:' => 'icon_question.gif', |
2999 ':?:' => "\xe2\x9d\x93", |
2559 ); |
3000 ); |
2560 } |
3001 } |
2561 |
3002 |
2562 if (count($wpsmiliestrans) == 0) { |
3003 if (count($wpsmiliestrans) == 0) { |
2563 return; |
3004 return; |
2568 * we match the longest possible smilie (:???: vs :?) as the regular |
3009 * we match the longest possible smilie (:???: vs :?) as the regular |
2569 * expression used below is first-match |
3010 * expression used below is first-match |
2570 */ |
3011 */ |
2571 krsort($wpsmiliestrans); |
3012 krsort($wpsmiliestrans); |
2572 |
3013 |
2573 $wp_smiliessearch = '/(?:\s|^)'; |
3014 $spaces = wp_spaces_regexp(); |
|
3015 |
|
3016 // Begin first "subpattern" |
|
3017 $wp_smiliessearch = '/(?<=' . $spaces . '|^)'; |
2574 |
3018 |
2575 $subchar = ''; |
3019 $subchar = ''; |
2576 foreach ( (array) $wpsmiliestrans as $smiley => $img ) { |
3020 foreach ( (array) $wpsmiliestrans as $smiley => $img ) { |
2577 $firstchar = substr($smiley, 0, 1); |
3021 $firstchar = substr($smiley, 0, 1); |
2578 $rest = substr($smiley, 1); |
3022 $rest = substr($smiley, 1); |
2579 |
3023 |
2580 // new subpattern? |
3024 // new subpattern? |
2581 if ($firstchar != $subchar) { |
3025 if ($firstchar != $subchar) { |
2582 if ($subchar != '') { |
3026 if ($subchar != '') { |
2583 $wp_smiliessearch .= ')|(?:\s|^)'; |
3027 $wp_smiliessearch .= ')(?=' . $spaces . '|$)'; // End previous "subpattern" |
|
3028 $wp_smiliessearch .= '|(?<=' . $spaces . '|^)'; // Begin another "subpattern" |
2584 } |
3029 } |
2585 $subchar = $firstchar; |
3030 $subchar = $firstchar; |
2586 $wp_smiliessearch .= preg_quote($firstchar, '/') . '(?:'; |
3031 $wp_smiliessearch .= preg_quote($firstchar, '/') . '(?:'; |
2587 } else { |
3032 } else { |
2588 $wp_smiliessearch .= '|'; |
3033 $wp_smiliessearch .= '|'; |
2589 } |
3034 } |
2590 $wp_smiliessearch .= preg_quote($rest, '/'); |
3035 $wp_smiliessearch .= preg_quote($rest, '/'); |
2591 } |
3036 } |
2592 |
3037 |
2593 $wp_smiliessearch .= ')(?:\s|$)/m'; |
3038 $wp_smiliessearch .= ')(?=' . $spaces . '|$)/m'; |
|
3039 |
2594 } |
3040 } |
2595 |
3041 |
2596 /** |
3042 /** |
2597 * Merge user defined arguments into defaults array. |
3043 * Merge user defined arguments into defaults array. |
2598 * |
3044 * |
2599 * This function is used throughout WordPress to allow for both string or array |
3045 * This function is used throughout WordPress to allow for both string or array |
2600 * to be merged into another array. |
3046 * to be merged into another array. |
2601 * |
3047 * |
2602 * @since 2.2.0 |
3048 * @since 2.2.0 |
2603 * |
3049 * |
2604 * @param string|array $args Value to merge with $defaults |
3050 * @param string|array $args Value to merge with $defaults |
2605 * @param array $defaults Array that serves as the defaults. |
3051 * @param array $defaults Optional. Array that serves as the defaults. Default empty. |
2606 * @return array Merged user defined values with defaults. |
3052 * @return array Merged user defined values with defaults. |
2607 */ |
3053 */ |
2608 function wp_parse_args( $args, $defaults = '' ) { |
3054 function wp_parse_args( $args, $defaults = '' ) { |
2609 if ( is_object( $args ) ) |
3055 if ( is_object( $args ) ) |
2610 $r = get_object_vars( $args ); |
3056 $r = get_object_vars( $args ); |
2720 } |
3169 } |
2721 |
3170 |
2722 /** |
3171 /** |
2723 * Pluck a certain field out of each object in a list. |
3172 * Pluck a certain field out of each object in a list. |
2724 * |
3173 * |
|
3174 * This has the same functionality and prototype of |
|
3175 * array_column() (PHP 5.5) but also supports objects. |
|
3176 * |
2725 * @since 3.1.0 |
3177 * @since 3.1.0 |
2726 * |
3178 * @since 4.0.0 $index_key parameter added. |
2727 * @param array $list A list of objects or arrays |
3179 * |
2728 * @param int|string $field A field from the object to place instead of the entire object |
3180 * @param array $list List of objects or arrays |
2729 * @return array |
3181 * @param int|string $field Field from the object to place instead of the entire object |
2730 */ |
3182 * @param int|string $index_key Optional. Field from the object to use as keys for the new array. |
2731 function wp_list_pluck( $list, $field ) { |
3183 * Default null. |
2732 foreach ( $list as $key => $value ) { |
3184 * @return array Array of found values. If `$index_key` is set, an array of found values with keys |
2733 if ( is_object( $value ) ) |
3185 * corresponding to `$index_key`. If `$index_key` is null, array keys from the original |
2734 $list[ $key ] = $value->$field; |
3186 * `$list` will be preserved in the results. |
2735 else |
3187 */ |
2736 $list[ $key ] = $value[ $field ]; |
3188 function wp_list_pluck( $list, $field, $index_key = null ) { |
2737 } |
3189 if ( ! $index_key ) { |
2738 |
3190 /* |
2739 return $list; |
3191 * This is simple. Could at some point wrap array_column() |
|
3192 * if we knew we had an array of arrays. |
|
3193 */ |
|
3194 foreach ( $list as $key => $value ) { |
|
3195 if ( is_object( $value ) ) { |
|
3196 $list[ $key ] = $value->$field; |
|
3197 } else { |
|
3198 $list[ $key ] = $value[ $field ]; |
|
3199 } |
|
3200 } |
|
3201 return $list; |
|
3202 } |
|
3203 |
|
3204 /* |
|
3205 * When index_key is not set for a particular item, push the value |
|
3206 * to the end of the stack. This is how array_column() behaves. |
|
3207 */ |
|
3208 $newlist = array(); |
|
3209 foreach ( $list as $value ) { |
|
3210 if ( is_object( $value ) ) { |
|
3211 if ( isset( $value->$index_key ) ) { |
|
3212 $newlist[ $value->$index_key ] = $value->$field; |
|
3213 } else { |
|
3214 $newlist[] = $value->$field; |
|
3215 } |
|
3216 } else { |
|
3217 if ( isset( $value[ $index_key ] ) ) { |
|
3218 $newlist[ $value[ $index_key ] ] = $value[ $field ]; |
|
3219 } else { |
|
3220 $newlist[] = $value[ $field ]; |
|
3221 } |
|
3222 } |
|
3223 } |
|
3224 |
|
3225 return $newlist; |
2740 } |
3226 } |
2741 |
3227 |
2742 /** |
3228 /** |
2743 * Determines if Widgets library should be loaded. |
3229 * Determines if Widgets library should be loaded. |
2744 * |
3230 * |
2745 * Checks to make sure that the widgets library hasn't already been loaded. If |
3231 * Checks to make sure that the widgets library hasn't already been loaded. |
2746 * it hasn't, then it will load the widgets library and run an action hook. |
3232 * If it hasn't, then it will load the widgets library and run an action hook. |
2747 * |
3233 * |
2748 * @since 2.2.0 |
3234 * @since 2.2.0 |
2749 * @uses add_action() Calls '_admin_menu' hook with 'wp_widgets_add_menu' value. |
|
2750 */ |
3235 */ |
2751 function wp_maybe_load_widgets() { |
3236 function wp_maybe_load_widgets() { |
2752 if ( ! apply_filters('load_default_widgets', true) ) |
3237 /** |
|
3238 * Filter whether to load the Widgets library. |
|
3239 * |
|
3240 * Passing a falsey value to the filter will effectively short-circuit |
|
3241 * the Widgets library from loading. |
|
3242 * |
|
3243 * @since 2.8.0 |
|
3244 * |
|
3245 * @param bool $wp_maybe_load_widgets Whether to load the Widgets library. |
|
3246 * Default true. |
|
3247 */ |
|
3248 if ( ! apply_filters( 'load_default_widgets', true ) ) { |
2753 return; |
3249 return; |
|
3250 } |
|
3251 |
2754 require_once( ABSPATH . WPINC . '/default-widgets.php' ); |
3252 require_once( ABSPATH . WPINC . '/default-widgets.php' ); |
|
3253 |
2755 add_action( '_admin_menu', 'wp_widgets_add_menu' ); |
3254 add_action( '_admin_menu', 'wp_widgets_add_menu' ); |
2756 } |
3255 } |
2757 |
3256 |
2758 /** |
3257 /** |
2759 * Append the Widgets menu to the themes main menu. |
3258 * Append the Widgets menu to the themes main menu. |
2760 * |
3259 * |
2761 * @since 2.2.0 |
3260 * @since 2.2.0 |
2762 * @uses $submenu The administration submenu list. |
|
2763 */ |
3261 */ |
2764 function wp_widgets_add_menu() { |
3262 function wp_widgets_add_menu() { |
2765 global $submenu; |
3263 global $submenu; |
2766 |
3264 |
2767 if ( ! current_theme_supports( 'widgets' ) ) |
3265 if ( ! current_theme_supports( 'widgets' ) ) |
2835 <?php |
3334 <?php |
2836 die(); |
3335 die(); |
2837 } |
3336 } |
2838 |
3337 |
2839 /** |
3338 /** |
2840 * Converts value to nonnegative integer. |
3339 * Convert a value to non-negative integer. |
2841 * |
3340 * |
2842 * @since 2.5.0 |
3341 * @since 2.5.0 |
2843 * |
3342 * |
2844 * @param mixed $maybeint Data you wish to have converted to a nonnegative integer |
3343 * @param mixed $maybeint Data you wish to have converted to a non-negative integer. |
2845 * @return int An nonnegative integer |
3344 * @return int A non-negative integer. |
2846 */ |
3345 */ |
2847 function absint( $maybeint ) { |
3346 function absint( $maybeint ) { |
2848 return abs( intval( $maybeint ) ); |
3347 return abs( intval( $maybeint ) ); |
2849 } |
3348 } |
2850 |
3349 |
2851 /** |
3350 /** |
2852 * Determines if the blog can be accessed over SSL. |
3351 * Mark a function as deprecated and inform when it has been used. |
2853 * |
|
2854 * Determines if blog can be accessed over SSL by using cURL to access the site |
|
2855 * using the https in the siteurl. Requires cURL extension to work correctly. |
|
2856 * |
|
2857 * @since 2.5.0 |
|
2858 * |
|
2859 * @param string $url |
|
2860 * @return bool Whether SSL access is available |
|
2861 */ |
|
2862 function url_is_accessable_via_ssl($url) |
|
2863 { |
|
2864 if ( in_array( 'curl', get_loaded_extensions() ) ) { |
|
2865 $ssl = set_url_scheme( $url, 'https' ); |
|
2866 |
|
2867 $ch = curl_init(); |
|
2868 curl_setopt($ch, CURLOPT_URL, $ssl); |
|
2869 curl_setopt($ch, CURLOPT_FAILONERROR, true); |
|
2870 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
2871 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
|
2872 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); |
|
2873 |
|
2874 curl_exec($ch); |
|
2875 |
|
2876 $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
2877 curl_close ($ch); |
|
2878 |
|
2879 if ($status == 200 || $status == 401) { |
|
2880 return true; |
|
2881 } |
|
2882 } |
|
2883 return false; |
|
2884 } |
|
2885 |
|
2886 /** |
|
2887 * Marks a function as deprecated and informs when it has been used. |
|
2888 * |
3352 * |
2889 * There is a hook deprecated_function_run that will be called that can be used |
3353 * There is a hook deprecated_function_run that will be called that can be used |
2890 * to get the backtrace up to what file and function called the deprecated |
3354 * to get the backtrace up to what file and function called the deprecated |
2891 * function. |
3355 * function. |
2892 * |
3356 * |
2893 * The current behavior is to trigger a user error if WP_DEBUG is true. |
3357 * The current behavior is to trigger a user error if WP_DEBUG is true. |
2894 * |
3358 * |
2895 * This function is to be used in every function that is deprecated. |
3359 * This function is to be used in every function that is deprecated. |
2896 * |
3360 * |
2897 * @package WordPress |
|
2898 * @subpackage Debug |
|
2899 * @since 2.5.0 |
3361 * @since 2.5.0 |
2900 * @access private |
3362 * @access private |
2901 * |
3363 * |
2902 * @uses do_action() Calls 'deprecated_function_run' and passes the function name, what to use instead, |
3364 * @param string $function The function that was called. |
2903 * and the version the function was deprecated in. |
3365 * @param string $version The version of WordPress that deprecated the function. |
2904 * @uses apply_filters() Calls 'deprecated_function_trigger_error' and expects boolean value of true to do |
3366 * @param string $replacement Optional. The function that should have been called. Default null. |
2905 * trigger or false to not trigger error. |
|
2906 * |
|
2907 * @param string $function The function that was called |
|
2908 * @param string $version The version of WordPress that deprecated the function |
|
2909 * @param string $replacement Optional. The function that should have been called |
|
2910 */ |
3367 */ |
2911 function _deprecated_function( $function, $version, $replacement = null ) { |
3368 function _deprecated_function( $function, $version, $replacement = null ) { |
2912 |
3369 |
|
3370 /** |
|
3371 * Fires when a deprecated function is called. |
|
3372 * |
|
3373 * @since 2.5.0 |
|
3374 * |
|
3375 * @param string $function The function that was called. |
|
3376 * @param string $replacement The function that should have been called. |
|
3377 * @param string $version The version of WordPress that deprecated the function. |
|
3378 */ |
2913 do_action( 'deprecated_function_run', $function, $replacement, $version ); |
3379 do_action( 'deprecated_function_run', $function, $replacement, $version ); |
2914 |
3380 |
2915 // Allow plugin to filter the output error trigger |
3381 /** |
|
3382 * Filter whether to trigger an error for deprecated functions. |
|
3383 * |
|
3384 * @since 2.5.0 |
|
3385 * |
|
3386 * @param bool $trigger Whether to trigger the error for deprecated functions. Default true. |
|
3387 */ |
2916 if ( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true ) ) { |
3388 if ( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true ) ) { |
2917 if ( function_exists( '__' ) ) { |
3389 if ( function_exists( '__' ) ) { |
2918 if ( ! is_null( $replacement ) ) |
3390 if ( ! is_null( $replacement ) ) |
2919 trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $function, $version, $replacement ) ); |
3391 trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $function, $version, $replacement ) ); |
2920 else |
3392 else |
2927 } |
3399 } |
2928 } |
3400 } |
2929 } |
3401 } |
2930 |
3402 |
2931 /** |
3403 /** |
2932 * Marks a file as deprecated and informs when it has been used. |
3404 * Mark a file as deprecated and inform when it has been used. |
2933 * |
3405 * |
2934 * There is a hook deprecated_file_included that will be called that can be used |
3406 * There is a hook deprecated_file_included that will be called that can be used |
2935 * to get the backtrace up to what file and function included the deprecated |
3407 * to get the backtrace up to what file and function included the deprecated |
2936 * file. |
3408 * file. |
2937 * |
3409 * |
2938 * The current behavior is to trigger a user error if WP_DEBUG is true. |
3410 * The current behavior is to trigger a user error if WP_DEBUG is true. |
2939 * |
3411 * |
2940 * This function is to be used in every file that is deprecated. |
3412 * This function is to be used in every file that is deprecated. |
2941 * |
3413 * |
2942 * @package WordPress |
|
2943 * @subpackage Debug |
|
2944 * @since 2.5.0 |
3414 * @since 2.5.0 |
2945 * @access private |
3415 * @access private |
2946 * |
3416 * |
2947 * @uses do_action() Calls 'deprecated_file_included' and passes the file name, what to use instead, |
3417 * @param string $file The file that was included. |
2948 * the version in which the file was deprecated, and any message regarding the change. |
3418 * @param string $version The version of WordPress that deprecated the file. |
2949 * @uses apply_filters() Calls 'deprecated_file_trigger_error' and expects boolean value of true to do |
3419 * @param string $replacement Optional. The file that should have been included based on ABSPATH. |
2950 * trigger or false to not trigger error. |
3420 * Default null. |
2951 * |
3421 * @param string $message Optional. A message regarding the change. Default empty. |
2952 * @param string $file The file that was included |
|
2953 * @param string $version The version of WordPress that deprecated the file |
|
2954 * @param string $replacement Optional. The file that should have been included based on ABSPATH |
|
2955 * @param string $message Optional. A message regarding the change |
|
2956 */ |
3422 */ |
2957 function _deprecated_file( $file, $version, $replacement = null, $message = '' ) { |
3423 function _deprecated_file( $file, $version, $replacement = null, $message = '' ) { |
2958 |
3424 |
|
3425 /** |
|
3426 * Fires when a deprecated file is called. |
|
3427 * |
|
3428 * @since 2.5.0 |
|
3429 * |
|
3430 * @param string $file The file that was called. |
|
3431 * @param string $replacement The file that should have been included based on ABSPATH. |
|
3432 * @param string $version The version of WordPress that deprecated the file. |
|
3433 * @param string $message A message regarding the change. |
|
3434 */ |
2959 do_action( 'deprecated_file_included', $file, $replacement, $version, $message ); |
3435 do_action( 'deprecated_file_included', $file, $replacement, $version, $message ); |
2960 |
3436 |
2961 // Allow plugin to filter the output error trigger |
3437 /** |
|
3438 * Filter whether to trigger an error for deprecated files. |
|
3439 * |
|
3440 * @since 2.5.0 |
|
3441 * |
|
3442 * @param bool $trigger Whether to trigger the error for deprecated files. Default true. |
|
3443 */ |
2962 if ( WP_DEBUG && apply_filters( 'deprecated_file_trigger_error', true ) ) { |
3444 if ( WP_DEBUG && apply_filters( 'deprecated_file_trigger_error', true ) ) { |
2963 $message = empty( $message ) ? '' : ' ' . $message; |
3445 $message = empty( $message ) ? '' : ' ' . $message; |
2964 if ( function_exists( '__' ) ) { |
3446 if ( function_exists( '__' ) ) { |
2965 if ( ! is_null( $replacement ) ) |
3447 if ( ! is_null( $replacement ) ) |
2966 trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $file, $version, $replacement ) . $message ); |
3448 trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $file, $version, $replacement ) . $message ); |
2973 trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $file, $version ) . $message ); |
3455 trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $file, $version ) . $message ); |
2974 } |
3456 } |
2975 } |
3457 } |
2976 } |
3458 } |
2977 /** |
3459 /** |
2978 * Marks a function argument as deprecated and informs when it has been used. |
3460 * Mark a function argument as deprecated and inform when it has been used. |
2979 * |
3461 * |
2980 * This function is to be used whenever a deprecated function argument is used. |
3462 * This function is to be used whenever a deprecated function argument is used. |
2981 * Before this function is called, the argument must be checked for whether it was |
3463 * Before this function is called, the argument must be checked for whether it was |
2982 * used by comparing it to its default value or evaluating whether it is empty. |
3464 * used by comparing it to its default value or evaluating whether it is empty. |
2983 * For example: |
3465 * For example: |
2984 * <code> |
3466 * |
2985 * if ( !empty($deprecated) ) |
3467 * if ( ! empty( $deprecated ) ) { |
2986 * _deprecated_argument( __FUNCTION__, '3.0' ); |
3468 * _deprecated_argument( __FUNCTION__, '3.0' ); |
2987 * </code> |
3469 * } |
|
3470 * |
2988 * |
3471 * |
2989 * There is a hook deprecated_argument_run that will be called that can be used |
3472 * There is a hook deprecated_argument_run that will be called that can be used |
2990 * to get the backtrace up to what file and function used the deprecated |
3473 * to get the backtrace up to what file and function used the deprecated |
2991 * argument. |
3474 * argument. |
2992 * |
3475 * |
2993 * The current behavior is to trigger a user error if WP_DEBUG is true. |
3476 * The current behavior is to trigger a user error if WP_DEBUG is true. |
2994 * |
3477 * |
2995 * @package WordPress |
|
2996 * @subpackage Debug |
|
2997 * @since 3.0.0 |
3478 * @since 3.0.0 |
2998 * @access private |
3479 * @access private |
2999 * |
3480 * |
3000 * @uses do_action() Calls 'deprecated_argument_run' and passes the function name, a message on the change, |
3481 * @param string $function The function that was called. |
3001 * and the version in which the argument was deprecated. |
3482 * @param string $version The version of WordPress that deprecated the argument used. |
3002 * @uses apply_filters() Calls 'deprecated_argument_trigger_error' and expects boolean value of true to do |
3483 * @param string $message Optional. A message regarding the change. Default null. |
3003 * trigger or false to not trigger error. |
|
3004 * |
|
3005 * @param string $function The function that was called |
|
3006 * @param string $version The version of WordPress that deprecated the argument used |
|
3007 * @param string $message Optional. A message regarding the change. |
|
3008 */ |
3484 */ |
3009 function _deprecated_argument( $function, $version, $message = null ) { |
3485 function _deprecated_argument( $function, $version, $message = null ) { |
3010 |
3486 |
|
3487 /** |
|
3488 * Fires when a deprecated argument is called. |
|
3489 * |
|
3490 * @since 3.0.0 |
|
3491 * |
|
3492 * @param string $function The function that was called. |
|
3493 * @param string $message A message regarding the change. |
|
3494 * @param string $version The version of WordPress that deprecated the argument used. |
|
3495 */ |
3011 do_action( 'deprecated_argument_run', $function, $message, $version ); |
3496 do_action( 'deprecated_argument_run', $function, $message, $version ); |
3012 |
3497 |
3013 // Allow plugin to filter the output error trigger |
3498 /** |
|
3499 * Filter whether to trigger an error for deprecated arguments. |
|
3500 * |
|
3501 * @since 3.0.0 |
|
3502 * |
|
3503 * @param bool $trigger Whether to trigger the error for deprecated arguments. Default true. |
|
3504 */ |
3014 if ( WP_DEBUG && apply_filters( 'deprecated_argument_trigger_error', true ) ) { |
3505 if ( WP_DEBUG && apply_filters( 'deprecated_argument_trigger_error', true ) ) { |
3015 if ( function_exists( '__' ) ) { |
3506 if ( function_exists( '__' ) ) { |
3016 if ( ! is_null( $message ) ) |
3507 if ( ! is_null( $message ) ) |
3017 trigger_error( sprintf( __('%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s'), $function, $version, $message ) ); |
3508 trigger_error( sprintf( __('%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s'), $function, $version, $message ) ); |
3018 else |
3509 else |
3025 } |
3516 } |
3026 } |
3517 } |
3027 } |
3518 } |
3028 |
3519 |
3029 /** |
3520 /** |
3030 * Marks something as being incorrectly called. |
3521 * Mark something as being incorrectly called. |
3031 * |
3522 * |
3032 * There is a hook doing_it_wrong_run that will be called that can be used |
3523 * There is a hook doing_it_wrong_run that will be called that can be used |
3033 * to get the backtrace up to what file and function called the deprecated |
3524 * to get the backtrace up to what file and function called the deprecated |
3034 * function. |
3525 * function. |
3035 * |
3526 * |
3036 * The current behavior is to trigger a user error if WP_DEBUG is true. |
3527 * The current behavior is to trigger a user error if WP_DEBUG is true. |
3037 * |
3528 * |
3038 * @package WordPress |
|
3039 * @subpackage Debug |
|
3040 * @since 3.1.0 |
3529 * @since 3.1.0 |
3041 * @access private |
3530 * @access private |
3042 * |
3531 * |
3043 * @uses do_action() Calls 'doing_it_wrong_run' and passes the function arguments. |
|
3044 * @uses apply_filters() Calls 'doing_it_wrong_trigger_error' and expects boolean value of true to do |
|
3045 * trigger or false to not trigger error. |
|
3046 * |
|
3047 * @param string $function The function that was called. |
3532 * @param string $function The function that was called. |
3048 * @param string $message A message explaining what has been done incorrectly. |
3533 * @param string $message A message explaining what has been done incorrectly. |
3049 * @param string $version The version of WordPress where the message was added. |
3534 * @param string $version The version of WordPress where the message was added. |
3050 */ |
3535 */ |
3051 function _doing_it_wrong( $function, $message, $version ) { |
3536 function _doing_it_wrong( $function, $message, $version ) { |
3052 |
3537 |
|
3538 /** |
|
3539 * Fires when the given function is being used incorrectly. |
|
3540 * |
|
3541 * @since 3.1.0 |
|
3542 * |
|
3543 * @param string $function The function that was called. |
|
3544 * @param string $message A message explaining what has been done incorrectly. |
|
3545 * @param string $version The version of WordPress where the message was added. |
|
3546 */ |
3053 do_action( 'doing_it_wrong_run', $function, $message, $version ); |
3547 do_action( 'doing_it_wrong_run', $function, $message, $version ); |
3054 |
3548 |
3055 // Allow plugin to filter the output error trigger |
3549 /** |
|
3550 * Filter whether to trigger an error for _doing_it_wrong() calls. |
|
3551 * |
|
3552 * @since 3.1.0 |
|
3553 * |
|
3554 * @param bool $trigger Whether to trigger the error for _doing_it_wrong() calls. Default true. |
|
3555 */ |
3056 if ( WP_DEBUG && apply_filters( 'doing_it_wrong_trigger_error', true ) ) { |
3556 if ( WP_DEBUG && apply_filters( 'doing_it_wrong_trigger_error', true ) ) { |
3057 if ( function_exists( '__' ) ) { |
3557 if ( function_exists( '__' ) ) { |
3058 $version = is_null( $version ) ? '' : sprintf( __( '(This message was added in version %s.)' ), $version ); |
3558 $version = is_null( $version ) ? '' : sprintf( __( '(This message was added in version %s.)' ), $version ); |
3059 $message .= ' ' . __( 'Please see <a href="http://codex.wordpress.org/Debugging_in_WordPress">Debugging in WordPress</a> for more information.' ); |
3559 $message .= ' ' . __( 'Please see <a href="https://codex.wordpress.org/Debugging_in_WordPress">Debugging in WordPress</a> for more information.' ); |
3060 trigger_error( sprintf( __( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s' ), $function, $message, $version ) ); |
3560 trigger_error( sprintf( __( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s' ), $function, $message, $version ) ); |
3061 } else { |
3561 } else { |
3062 $version = is_null( $version ) ? '' : sprintf( '(This message was added in version %s.)', $version ); |
3562 $version = is_null( $version ) ? '' : sprintf( '(This message was added in version %s.)', $version ); |
3063 $message .= ' Please see <a href="http://codex.wordpress.org/Debugging_in_WordPress">Debugging in WordPress</a> for more information.'; |
3563 $message .= ' Please see <a href="https://codex.wordpress.org/Debugging_in_WordPress">Debugging in WordPress</a> for more information.'; |
3064 trigger_error( sprintf( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s', $function, $message, $version ) ); |
3564 trigger_error( sprintf( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s', $function, $message, $version ) ); |
3065 } |
3565 } |
3066 } |
3566 } |
3067 } |
3567 } |
3068 |
3568 |
3069 /** |
3569 /** |
3070 * Is the server running earlier than 1.5.0 version of lighttpd? |
3570 * Is the server running earlier than 1.5.0 version of lighttpd? |
3071 * |
3571 * |
3072 * @since 2.5.0 |
3572 * @since 2.5.0 |
3073 * |
3573 * |
3074 * @return bool Whether the server is running lighttpd < 1.5.0 |
3574 * @return bool Whether the server is running lighttpd < 1.5.0. |
3075 */ |
3575 */ |
3076 function is_lighttpd_before_150() { |
3576 function is_lighttpd_before_150() { |
3077 $server_parts = explode( '/', isset( $_SERVER['SERVER_SOFTWARE'] )? $_SERVER['SERVER_SOFTWARE'] : '' ); |
3577 $server_parts = explode( '/', isset( $_SERVER['SERVER_SOFTWARE'] )? $_SERVER['SERVER_SOFTWARE'] : '' ); |
3078 $server_parts[1] = isset( $server_parts[1] )? $server_parts[1] : ''; |
3578 $server_parts[1] = isset( $server_parts[1] )? $server_parts[1] : ''; |
3079 return 'lighttpd' == $server_parts[0] && -1 == version_compare( $server_parts[1], '1.5.0' ); |
3579 return 'lighttpd' == $server_parts[0] && -1 == version_compare( $server_parts[1], '1.5.0' ); |
3256 $directory = str_replace( ABSPATH, '', $script_filename_dir ); |
3757 $directory = str_replace( ABSPATH, '', $script_filename_dir ); |
3257 // Strip off the sub directory, and any file/query paramss |
3758 // Strip off the sub directory, and any file/query paramss |
3258 $path = preg_replace( '#/' . preg_quote( $directory, '#' ) . '/[^/]*$#i', '' , $_SERVER['REQUEST_URI'] ); |
3759 $path = preg_replace( '#/' . preg_quote( $directory, '#' ) . '/[^/]*$#i', '' , $_SERVER['REQUEST_URI'] ); |
3259 } elseif ( false !== strpos( $abspath_fix, $script_filename_dir ) ) { |
3760 } elseif ( false !== strpos( $abspath_fix, $script_filename_dir ) ) { |
3260 // Request is hitting a file above ABSPATH |
3761 // Request is hitting a file above ABSPATH |
3261 $subdirectory = str_replace( $script_filename_dir, '', $abspath_fix ); |
3762 $subdirectory = substr( $abspath_fix, strpos( $abspath_fix, $script_filename_dir ) + strlen( $script_filename_dir ) ); |
3262 // Strip off any file/query params from the path, appending the sub directory to the install |
3763 // Strip off any file/query params from the path, appending the sub directory to the install |
3263 $path = preg_replace( '#/[^/]*$#i', '' , $_SERVER['REQUEST_URI'] ) . $subdirectory; |
3764 $path = preg_replace( '#/[^/]*$#i', '' , $_SERVER['REQUEST_URI'] ) . $subdirectory; |
3264 } else { |
3765 } else { |
3265 $path = $_SERVER['REQUEST_URI']; |
3766 $path = $_SERVER['REQUEST_URI']; |
3266 } |
3767 } |
3298 } |
3799 } |
3299 |
3800 |
3300 /** |
3801 /** |
3301 * Suspend cache invalidation. |
3802 * Suspend cache invalidation. |
3302 * |
3803 * |
3303 * Turns cache invalidation on and off. Useful during imports where you don't wont to do invalidations |
3804 * Turns cache invalidation on and off. Useful during imports where you don't wont to do |
3304 * every time a post is inserted. Callers must be sure that what they are doing won't lead to an inconsistent |
3805 * invalidations every time a post is inserted. Callers must be sure that what they are |
3305 * cache when invalidation is suspended. |
3806 * doing won't lead to an inconsistent cache when invalidation is suspended. |
3306 * |
3807 * |
3307 * @since 2.7.0 |
3808 * @since 2.7.0 |
3308 * |
3809 * |
3309 * @param bool $suspend Whether to suspend or enable cache invalidation |
3810 * @param bool $suspend Optional. Whether to suspend or enable cache invalidation. Default true. |
3310 * @return bool The current suspend setting |
3811 * @return bool The current suspend setting. |
3311 */ |
3812 */ |
3312 function wp_suspend_cache_invalidation($suspend = true) { |
3813 function wp_suspend_cache_invalidation( $suspend = true ) { |
3313 global $_wp_suspend_cache_invalidation; |
3814 global $_wp_suspend_cache_invalidation; |
3314 |
3815 |
3315 $current_suspend = $_wp_suspend_cache_invalidation; |
3816 $current_suspend = $_wp_suspend_cache_invalidation; |
3316 $_wp_suspend_cache_invalidation = $suspend; |
3817 $_wp_suspend_cache_invalidation = $suspend; |
3317 return $current_suspend; |
3818 return $current_suspend; |
3318 } |
3819 } |
3319 |
3820 |
3320 /** |
3821 /** |
3321 * Whether a site is the main site of the current network. |
3822 * Determine whether a site is the main site of the current network. |
3322 * |
3823 * |
3323 * @since 3.0.0 |
3824 * @since 3.0.0 |
3324 * |
3825 * |
3325 * @param int $site_id Optional. Site ID to test. Defaults to current site. |
3826 * @param int $site_id Optional. Site ID to test. Defaults to current site. |
3326 * @return bool True if $site_id is the main site of the network, or if not running multisite. |
3827 * Defaults to current site. |
|
3828 * @return bool True if $site_id is the main site of the network, or if not |
|
3829 * running Multisite. |
3327 */ |
3830 */ |
3328 function is_main_site( $site_id = null ) { |
3831 function is_main_site( $site_id = null ) { |
3329 // This is the current network's information; 'site' is old terminology. |
3832 // This is the current network's information; 'site' is old terminology. |
3330 global $current_site; |
3833 global $current_site; |
3331 |
3834 |
3770 * Returns an empty string. |
4306 * Returns an empty string. |
3771 * |
4307 * |
3772 * Useful for returning an empty string to filters easily. |
4308 * Useful for returning an empty string to filters easily. |
3773 * |
4309 * |
3774 * @since 3.7.0 |
4310 * @since 3.7.0 |
|
4311 * |
3775 * @see __return_null() |
4312 * @see __return_null() |
3776 * @return string Empty string |
4313 * |
|
4314 * @return string Empty string. |
3777 */ |
4315 */ |
3778 function __return_empty_string() { |
4316 function __return_empty_string() { |
3779 return ''; |
4317 return ''; |
3780 } |
4318 } |
3781 |
4319 |
3782 /** |
4320 /** |
3783 * Send a HTTP header to disable content type sniffing in browsers which support it. |
4321 * Send a HTTP header to disable content type sniffing in browsers which support it. |
3784 * |
4322 * |
3785 * @link http://blogs.msdn.com/ie/archive/2008/07/02/ie8-security-part-v-comprehensive-protection.aspx |
|
3786 * @link http://src.chromium.org/viewvc/chrome?view=rev&revision=6985 |
|
3787 * |
|
3788 * @since 3.0.0 |
4323 * @since 3.0.0 |
3789 * @return none |
4324 * |
|
4325 * @see http://blogs.msdn.com/ie/archive/2008/07/02/ie8-security-part-v-comprehensive-protection.aspx |
|
4326 * @see http://src.chromium.org/viewvc/chrome?view=rev&revision=6985 |
3790 */ |
4327 */ |
3791 function send_nosniff_header() { |
4328 function send_nosniff_header() { |
3792 @header( 'X-Content-Type-Options: nosniff' ); |
4329 @header( 'X-Content-Type-Options: nosniff' ); |
3793 } |
4330 } |
3794 |
4331 |
3795 /** |
4332 /** |
3796 * Returns a MySQL expression for selecting the week number based on the start_of_week option. |
4333 * Return a MySQL expression for selecting the week number based on the start_of_week option. |
3797 * |
4334 * |
3798 * @internal |
4335 * @ignore |
3799 * @since 3.0.0 |
4336 * @since 3.0.0 |
3800 * @param string $column |
4337 * |
3801 * @return string |
4338 * @param string $column Database column. |
|
4339 * @return string SQL clause. |
3802 */ |
4340 */ |
3803 function _wp_mysql_week( $column ) { |
4341 function _wp_mysql_week( $column ) { |
3804 switch ( $start_of_week = (int) get_option( 'start_of_week' ) ) { |
4342 switch ( $start_of_week = (int) get_option( 'start_of_week' ) ) { |
3805 default : |
|
3806 case 0 : |
|
3807 return "WEEK( $column, 0 )"; |
|
3808 case 1 : |
4343 case 1 : |
3809 return "WEEK( $column, 1 )"; |
4344 return "WEEK( $column, 1 )"; |
3810 case 2 : |
4345 case 2 : |
3811 case 3 : |
4346 case 3 : |
3812 case 4 : |
4347 case 4 : |
3813 case 5 : |
4348 case 5 : |
3814 case 6 : |
4349 case 6 : |
3815 return "WEEK( DATE_SUB( $column, INTERVAL $start_of_week DAY ), 0 )"; |
4350 return "WEEK( DATE_SUB( $column, INTERVAL $start_of_week DAY ), 0 )"; |
3816 } |
4351 case 0 : |
3817 } |
4352 default : |
3818 |
4353 return "WEEK( $column, 0 )"; |
3819 /** |
4354 } |
3820 * Finds hierarchy loops using a callback function that maps object IDs to parent IDs. |
4355 } |
|
4356 |
|
4357 /** |
|
4358 * Find hierarchy loops using a callback function that maps object IDs to parent IDs. |
3821 * |
4359 * |
3822 * @since 3.1.0 |
4360 * @since 3.1.0 |
3823 * @access private |
4361 * @access private |
3824 * |
4362 * |
3825 * @param callback $callback function that accepts ( ID, $callback_args ) and outputs parent_ID |
4363 * @param callback $callback Function that accepts ( ID, $callback_args ) and outputs parent_ID. |
3826 * @param int $start The ID to start the loop check at |
4364 * @param int $start The ID to start the loop check at. |
3827 * @param int $start_parent the parent_ID of $start to use instead of calling $callback( $start ). Use null to always use $callback |
4365 * @param int $start_parent The parent_ID of $start to use instead of calling $callback( $start ). |
3828 * @param array $callback_args optional additional arguments to send to $callback |
4366 * Use null to always use $callback |
3829 * @return array IDs of all members of loop |
4367 * @param array $callback_args Optional. Additional arguments to send to $callback. |
|
4368 * @return array IDs of all members of loop. |
3830 */ |
4369 */ |
3831 function wp_find_hierarchy_loop( $callback, $start, $start_parent, $callback_args = array() ) { |
4370 function wp_find_hierarchy_loop( $callback, $start, $start_parent, $callback_args = array() ) { |
3832 $override = is_null( $start_parent ) ? array() : array( $start => $start_parent ); |
4371 $override = is_null( $start_parent ) ? array() : array( $start => $start_parent ); |
3833 |
4372 |
3834 if ( !$arbitrary_loop_member = wp_find_hierarchy_loop_tortoise_hare( $callback, $start, $override, $callback_args ) ) |
4373 if ( !$arbitrary_loop_member = wp_find_hierarchy_loop_tortoise_hare( $callback, $start, $override, $callback_args ) ) |
3836 |
4375 |
3837 return wp_find_hierarchy_loop_tortoise_hare( $callback, $arbitrary_loop_member, $override, $callback_args, true ); |
4376 return wp_find_hierarchy_loop_tortoise_hare( $callback, $arbitrary_loop_member, $override, $callback_args, true ); |
3838 } |
4377 } |
3839 |
4378 |
3840 /** |
4379 /** |
3841 * Uses the "The Tortoise and the Hare" algorithm to detect loops. |
4380 * Use the "The Tortoise and the Hare" algorithm to detect loops. |
3842 * |
4381 * |
3843 * For every step of the algorithm, the hare takes two steps and the tortoise one. |
4382 * For every step of the algorithm, the hare takes two steps and the tortoise one. |
3844 * If the hare ever laps the tortoise, there must be a loop. |
4383 * If the hare ever laps the tortoise, there must be a loop. |
3845 * |
4384 * |
3846 * @since 3.1.0 |
4385 * @since 3.1.0 |
3847 * @access private |
4386 * @access private |
3848 * |
4387 * |
3849 * @param callback $callback function that accepts ( ID, callback_arg, ... ) and outputs parent_ID |
4388 * @param callback $callback Function that accepts ( ID, callback_arg, ... ) and outputs parent_ID. |
3850 * @param int $start The ID to start the loop check at |
4389 * @param int $start The ID to start the loop check at. |
3851 * @param array $override an array of ( ID => parent_ID, ... ) to use instead of $callback |
4390 * @param array $override Optional. An array of ( ID => parent_ID, ... ) to use instead of $callback. |
3852 * @param array $callback_args optional additional arguments to send to $callback |
4391 * Default empty array. |
3853 * @param bool $_return_loop Return loop members or just detect presence of loop? |
4392 * @param array $callback_args Optional. Additional arguments to send to $callback. Default empty array. |
3854 * Only set to true if you already know the given $start is part of a loop |
4393 * @param bool $_return_loop Optional. Return loop members or just detect presence of loop? Only set |
3855 * (otherwise the returned array might include branches) |
4394 * to true if you already know the given $start is part of a loop (otherwise |
3856 * @return mixed scalar ID of some arbitrary member of the loop, or array of IDs of all members of loop if $_return_loop |
4395 * the returned array might include branches). Default false. |
|
4396 * @return mixed Scalar ID of some arbitrary member of the loop, or array of IDs of all members of loop if |
|
4397 * $_return_loop |
3857 */ |
4398 */ |
3858 function wp_find_hierarchy_loop_tortoise_hare( $callback, $start, $override = array(), $callback_args = array(), $_return_loop = false ) { |
4399 function wp_find_hierarchy_loop_tortoise_hare( $callback, $start, $override = array(), $callback_args = array(), $_return_loop = false ) { |
3859 $tortoise = $hare = $evanescent_hare = $start; |
4400 $tortoise = $hare = $evanescent_hare = $start; |
3860 $return = array(); |
4401 $return = array(); |
3861 |
4402 |
3883 } |
4424 } |
3884 |
4425 |
3885 /** |
4426 /** |
3886 * Send a HTTP header to limit rendering of pages to same origin iframes. |
4427 * Send a HTTP header to limit rendering of pages to same origin iframes. |
3887 * |
4428 * |
3888 * @link https://developer.mozilla.org/en/the_x-frame-options_response_header |
|
3889 * |
|
3890 * @since 3.1.3 |
4429 * @since 3.1.3 |
3891 * @return none |
4430 * |
|
4431 * @see https://developer.mozilla.org/en/the_x-frame-options_response_header |
3892 */ |
4432 */ |
3893 function send_frame_options_header() { |
4433 function send_frame_options_header() { |
3894 @header( 'X-Frame-Options: SAMEORIGIN' ); |
4434 @header( 'X-Frame-Options: SAMEORIGIN' ); |
3895 } |
4435 } |
3896 |
4436 |
3897 /** |
4437 /** |
3898 * Retrieve a list of protocols to allow in HTML attributes. |
4438 * Retrieve a list of protocols to allow in HTML attributes. |
3899 * |
4439 * |
3900 * @since 3.3.0 |
4440 * @since 3.3.0 |
|
4441 * |
3901 * @see wp_kses() |
4442 * @see wp_kses() |
3902 * @see esc_url() |
4443 * @see esc_url() |
3903 * |
4444 * |
3904 * @return array Array of allowed protocols |
4445 * @return array Array of allowed protocols. |
3905 */ |
4446 */ |
3906 function wp_allowed_protocols() { |
4447 function wp_allowed_protocols() { |
3907 static $protocols; |
4448 static $protocols; |
3908 |
4449 |
3909 if ( empty( $protocols ) ) { |
4450 if ( empty( $protocols ) ) { |
3910 $protocols = array( 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'svn', 'tel', 'fax', 'xmpp' ); |
4451 $protocols = array( 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'svn', 'tel', 'fax', 'xmpp' ); |
|
4452 |
|
4453 /** |
|
4454 * Filter the list of protocols allowed in HTML attributes. |
|
4455 * |
|
4456 * @since 3.0.0 |
|
4457 * |
|
4458 * @param array $protocols Array of allowed protocols e.g. 'http', 'ftp', 'tel', and more. |
|
4459 */ |
3911 $protocols = apply_filters( 'kses_allowed_protocols', $protocols ); |
4460 $protocols = apply_filters( 'kses_allowed_protocols', $protocols ); |
3912 } |
4461 } |
3913 |
4462 |
3914 return $protocols; |
4463 return $protocols; |
3915 } |
4464 } |
3916 |
4465 |
3917 /** |
4466 /** |
3918 * Return a comma separated string of functions that have been called to get to the current point in code. |
4467 * Return a comma-separated string of functions that have been called to get |
3919 * |
4468 * to the current point in code. |
3920 * @link http://core.trac.wordpress.org/ticket/19589 |
4469 * |
3921 * @since 3.4 |
4470 * @since 3.4.0 |
3922 * |
4471 * |
3923 * @param string $ignore_class A class to ignore all function calls within - useful when you want to just give info about the callee |
4472 * @see https://core.trac.wordpress.org/ticket/19589 |
3924 * @param int $skip_frames A number of stack frames to skip - useful for unwinding back to the source of the issue |
4473 * |
3925 * @param bool $pretty Whether or not you want a comma separated string or raw array returned |
4474 * @param string $ignore_class Optional. A class to ignore all function calls within - useful |
3926 * @return string|array Either a string containing a reversed comma separated trace or an array of individual calls. |
4475 * when you want to just give info about the callee. Default null. |
|
4476 * @param int $skip_frames Optional. A number of stack frames to skip - useful for unwinding |
|
4477 * back to the source of the issue. Default 0. |
|
4478 * @param bool $pretty Optional. Whether or not you want a comma separated string or raw |
|
4479 * array returned. Default true. |
|
4480 * @return string|array Either a string containing a reversed comma separated trace or an array |
|
4481 * of individual calls. |
3927 */ |
4482 */ |
3928 function wp_debug_backtrace_summary( $ignore_class = null, $skip_frames = 0, $pretty = true ) { |
4483 function wp_debug_backtrace_summary( $ignore_class = null, $skip_frames = 0, $pretty = true ) { |
3929 if ( version_compare( PHP_VERSION, '5.2.5', '>=' ) ) |
4484 if ( version_compare( PHP_VERSION, '5.2.5', '>=' ) ) |
3930 $trace = debug_backtrace( false ); |
4485 $trace = debug_backtrace( false ); |
3931 else |
4486 else |
4005 } |
4561 } |
4006 |
4562 |
4007 /** |
4563 /** |
4008 * Test if a given path is a stream URL |
4564 * Test if a given path is a stream URL |
4009 * |
4565 * |
4010 * @param string $path The resource path or URL |
4566 * @param string $path The resource path or URL. |
4011 * @return bool True if the path is a stream URL |
4567 * @return bool True if the path is a stream URL. |
4012 */ |
4568 */ |
4013 function wp_is_stream( $path ) { |
4569 function wp_is_stream( $path ) { |
4014 $wrappers = stream_get_wrappers(); |
4570 $wrappers = stream_get_wrappers(); |
4015 $wrappers_re = '(' . join('|', $wrappers) . ')'; |
4571 $wrappers_re = '(' . join('|', $wrappers) . ')'; |
4016 |
4572 |
4017 return preg_match( "!^$wrappers_re://!", $path ) === 1; |
4573 return preg_match( "!^$wrappers_re://!", $path ) === 1; |
4018 } |
4574 } |
4019 |
4575 |
4020 /** |
4576 /** |
4021 * Test if the supplied date is valid for the Gregorian calendar |
4577 * Test if the supplied date is valid for the Gregorian calendar. |
4022 * |
4578 * |
4023 * @since 3.5.0 |
4579 * @since 3.5.0 |
4024 * |
4580 * |
4025 * @return bool true|false |
4581 * @see checkdate() |
|
4582 * |
|
4583 * @param int $month Month number. |
|
4584 * @param int $day Day number. |
|
4585 * @param int $year Year number. |
|
4586 * @param string $source_date The date to filter. |
|
4587 * @return bool True if valid date, false if not valid date. |
4026 */ |
4588 */ |
4027 function wp_checkdate( $month, $day, $year, $source_date ) { |
4589 function wp_checkdate( $month, $day, $year, $source_date ) { |
|
4590 /** |
|
4591 * Filter whether the given date is valid for the Gregorian calendar. |
|
4592 * |
|
4593 * @since 3.5.0 |
|
4594 * |
|
4595 * @param bool $checkdate Whether the given date is valid. |
|
4596 * @param string $source_date Date to check. |
|
4597 */ |
4028 return apply_filters( 'wp_checkdate', checkdate( $month, $day, $year ), $source_date ); |
4598 return apply_filters( 'wp_checkdate', checkdate( $month, $day, $year ), $source_date ); |
4029 } |
4599 } |
4030 |
4600 |
4031 /** |
4601 /** |
4032 * Load the auth check for monitoring whether the user is still logged in. |
4602 * Load the auth check for monitoring whether the user is still logged in. |
4105 * |
4689 * |
4106 * Send a result that shows a log-in box if the user is no longer logged in, |
4690 * Send a result that shows a log-in box if the user is no longer logged in, |
4107 * or if their cookie is within the grace period. |
4691 * or if their cookie is within the grace period. |
4108 * |
4692 * |
4109 * @since 3.6.0 |
4693 * @since 3.6.0 |
4110 */ |
4694 * |
4111 function wp_auth_check( $response, $data ) { |
4695 * @param array|object $response The Heartbeat response object or array. |
|
4696 * @return array|object $response The Heartbeat response object or array with 'wp-auth-check' |
|
4697 * value set. |
|
4698 */ |
|
4699 function wp_auth_check( $response ) { |
4112 $response['wp-auth-check'] = is_user_logged_in() && empty( $GLOBALS['login_grace_period'] ); |
4700 $response['wp-auth-check'] = is_user_logged_in() && empty( $GLOBALS['login_grace_period'] ); |
4113 return $response; |
4701 return $response; |
4114 } |
4702 } |
4115 |
4703 |
4116 /** |
4704 /** |
4117 * Return RegEx body to liberally match an opening HTML tag that: |
4705 * Return RegEx body to liberally match an opening HTML tag. |
|
4706 * |
|
4707 * Matches an opening HTML tag that: |
4118 * 1. Is self-closing or |
4708 * 1. Is self-closing or |
4119 * 2. Has no body but has a closing tag of the same name or |
4709 * 2. Has no body but has a closing tag of the same name or |
4120 * 3. Contains a body and a closing tag of the same name |
4710 * 3. Contains a body and a closing tag of the same name |
4121 * |
4711 * |
4122 * Note: this RegEx does not balance inner tags and does not attempt to produce valid HTML |
4712 * Note: this RegEx does not balance inner tags and does not attempt |
|
4713 * to produce valid HTML |
4123 * |
4714 * |
4124 * @since 3.6.0 |
4715 * @since 3.6.0 |
4125 * |
4716 * |
4126 * @param string $tag An HTML tag name. Example: 'video' |
4717 * @param string $tag An HTML tag name. Example: 'video'. |
4127 * @return string |
4718 * @return string Tag RegEx. |
4128 */ |
4719 */ |
4129 function get_tag_regex( $tag ) { |
4720 function get_tag_regex( $tag ) { |
4130 if ( empty( $tag ) ) |
4721 if ( empty( $tag ) ) |
4131 return; |
4722 return; |
4132 return sprintf( '<%1$s[^<]*(?:>[\s\S]*<\/%1$s>|\s*\/>)', tag_escape( $tag ) ); |
4723 return sprintf( '<%1$s[^<]*(?:>[\s\S]*<\/%1$s>|\s*\/>)', tag_escape( $tag ) ); |
4133 } |
4724 } |
4134 |
4725 |
4135 /** |
4726 /** |
4136 * Return a canonical form of the provided charset appropriate for passing to PHP |
4727 * Retrieve a canonical form of the provided charset appropriate for passing to PHP |
4137 * functions such as htmlspecialchars() and charset html attributes. |
4728 * functions such as htmlspecialchars() and charset html attributes. |
4138 * |
4729 * |
4139 * @link http://core.trac.wordpress.org/ticket/23688 |
|
4140 * @since 3.6.0 |
4730 * @since 3.6.0 |
4141 * |
4731 * @access private |
4142 * @param string A charset name |
4732 * |
4143 * @return string The canonical form of the charset |
4733 * @see https://core.trac.wordpress.org/ticket/23688 |
|
4734 * |
|
4735 * @param string $charset A charset name. |
|
4736 * @return string The canonical form of the charset. |
4144 */ |
4737 */ |
4145 function _canonical_charset( $charset ) { |
4738 function _canonical_charset( $charset ) { |
4146 if ( 'UTF-8' === $charset || 'utf-8' === $charset || 'utf8' === $charset || |
4739 if ( 'UTF-8' === $charset || 'utf-8' === $charset || 'utf8' === $charset || |
4147 'UTF8' === $charset ) |
4740 'UTF8' === $charset ) |
4148 return 'UTF-8'; |
4741 return 'UTF-8'; |
4153 |
4746 |
4154 return $charset; |
4747 return $charset; |
4155 } |
4748 } |
4156 |
4749 |
4157 /** |
4750 /** |
4158 * Sets the mbstring internal encoding to a binary safe encoding whne func_overload is enabled. |
4751 * Set the mbstring internal encoding to a binary safe encoding when func_overload |
4159 * |
4752 * is enabled. |
4160 * When mbstring.func_overload is in use for multi-byte encodings, the results from strlen() and |
4753 * |
4161 * similar functions respect the utf8 characters, causing binary data to return incorrect lengths. |
4754 * When mbstring.func_overload is in use for multi-byte encodings, the results from |
4162 * |
4755 * strlen() and similar functions respect the utf8 characters, causing binary data |
4163 * This function overrides the mbstring encoding to a binary-safe encoding, and resets it to the |
4756 * to return incorrect lengths. |
4164 * users expected encoding afterwards through the `reset_mbstring_encoding` function. |
4757 * |
4165 * |
4758 * This function overrides the mbstring encoding to a binary-safe encoding, and |
4166 * It is safe to recursively call this function, however each `mbstring_binary_safe_encoding()` |
4759 * resets it to the users expected encoding afterwards through the |
4167 * call must be followed up with an equal number of `reset_mbstring_encoding()` calls. |
4760 * `reset_mbstring_encoding` function. |
|
4761 * |
|
4762 * It is safe to recursively call this function, however each |
|
4763 * `mbstring_binary_safe_encoding()` call must be followed up with an equal number |
|
4764 * of `reset_mbstring_encoding()` calls. |
|
4765 * |
|
4766 * @since 3.7.0 |
4168 * |
4767 * |
4169 * @see reset_mbstring_encoding() |
4768 * @see reset_mbstring_encoding() |
4170 * |
4769 * |
4171 * @since 3.7.0 |
4770 * @param bool $reset Optional. Whether to reset the encoding back to a previously-set encoding. |
4172 * |
4771 * Default false. |
4173 * @param bool $reset Whether to reset the encoding back to a previously-set encoding. |
|
4174 */ |
4772 */ |
4175 function mbstring_binary_safe_encoding( $reset = false ) { |
4773 function mbstring_binary_safe_encoding( $reset = false ) { |
4176 static $encodings = array(); |
4774 static $encodings = array(); |
4177 static $overloaded = null; |
4775 static $overloaded = null; |
4178 |
4776 |