1<?php
2/**
3 * Main WordPress Formatting API.
4 *
5 * Handles many functions for formatting output.
6 *
7 * @package WordPress
8 */
9
10/**
11 * Replaces common plain text characters with formatted entities.
12 *
13 * Returns given text with transformations of quotes into smart quotes, apostrophes,
14 * dashes, ellipses, the trademark symbol, and the multiplication symbol.
15 *
16 * As an example,
17 *
18 * 'cause today's effort makes it worth tomorrow's "holiday" ...
19 *
20 * Becomes:
21 *
22 * ’cause today’s effort makes it worth tomorrow’s “holiday” …
23 *
24 * Code within certain HTML blocks are skipped.
25 *
26 * Do not use this function before the {@see 'init'} action hook; everything will break.
27 *
28 * @since 0.71
29 *
30 * @global array $wp_cockneyreplace Array of formatted entities for certain common phrases.
31 * @global array $shortcode_tags
32 *
33 * @param string $text The text to be formatted.
34 * @param bool $reset Set to true for unit testing. Translated patterns will reset.
35 * @return string The string replaced with HTML entities.
36 */
37function wptexturize( $text, $reset = false ) {
38 global $wp_cockneyreplace, $shortcode_tags;
39 static $static_characters = null,
40 $static_replacements = null,
41 $dynamic_characters = null,
42 $dynamic_replacements = null,
43 $default_no_texturize_tags = null,
44 $default_no_texturize_shortcodes = null,
45 $run_texturize = true,
46 $apos = null,
47 $prime = null,
48 $double_prime = null,
49 $opening_quote = null,
50 $closing_quote = null,
51 $opening_single_quote = null,
52 $closing_single_quote = null,
53 $open_q_flag = '<!--oq-->',
54 $open_sq_flag = '<!--osq-->',
55 $apos_flag = '<!--apos-->';
56
57 // If there's nothing to do, just stop.
58 if ( empty( $text ) || false === $run_texturize ) {
59 return $text;
60 }
61
62 // Set up static variables. Run once only.
63 if ( $reset || ! isset( $static_characters ) ) {
64 /**
65 * Filters whether to skip running wptexturize().
66 *
67 * Returning false from the filter will effectively short-circuit wptexturize()
68 * and return the original text passed to the function instead.
69 *
70 * The filter runs only once, the first time wptexturize() is called.
71 *
72 * @since 4.0.0
73 *
74 * @see wptexturize()
75 *
76 * @param bool $run_texturize Whether to short-circuit wptexturize().
77 */
78 $run_texturize = apply_filters( 'run_wptexturize', $run_texturize );
79 if ( false === $run_texturize ) {
80 return $text;
81 }
82
83 /* translators: Opening curly double quote. */
84 $opening_quote = _x( '“', 'opening curly double quote' );
85 /* translators: Closing curly double quote. */
86 $closing_quote = _x( '”', 'closing curly double quote' );
87
88 /* translators: Apostrophe, for example in 'cause or can't. */
89 $apos = _x( '’', 'apostrophe' );
90
91 /* translators: Prime, for example in 9' (nine feet). */
92 $prime = _x( '′', 'prime' );
93 /* translators: Double prime, for example in 9" (nine inches). */
94 $double_prime = _x( '″', 'double prime' );
95
96 /* translators: Opening curly single quote. */
97 $opening_single_quote = _x( '‘', 'opening curly single quote' );
98 /* translators: Closing curly single quote. */
99 $closing_single_quote = _x( '’', 'closing curly single quote' );
100
101 /* translators: En dash. */
102 $en_dash = _x( '–', 'en dash' );
103 /* translators: Em dash. */
104 $em_dash = _x( '—', 'em dash' );
105
106 $default_no_texturize_tags = array( 'pre', 'code', 'kbd', 'style', 'script', 'tt' );
107 $default_no_texturize_shortcodes = array( 'code' );
108
109 // If a plugin has provided an autocorrect array, use it.
110 if ( isset( $wp_cockneyreplace ) ) {
111 $cockney = array_keys( $wp_cockneyreplace );
112 $cockneyreplace = array_values( $wp_cockneyreplace );
113 } else {
114 /*
115 * translators: This is a comma-separated list of words that defy the syntax of quotations in normal use,
116 * for example... 'We do not have enough words yet'... is a typical quoted phrase. But when we write
117 * lines of code 'til we have enough of 'em, then we need to insert apostrophes instead of quotes.
118 */
119 $cockney = explode(
120 ',',
121 _x(
122 "'tain't,'twere,'twas,'tis,'twill,'til,'bout,'nuff,'round,'cause,'em",
123 'Comma-separated list of words to texturize in your language'
124 )
125 );
126
127 $cockneyreplace = explode(
128 ',',
129 _x(
130 '’tain’t,’twere,’twas,’tis,’twill,’til,’bout,’nuff,’round,’cause,’em',
131 'Comma-separated list of replacement words in your language'
132 )
133 );
134 }
135
136 $static_characters = array_merge( array( '...', '``', '\'\'', ' (tm)' ), $cockney );
137 $static_replacements = array_merge( array( '…', $opening_quote, $closing_quote, ' ™' ), $cockneyreplace );
138
139 /*
140 * Pattern-based replacements of characters.
141 * Sort the remaining patterns into several arrays for performance tuning.
142 */
143 $dynamic_characters = array(
144 'apos' => array(),
145 'quote' => array(),
146 'dash' => array(),
147 );
148 $dynamic_replacements = array(
149 'apos' => array(),
150 'quote' => array(),
151 'dash' => array(),
152 );
153 $dynamic = array();
154 $spaces = wp_spaces_regexp();
155
156 // '99' and '99" are ambiguous among other patterns; assume it's an abbreviated year at the end of a quotation.
157 if ( "'" !== $apos || "'" !== $closing_single_quote ) {
158 $dynamic[ '/\'(\d\d)\'(?=\Z|[.,:;!?)}\-\]]|>|' . $spaces . ')/' ] = $apos_flag . '$1' . $closing_single_quote;
159 }
160 if ( "'" !== $apos || '"' !== $closing_quote ) {
161 $dynamic[ '/\'(\d\d)"(?=\Z|[.,:;!?)}\-\]]|>|' . $spaces . ')/' ] = $apos_flag . '$1' . $closing_quote;
162 }
163
164 // '99 '99s '99's (apostrophe) But never '9 or '99% or '999 or '99.0.
165 if ( "'" !== $apos ) {
166 $dynamic['/\'(?=\d\d(?:\Z|(?![%\d]|[.,]\d)))/'] = $apos_flag;
167 }
168
169 // Quoted numbers like '0.42'.
170 if ( "'" !== $opening_single_quote && "'" !== $closing_single_quote ) {
171 $dynamic[ '/(?<=\A|' . $spaces . ')\'(\d[.,\d]*)\'/' ] = $open_sq_flag . '$1' . $closing_single_quote;
172 }
173
174 // Single quote at start, or preceded by (, {, <, [, ", -, or spaces.
175 if ( "'" !== $opening_single_quote ) {
176 $dynamic[ '/(?<=\A|[([{"\-]|<|' . $spaces . ')\'/' ] = $open_sq_flag;
177 }
178
179 // Apostrophe in a word. No spaces, double apostrophes, or other punctuation.
180 if ( "'" !== $apos ) {
181 $dynamic[ '/(?<!' . $spaces . ')\'(?!\Z|[.,:;!?"\'(){}[\]\-]|&[lg]t;|' . $spaces . ')/' ] = $apos_flag;
182 }
183
184 $dynamic_characters['apos'] = array_keys( $dynamic );
185 $dynamic_replacements['apos'] = array_values( $dynamic );
186 $dynamic = array();
187
188 // Quoted numbers like "42".
189 if ( '"' !== $opening_quote && '"' !== $closing_quote ) {
190 $dynamic[ '/(?<=\A|' . $spaces . ')"(\d[.,\d]*)"/' ] = $open_q_flag . '$1' . $closing_quote;
191 }
192
193 // Double quote at start, or preceded by (, {, <, [, -, or spaces, and not followed by spaces.
194 if ( '"' !== $opening_quote ) {
195 $dynamic[ '/(?<=\A|[([{\-]|<|' . $spaces . ')"(?!' . $spaces . ')/' ] = $open_q_flag;
196 }
197
198 $dynamic_characters['quote'] = array_keys( $dynamic );
199 $dynamic_replacements['quote'] = array_values( $dynamic );
200 $dynamic = array();
201
202 // Dashes and spaces.
203 $dynamic['/---/'] = $em_dash;
204 $dynamic[ '/(?<=^|' . $spaces . ')--(?=$|' . $spaces . ')/' ] = $em_dash;
205 $dynamic['/(?<!xn)--/'] = $en_dash;
206 $dynamic[ '/(?<=^|' . $spaces . ')-(?=$|' . $spaces . ')/' ] = $en_dash;
207
208 $dynamic_characters['dash'] = array_keys( $dynamic );
209 $dynamic_replacements['dash'] = array_values( $dynamic );
210 }
211
212 // Must do this every time in case plugins use these filters in a context sensitive manner.
213 /**
214 * Filters the list of HTML elements not to texturize.
215 *
216 * @since 2.8.0
217 *
218 * @param string[] $default_no_texturize_tags An array of HTML element names.
219 */
220 $no_texturize_tags = apply_filters( 'no_texturize_tags', $default_no_texturize_tags );
221 /**
222 * Filters the list of shortcodes not to texturize.
223 *
224 * @since 2.8.0
225 *
226 * @param string[] $default_no_texturize_shortcodes An array of shortcode names.
227 */
228 $no_texturize_shortcodes = apply_filters( 'no_texturize_shortcodes', $default_no_texturize_shortcodes );
229
230 $no_texturize_tags_stack = array();
231 $no_texturize_shortcodes_stack = array();
232
233 // Look for shortcodes and HTML elements.
234
235 preg_match_all( '@\[/?([^<>&/\[\]\x00-\x20=]++)@', $text, $matches );
236 $tagnames = array_intersect( array_keys( $shortcode_tags ), $matches[1] );
237 $found_shortcodes = ! empty( $tagnames );
238 $shortcode_regex = $found_shortcodes ? _get_wptexturize_shortcode_regex( $tagnames ) : '';
239 $regex = _get_wptexturize_split_regex( $shortcode_regex );
240
241 $textarr = preg_split( $regex, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
242
243 foreach ( $textarr as &$curl ) {
244 // Only call _wptexturize_pushpop_element if $curl is a delimiter.
245 $first = $curl[0];
246 if ( '<' === $first ) {
247 if ( str_starts_with( $curl, '<!--' ) ) {
248 // This is an HTML comment delimiter.
249 continue;
250 } else {
251 // This is an HTML element delimiter.
252
253 // Replace each & with & unless it already looks like an entity.
254 $curl = preg_replace( '/&(?!#(?:\d+|x[a-f0-9]+);|[a-z1-4]{1,8};)/i', '&', $curl );
255
256 _wptexturize_pushpop_element( $curl, $no_texturize_tags_stack, $no_texturize_tags );
257 }
258 } elseif ( '' === trim( $curl ) ) {
259 // This is a newline between delimiters. Performance improves when we check this.
260 continue;
261
262 } elseif ( '[' === $first && $found_shortcodes && 1 === preg_match( '/^' . $shortcode_regex . '$/', $curl ) ) {
263 // This is a shortcode delimiter.
264
265 if ( ! str_starts_with( $curl, '[[' ) && ! str_ends_with( $curl, ']]' ) ) {
266 // Looks like a normal shortcode.
267 _wptexturize_pushpop_element( $curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes );
268 } else {
269 // Looks like an escaped shortcode.
270 continue;
271 }
272 } elseif ( empty( $no_texturize_shortcodes_stack ) && empty( $no_texturize_tags_stack ) ) {
273 // This is neither a delimiter, nor is this content inside of no_texturize pairs. Do texturize.
274
275 $curl = str_replace( $static_characters, $static_replacements, $curl );
276
277 if ( str_contains( $curl, "'" ) ) {
278 $curl = preg_replace( $dynamic_characters['apos'], $dynamic_replacements['apos'], $curl );
279 $curl = wptexturize_primes( $curl, "'", $prime, $open_sq_flag, $closing_single_quote );
280 $curl = str_replace( $apos_flag, $apos, $curl );
281 $curl = str_replace( $open_sq_flag, $opening_single_quote, $curl );
282 }
283 if ( str_contains( $curl, '"' ) ) {
284 $curl = preg_replace( $dynamic_characters['quote'], $dynamic_replacements['quote'], $curl );
285 $curl = wptexturize_primes( $curl, '"', $double_prime, $open_q_flag, $closing_quote );
286 $curl = str_replace( $open_q_flag, $opening_quote, $curl );
287 }
288 if ( str_contains( $curl, '-' ) ) {
289 $curl = preg_replace( $dynamic_characters['dash'], $dynamic_replacements['dash'], $curl );
290 }
291
292 // 9x9 (times), but never 0x9999.
293 if ( 1 === preg_match( '/(?<=\d)x\d/', $curl ) ) {
294 // Searching for a digit is 10 times more expensive than for the x, so we avoid doing this one!
295 $curl = preg_replace( '/\b(\d(?(?<=0)[\d\.,]+|[\d\.,]*))x(\d[\d\.,]*)\b/', '$1×$2', $curl );
296 }
297
298 // Replace each & with & unless it already looks like an entity.
299 $curl = preg_replace( '/&(?!#(?:\d+|x[a-f0-9]+);|[a-z1-4]{1,8};)/i', '&', $curl );
300 }
301 }
302
303 return implode( '', $textarr );
304}
305
306/**
307 * Implements a logic tree to determine whether or not "7'." represents seven feet,
308 * then converts the special char into either a prime char or a closing quote char.
309 *
310 * @since 4.3.0
311 *
312 * @param string $haystack The plain text to be searched.
313 * @param string $needle The character to search for such as ' or ".
314 * @param string $prime The prime char to use for replacement.
315 * @param string $open_quote The opening quote char. Opening quote replacement must be
316 * accomplished already.
317 * @param string $close_quote The closing quote char to use for replacement.
318 * @return string The $haystack value after primes and quotes replacements.
319 */
320function wptexturize_primes( $haystack, $needle, $prime, $open_quote, $close_quote ) {
321 $spaces = wp_spaces_regexp();
322 $flag = '<!--wp-prime-or-quote-->';
323 $quote_pattern = "/$needle(?=\\Z|[.,:;!?)}\\-\\]]|>|" . $spaces . ')/';
324 $prime_pattern = "/(?<=\\d)$needle/";
325 $flag_after_digit = "/(?<=\\d)$flag/";
326 $flag_no_digit = "/(?<!\\d)$flag/";
327
328 $sentences = explode( $open_quote, $haystack );
329
330 foreach ( $sentences as $key => &$sentence ) {
331 if ( ! str_contains( $sentence, $needle ) ) {
332 continue;
333 } elseif ( 0 !== $key && 0 === substr_count( $sentence, $close_quote ) ) {
334 $sentence = preg_replace( $quote_pattern, $flag, $sentence, -1, $count );
335 if ( $count > 1 ) {
336 // This sentence appears to have multiple closing quotes. Attempt Vulcan logic.
337 $sentence = preg_replace( $flag_no_digit, $close_quote, $sentence, -1, $count2 );
338 if ( 0 === $count2 ) {
339 // Try looking for a quote followed by a period.
340 $count2 = substr_count( $sentence, "$flag." );
341 if ( $count2 > 0 ) {
342 // Assume the rightmost quote-period match is the end of quotation.
343 $pos = strrpos( $sentence, "$flag." );
344 } else {
345 /*
346 * When all else fails, make the rightmost candidate a closing quote.
347 * This is most likely to be problematic in the context of bug #18549.
348 */
349 $pos = strrpos( $sentence, $flag );
350 }
351 $sentence = substr_replace( $sentence, $close_quote, $pos, strlen( $flag ) );
352 }
353 // Use conventional replacement on any remaining primes and quotes.
354 $sentence = preg_replace( $prime_pattern, $prime, $sentence );
355 $sentence = preg_replace( $flag_after_digit, $prime, $sentence );
356 $sentence = str_replace( $flag, $close_quote, $sentence );
357 } elseif ( 1 === $count ) {
358 // Found only one closing quote candidate, so give it priority over primes.
359 $sentence = str_replace( $flag, $close_quote, $sentence );
360 $sentence = preg_replace( $prime_pattern, $prime, $sentence );
361 } else {
362 // No closing quotes found. Just run primes pattern.
363 $sentence = preg_replace( $prime_pattern, $prime, $sentence );
364 }
365 } else {
366 $sentence = preg_replace( $prime_pattern, $prime, $sentence );
367 $sentence = preg_replace( $quote_pattern, $close_quote, $sentence );
368 }
369 if ( '"' === $needle && str_contains( $sentence, '"' ) ) {
370 $sentence = str_replace( '"', $close_quote, $sentence );
371 }
372 }
373
374 return implode( $open_quote, $sentences );
375}
376
377/**
378 * Searches for disabled element tags. Pushes element to stack on tag open
379 * and pops on tag close.
380 *
381 * Assumes first char of `$text` is tag opening and last char is tag closing.
382 * Assumes second char of `$text` is optionally `/` to indicate closing as in `</html>`.
383 *
384 * @since 2.9.0
385 * @access private
386 *
387 * @param string $text Text to check. Must be a tag like `<html>` or `[shortcode]`.
388 * @param string[] $stack Array of open tag elements.
389 * @param string[] $disabled_elements Array of tag names to match against. Spaces are not allowed in tag names.
390 */
391function _wptexturize_pushpop_element( $text, &$stack, $disabled_elements ) {
392 // Is it an opening tag or closing tag?
393 if ( isset( $text[1] ) && '/' !== $text[1] ) {
394 $opening_tag = true;
395 $name_offset = 1;
396 } elseif ( 0 === count( $stack ) ) {
397 // Stack is empty. Just stop.
398 return;
399 } else {
400 $opening_tag = false;
401 $name_offset = 2;
402 }
403
404 // Parse out the tag name.
405 $space = strpos( $text, ' ' );
406 if ( false === $space ) {
407 $space = -1;
408 } else {
409 $space -= $name_offset;
410 }
411 $tag = substr( $text, $name_offset, $space );
412
413 // Handle disabled tags.
414 if ( in_array( $tag, $disabled_elements, true ) ) {
415 if ( $opening_tag ) {
416 /*
417 * This disables texturize until we find a closing tag of our type
418 * (e.g. <pre>) even if there was invalid nesting before that.
419 *
420 * Example: in the case <pre>sadsadasd</code>"baba"</pre>
421 * "baba" won't be texturized.
422 */
423
424 array_push( $stack, $tag );
425 } elseif ( end( $stack ) === $tag ) {
426 array_pop( $stack );
427 }
428 }
429}
430
431/**
432 * Replaces double line breaks with paragraph elements.
433 *
434 * A group of regex replaces used to identify text formatted with newlines and
435 * replace double line breaks with HTML paragraph tags. The remaining line breaks
436 * after conversion become `<br />` tags, unless `$br` is set to '0' or 'false'.
437 *
438 * @since 0.71
439 *
440 * @param string $text The text which has to be formatted.
441 * @param bool $br Optional. If set, this will convert all remaining line breaks
442 * after paragraphing. Line breaks within `<script>`, `<style>`,
443 * and `<svg>` tags are not affected. Default true.
444 * @return string Text which has been converted into correct paragraph tags.
445 */
446function wpautop( $text, $br = true ) {
447 $pre_tags = array();
448
449 if ( '' === trim( $text ) ) {
450 return '';
451 }
452
453 // Just to make things a little easier, pad the end.
454 $text = $text . "\n";
455
456 /*
457 * Pre tags shouldn't be touched by autop.
458 * Replace pre tags with placeholders and bring them back after autop.
459 */
460 if ( str_contains( $text, '<pre' ) ) {
461 $text_parts = explode( '</pre>', $text );
462 $last_part = array_pop( $text_parts );
463 $text = '';
464 $i = 0;
465
466 foreach ( $text_parts as $text_part ) {
467 $start = strpos( $text_part, '<pre' );
468
469 // Malformed HTML?
470 if ( false === $start ) {
471 $text .= $text_part;
472 continue;
473 }
474
475 $name = "<pre wp-pre-tag-$i></pre>";
476 $pre_tags[ $name ] = substr( $text_part, $start ) . '</pre>';
477
478 $text .= substr( $text_part, 0, $start ) . $name;
479 ++$i;
480 }
481
482 $text .= $last_part;
483 }
484 // Change multiple <br>'s into two line breaks, which will turn into paragraphs.
485 $text = preg_replace( '|<br\s*/?>\s*<br\s*/?>|', "\n\n", $text );
486
487 $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|form|map|area|blockquote|address|style|p|h[1-6]|hr|fieldset|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
488
489 // Add a double line break above block-level opening tags.
490 $text = preg_replace( '!(<' . $allblocks . '[\s/>])!', "\n\n$1", $text );
491
492 // Add a double line break below block-level closing tags.
493 $text = preg_replace( '!(</' . $allblocks . '>)!', "$1\n\n", $text );
494
495 // Add a double line break after hr tags, which are self closing.
496 $text = preg_replace( '!(<hr\s*?/?>)!', "$1\n\n", $text );
497
498 // Standardize newline characters to "\n".
499 $text = str_replace( array( "\r\n", "\r" ), "\n", $text );
500
501 // Find newlines in all elements and add placeholders.
502 $text = wp_replace_in_html_tags( $text, array( "\n" => ' <!-- wpnl --> ' ) );
503
504 // Collapse line breaks before and after <option> elements so they don't get autop'd.
505 if ( str_contains( $text, '<option' ) ) {
506 $text = preg_replace( '|\s*<option|', '<option', $text );
507 $text = preg_replace( '|</option>\s*|', '</option>', $text );
508 }
509
510 /*
511 * Collapse line breaks inside <object> elements, before <param> and <embed> elements
512 * so they don't get autop'd.
513 */
514 if ( str_contains( $text, '</object>' ) ) {
515 $text = preg_replace( '|(<object[^>]*>)\s*|', '$1', $text );
516 $text = preg_replace( '|\s*</object>|', '</object>', $text );
517 $text = preg_replace( '%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $text );
518 }
519
520 /*
521 * Collapse line breaks inside <audio> and <video> elements,
522 * before and after <source> and <track> elements.
523 */
524 if ( str_contains( $text, '<source' ) || str_contains( $text, '<track' ) ) {
525 $text = preg_replace( '%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $text );
526 $text = preg_replace( '%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $text );
527 $text = preg_replace( '%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $text );
528 }
529
530 // Collapse line breaks before and after <figcaption> elements.
531 if ( str_contains( $text, '<figcaption' ) ) {
532 $text = preg_replace( '|\s*(<figcaption[^>]*>)|', '$1', $text );
533 $text = preg_replace( '|</figcaption>\s*|', '</figcaption>', $text );
534 }
535
536 // Remove more than two contiguous line breaks.
537 $text = preg_replace( "/\n\n+/", "\n\n", $text );
538
539 // Split up the contents into an array of strings, separated by double line breaks.
540 $paragraphs = preg_split( '/\n\s*\n/', $text, -1, PREG_SPLIT_NO_EMPTY );
541
542 // Reset $text prior to rebuilding.
543 $text = '';
544
545 // Rebuild the content as a string, wrapping every bit with a <p>.
546 foreach ( $paragraphs as $paragraph ) {
547 $text .= '<p>' . trim( $paragraph, "\n" ) . "</p>\n";
548 }
549
550 // Under certain strange conditions it could create a P of entirely whitespace.
551 $text = preg_replace( '|<p>\s*</p>|', '', $text );
552
553 // Add a closing <p> inside <div>, <address>, or <form> tag if missing.
554 $text = preg_replace( '!<p>([^<]+)</(div|address|form)>!', '<p>$1</p></$2>', $text );
555
556 // If an opening or closing block element tag is wrapped in a <p>, unwrap it.
557 $text = preg_replace( '!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', '$1', $text );
558
559 // In some cases <li> may get wrapped in <p>, fix them.
560 $text = preg_replace( '|<p>(<li.+?)</p>|', '$1', $text );
561
562 // If a <blockquote> is wrapped with a <p>, move it inside the <blockquote>.
563 $text = preg_replace( '|<p><blockquote([^>]*)>|i', '<blockquote$1><p>', $text );
564 $text = str_replace( '</blockquote></p>', '</p></blockquote>', $text );
565
566 // If an opening or closing block element tag is preceded by an opening <p> tag, remove it.
567 $text = preg_replace( '!<p>\s*(</?' . $allblocks . '[^>]*>)!', '$1', $text );
568
569 // If an opening or closing block element tag is followed by a closing <p> tag, remove it.
570 $text = preg_replace( '!(</?' . $allblocks . '[^>]*>)\s*</p>!', '$1', $text );
571
572 // Optionally insert line breaks.
573 if ( $br ) {
574 // Replace newlines that shouldn't be touched with a placeholder.
575 $text = preg_replace_callback( '/<(script|style|svg|math).*?<\/\\1>/s', '_autop_newline_preservation_helper', $text );
576
577 // Normalize <br>.
578 $text = str_replace( array( '<br>', '<br/>' ), '<br />', $text );
579
580 // Replace any new line characters that aren't preceded by a <br /> with a <br />.
581 $text = preg_replace( '|(?<!<br />)\s*\n|', "<br />\n", $text );
582
583 // Replace newline placeholders with newlines.
584 $text = str_replace( '<WPPreserveNewline />', "\n", $text );
585 }
586
587 // If a <br /> tag is after an opening or closing block tag, remove it.
588 $text = preg_replace( '!(</?' . $allblocks . '[^>]*>)\s*<br />!', '$1', $text );
589
590 // If a <br /> tag is before a subset of opening or closing block tags, remove it.
591 $text = preg_replace( '!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $text );
592 $text = preg_replace( "|\n</p>$|", '</p>', $text );
593
594 // Replace placeholder <pre> tags with their original content.
595 if ( ! empty( $pre_tags ) ) {
596 $text = str_replace( array_keys( $pre_tags ), array_values( $pre_tags ), $text );
597 }
598
599 // Restore newlines in all elements.
600 if ( str_contains( $text, '<!-- wpnl -->' ) ) {
601 $text = str_replace( array( ' <!-- wpnl --> ', '<!-- wpnl -->' ), "\n", $text );
602 }
603
604 return $text;
605}
606
607/**
608 * Separates HTML elements and comments from the text.
609 *
610 * @since 4.2.4
611 *
612 * @param string $input The text which has to be formatted.
613 * @return string[] Array of the formatted text.
614 */
615function wp_html_split( $input ) {
616 return preg_split( get_html_split_regex(), $input, -1, PREG_SPLIT_DELIM_CAPTURE );
617}
618
619/**
620 * Retrieves the regular expression for an HTML element.
621 *
622 * @since 4.4.0
623 *
624 * @return string The regular expression.
625 */
626function get_html_split_regex() {
627 static $regex;
628
629 if ( ! isset( $regex ) ) {
630 // phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound -- don't remove regex indentation
631 $comments =
632 '!' // Start of comment, after the <.
633 . '(?:' // Unroll the loop: Consume everything until --> is found.
634 . '-(?!->)' // Dash not followed by end of comment.
635 . '[^\-]*+' // Consume non-dashes.
636 . ')*+' // Loop possessively.
637 . '(?:-->)?'; // End of comment. If not found, match all input.
638
639 $cdata =
640 '!\[CDATA\[' // Start of comment, after the <.
641 . '[^\]]*+' // Consume non-].
642 . '(?:' // Unroll the loop: Consume everything until ]]> is found.
643 . '](?!]>)' // One ] not followed by end of comment.
644 . '[^\]]*+' // Consume non-].
645 . ')*+' // Loop possessively.
646 . '(?:]]>)?'; // End of comment. If not found, match all input.
647
648 $escaped =
649 '(?=' // Is the element escaped?
650 . '!--'
651 . '|'
652 . '!\[CDATA\['
653 . ')'
654 . '(?(?=!-)' // If yes, which type?
655 . $comments
656 . '|'
657 . $cdata
658 . ')';
659
660 $regex =
661 '/(' // Capture the entire match.
662 . '<' // Find start of element.
663 . '(?' // Conditional expression follows.
664 . $escaped // Find end of escaped element.
665 . '|' // ...else...
666 . '[^>]*>?' // Find end of normal element.
667 . ')'
668 . ')/';
669 // phpcs:enable
670 }
671
672 return $regex;
673}
674
675/**
676 * Retrieves the combined regular expression for HTML and shortcodes.
677 *
678 * @access private
679 * @ignore
680 * @internal This function will be removed in 4.5.0 per Shortcode API Roadmap.
681 * @since 4.4.0
682 *
683 * @param string $shortcode_regex Optional. The result from _get_wptexturize_shortcode_regex().
684 * @return string The regular expression.
685 */
686function _get_wptexturize_split_regex( $shortcode_regex = '' ) {
687 static $html_regex;
688
689 if ( ! isset( $html_regex ) ) {
690 // phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound -- don't remove regex indentation
691 $comment_regex =
692 '!' // Start of comment, after the <.
693 . '(?:' // Unroll the loop: Consume everything until --> is found.
694 . '-(?!->)' // Dash not followed by end of comment.
695 . '[^\-]*+' // Consume non-dashes.
696 . ')*+' // Loop possessively.
697 . '(?:-->)?'; // End of comment. If not found, match all input.
698
699 $html_regex = // Needs replaced with wp_html_split() per Shortcode API Roadmap.
700 '<' // Find start of element.
701 . '(?(?=!--)' // Is this a comment?
702 . $comment_regex // Find end of comment.
703 . '|'
704 . '[^>]*>?' // Find end of element. If not found, match all input.
705 . ')';
706 // phpcs:enable
707 }
708
709 if ( empty( $shortcode_regex ) ) {
710 $regex = '/(' . $html_regex . ')/';
711 } else {
712 $regex = '/(' . $html_regex . '|' . $shortcode_regex . ')/';
713 }
714
715 return $regex;
716}
717
718/**
719 * Retrieves the regular expression for shortcodes.
720 *
721 * @access private
722 * @ignore
723 * @since 4.4.0
724 *
725 * @param string[] $tagnames Array of shortcodes to find.
726 * @return string The regular expression.
727 */
728function _get_wptexturize_shortcode_regex( $tagnames ) {
729 $tagregexp = implode( '|', array_map( 'preg_quote', $tagnames ) );
730 $tagregexp = "(?:$tagregexp)(?=[\\s\\]\\/])"; // Excerpt of get_shortcode_regex().
731 // phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound -- don't remove regex indentation
732 $regex =
733 '\[' // Find start of shortcode.
734 . '[\/\[]?' // Shortcodes may begin with [/ or [[.
735 . $tagregexp // Only match registered shortcodes, because performance.
736 . '(?:'
737 . '[^\[\]<>]+' // Shortcodes do not contain other shortcodes. Quantifier critical.
738 . '|'
739 . '<[^\[\]>]*>' // HTML elements permitted. Prevents matching ] before >.
740 . ')*+' // Possessive critical.
741 . '\]' // Find end of shortcode.
742 . '\]?'; // Shortcodes may end with ]].
743 // phpcs:enable
744
745 return $regex;
746}
747
748/**
749 * Replaces characters or phrases within HTML elements only.
750 *
751 * @since 4.2.3
752 *
753 * @param string $haystack The text which has to be formatted.
754 * @param array $replace_pairs In the form array('from' => 'to', ...).
755 * @return string The formatted text.
756 */
757function wp_replace_in_html_tags( $haystack, $replace_pairs ) {
758 // Find all elements.
759 $textarr = wp_html_split( $haystack );
760 $changed = false;
761
762 // Optimize when searching for one item.
763 if ( 1 === count( $replace_pairs ) ) {
764 // Extract $needle and $replace.
765 $needle = array_key_first( $replace_pairs );
766 $replace = $replace_pairs[ $needle ];
767
768 // Loop through delimiters (elements) only.
769 for ( $i = 1, $c = count( $textarr ); $i < $c; $i += 2 ) {
770 if ( str_contains( $textarr[ $i ], $needle ) ) {
771 $textarr[ $i ] = str_replace( $needle, $replace, $textarr[ $i ] );
772 $changed = true;
773 }
774 }
775 } else {
776 // Extract all $needles.
777 $needles = array_keys( $replace_pairs );
778
779 // Loop through delimiters (elements) only.
780 for ( $i = 1, $c = count( $textarr ); $i < $c; $i += 2 ) {
781 foreach ( $needles as $needle ) {
782 if ( str_contains( $textarr[ $i ], $needle ) ) {
783 $textarr[ $i ] = strtr( $textarr[ $i ], $replace_pairs );
784 $changed = true;
785 // After one strtr() break out of the foreach loop and look at next element.
786 break;
787 }
788 }
789 }
790 }
791
792 if ( $changed ) {
793 $haystack = implode( $textarr );
794 }
795
796 return $haystack;
797}
798
799/**
800 * Newline preservation help function for wpautop().
801 *
802 * @since 3.1.0
803 * @access private
804 *
805 * @param array $matches preg_replace_callback matches array
806 * @return string
807 */
808function _autop_newline_preservation_helper( $matches ) {
809 return str_replace( "\n", '<WPPreserveNewline />', $matches[0] );
810}
811
812/**
813 * Don't auto-p wrap shortcodes that stand alone.
814 *
815 * Ensures that shortcodes are not wrapped in `<p>...</p>`.
816 *
817 * @since 2.9.0
818 *
819 * @global array $shortcode_tags
820 *
821 * @param string $text The content.
822 * @return string The filtered content.
823 */
824function shortcode_unautop( $text ) {
825 global $shortcode_tags;
826
827 if ( empty( $shortcode_tags ) || ! is_array( $shortcode_tags ) ) {
828 return $text;
829 }
830
831 $tagregexp = implode( '|', array_map( 'preg_quote', array_keys( $shortcode_tags ) ) );
832 $spaces = wp_spaces_regexp();
833
834 // phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound,Universal.WhiteSpace.PrecisionAlignment.Found -- don't remove regex indentation
835 $pattern =
836 '/'
837 . '<p>' // Opening paragraph.
838 . '(?:' . $spaces . ')*+' // Optional leading whitespace.
839 . '(' // 1: The shortcode.
840 . '\\[' // Opening bracket.
841 . "($tagregexp)" // 2: Shortcode name.
842 . '(?![\\w-])' // Not followed by word character or hyphen.
843 // Unroll the loop: Inside the opening shortcode tag.
844 . '[^\\]\\/]*' // Not a closing bracket or forward slash.
845 . '(?:'
846 . '\\/(?!\\])' // A forward slash not followed by a closing bracket.
847 . '[^\\]\\/]*' // Not a closing bracket or forward slash.
848 . ')*?'
849 . '(?:'
850 . '\\/\\]' // Self closing tag and closing bracket.
851 . '|'
852 . '\\]' // Closing bracket.
853 . '(?:' // Unroll the loop: Optionally, anything between the opening and closing shortcode tags.
854 . '[^\\[]*+' // Not an opening bracket.
855 . '(?:'
856 . '\\[(?!\\/\\2\\])' // An opening bracket not followed by the closing shortcode tag.
857 . '[^\\[]*+' // Not an opening bracket.
858 . ')*+'
859 . '\\[\\/\\2\\]' // Closing shortcode tag.
860 . ')?'
861 . ')'
862 . ')'
863 . '(?:' . $spaces . ')*+' // Optional trailing whitespace.
864 . '<\\/p>' // Closing paragraph.
865 . '/';
866 // phpcs:enable
867
868 return preg_replace( $pattern, '$1', $text );
869}
870
871/**
872 * Checks to see if a string is utf8 encoded.
873 *
874 * NOTE: This function checks for 5-Byte sequences, UTF8
875 * has Bytes Sequences with a maximum length of 4.
876 *
877 * @author bmorel at ssi dot fr (modified)
878 * @since 1.2.1
879 * @deprecated 6.9.0 Use {@see wp_is_valid_utf8()} instead.
880 *
881 * @param string $str The string to be checked.
882 * @return bool True if $str fits a UTF-8 model, false otherwise.
883 */
884function seems_utf8( $str ) {
885 _deprecated_function( __FUNCTION__, '6.9.0', 'wp_is_valid_utf8()' );
886
887 mbstring_binary_safe_encoding();
888 $length = strlen( $str );
889 reset_mbstring_encoding();
890
891 for ( $i = 0; $i < $length; $i++ ) {
892 $c = ord( $str[ $i ] );
893
894 if ( $c < 0x80 ) {
895 $n = 0; // 0bbbbbbb
896 } elseif ( ( $c & 0xE0 ) === 0xC0 ) {
897 $n = 1; // 110bbbbb
898 } elseif ( ( $c & 0xF0 ) === 0xE0 ) {
899 $n = 2; // 1110bbbb
900 } elseif ( ( $c & 0xF8 ) === 0xF0 ) {
901 $n = 3; // 11110bbb
902 } elseif ( ( $c & 0xFC ) === 0xF8 ) {
903 $n = 4; // 111110bb
904 } elseif ( ( $c & 0xFE ) === 0xFC ) {
905 $n = 5; // 1111110b
906 } else {
907 return false; // Does not match any model.
908 }
909
910 for ( $j = 0; $j < $n; $j++ ) { // n bytes matching 10bbbbbb follow?
911 if ( ( ++$i === $length ) || ( ( ord( $str[ $i ] ) & 0xC0 ) !== 0x80 ) ) {
912 return false;
913 }
914 }
915 }
916
917 return true;
918}
919
920/**
921 * Converts a number of special characters into their HTML entities.
922 *
923 * Specifically deals with: `&`, `<`, `>`, `"`, and `'`.
924 *
925 * `$quote_style` can be set to ENT_COMPAT to encode `"` to
926 * `"`, or ENT_QUOTES to do both. Default is ENT_NOQUOTES where no quotes are encoded.
927 *
928 * @since 1.2.2
929 * @since 5.5.0 `$quote_style` also accepts `ENT_XML1`.
930 * @access private
931 *
932 * @param string $text The text which is to be encoded.
933 * @param int|string $quote_style Optional. Converts double quotes if set to ENT_COMPAT,
934 * both single and double if set to ENT_QUOTES or none if set to ENT_NOQUOTES.
935 * Converts single and double quotes, as well as converting HTML
936 * named entities (that are not also XML named entities) to their
937 * code points if set to ENT_XML1. Also compatible with old values;
938 * converting single quotes if set to 'single',
939 * double if set to 'double' or both if otherwise set.
940 * Default is ENT_NOQUOTES.
941 * @param false|string $charset Optional. The character encoding of the string. Default false.
942 * @param bool $double_encode Optional. Whether to encode existing HTML entities. Default false.
943 * @return string The encoded text with HTML entities.
944 */
945function _wp_specialchars( $text, $quote_style = ENT_NOQUOTES, $charset = false, $double_encode = false ) {
946 $text = (string) $text;
947
948 if ( 0 === strlen( $text ) ) {
949 return '';
950 }
951
952 // Don't bother if there are no specialchars - saves some processing.
953 if ( ! preg_match( '/[&<>"\']/', $text ) ) {
954 return $text;
955 }
956
957 // Account for the previous behavior of the function when the $quote_style is not an accepted value.
958 if ( empty( $quote_style ) ) {
959 $quote_style = ENT_NOQUOTES;
960 } elseif ( ENT_XML1 === $quote_style ) {
961 $quote_style = ENT_QUOTES | ENT_XML1;
962 } elseif ( ! in_array( $quote_style, array( ENT_NOQUOTES, ENT_COMPAT, ENT_QUOTES, 'single', 'double' ), true ) ) {
963 $quote_style = ENT_QUOTES;
964 }
965
966 $charset = _canonical_charset( $charset ? $charset : get_option( 'blog_charset' ) );
967
968 $_quote_style = $quote_style;
969
970 if ( 'double' === $quote_style ) {
971 $quote_style = ENT_COMPAT;
972 $_quote_style = ENT_COMPAT;
973 } elseif ( 'single' === $quote_style ) {
974 $quote_style = ENT_NOQUOTES;
975 }
976
977 if ( ! $double_encode ) {
978 /*
979 * Guarantee every &entity; is valid, convert &garbage; into &garbage;
980 * This is required for PHP < 5.4.0 because ENT_HTML401 flag is unavailable.
981 */
982 $text = wp_kses_normalize_entities( $text, ( $quote_style & ENT_XML1 ) ? 'xml' : 'html' );
983 }
984
985 $text = htmlspecialchars( $text, $quote_style, $charset, $double_encode );
986
987 // Back-compat.
988 if ( 'single' === $_quote_style ) {
989 $text = str_replace( "'", ''', $text );
990 }
991
992 return $text;
993}
994
995/**
996 * Converts a number of HTML entities into their special characters.
997 *
998 * Specifically deals with: `&`, `<`, `>`, `"`, and `'`.
999 *
1000 * `$quote_style` can be set to ENT_COMPAT to decode `"` entities,
1001 * or ENT_QUOTES to do both `"` and `'`. Default is ENT_NOQUOTES where no quotes are decoded.
1002 *
1003 * @since 2.8.0
1004 *
1005 * @param string $text The text which is to be decoded.
1006 * @param string|int $quote_style Optional. Converts double quotes if set to ENT_COMPAT,
1007 * both single and double if set to ENT_QUOTES or
1008 * none if set to ENT_NOQUOTES.
1009 * Also compatible with old _wp_specialchars() values;
1010 * converting single quotes if set to 'single',
1011 * double if set to 'double' or both if otherwise set.
1012 * Default is ENT_NOQUOTES.
1013 * @return string The decoded text without HTML entities.
1014 */
1015function wp_specialchars_decode( $text, $quote_style = ENT_NOQUOTES ) {
1016 $text = (string) $text;
1017
1018 if ( 0 === strlen( $text ) ) {
1019 return '';
1020 }
1021
1022 // Don't bother if there are no entities - saves a lot of processing.
1023 if ( ! str_contains( $text, '&' ) ) {
1024 return $text;
1025 }
1026
1027 // Match the previous behavior of _wp_specialchars() when the $quote_style is not an accepted value.
1028 if ( empty( $quote_style ) ) {
1029 $quote_style = ENT_NOQUOTES;
1030 } elseif ( ! in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) {
1031 $quote_style = ENT_QUOTES;
1032 }
1033
1034 // More complete than get_html_translation_table( HTML_SPECIALCHARS ).
1035 $single = array(
1036 ''' => '\'',
1037 ''' => '\'',
1038 );
1039 $single_preg = array(
1040 '/�*39;/' => ''',
1041 '/�*27;/i' => ''',
1042 );
1043 $double = array(
1044 '"' => '"',
1045 '"' => '"',
1046 '"' => '"',
1047 );
1048 $double_preg = array(
1049 '/�*34;/' => '"',
1050 '/�*22;/i' => '"',
1051 );
1052 $others = array(
1053 '<' => '<',
1054 '<' => '<',
1055 '>' => '>',
1056 '>' => '>',
1057 '&' => '&',
1058 '&' => '&',
1059 '&' => '&',
1060 );
1061 $others_preg = array(
1062 '/�*60;/' => '<',
1063 '/�*62;/' => '>',
1064 '/�*38;/' => '&',
1065 '/�*26;/i' => '&',
1066 );
1067
1068 if ( ENT_QUOTES === $quote_style ) {
1069 $translation = array_merge( $single, $double, $others );
1070 $translation_preg = array_merge( $single_preg, $double_preg, $others_preg );
1071 } elseif ( ENT_COMPAT === $quote_style || 'double' === $quote_style ) {
1072 $translation = array_merge( $double, $others );
1073 $translation_preg = array_merge( $double_preg, $others_preg );
1074 } elseif ( 'single' === $quote_style ) {
1075 $translation = array_merge( $single, $others );
1076 $translation_preg = array_merge( $single_preg, $others_preg );
1077 } elseif ( ENT_NOQUOTES === $quote_style ) {
1078 $translation = $others;
1079 $translation_preg = $others_preg;
1080 }
1081
1082 // Remove zero padding on numeric entities.
1083 $text = preg_replace( array_keys( $translation_preg ), array_values( $translation_preg ), $text );
1084
1085 // Replace characters according to translation table.
1086 return strtr( $text, $translation );
1087}
1088
1089/**
1090 * Checks for invalid UTF8 in a string.
1091 *
1092 * Note! This function only performs its work if the `blog_charset` is set
1093 * to UTF-8. For all other values it returns the input text unchanged.
1094 *
1095 * Note! Unless requested, this returns an empty string if the input contains
1096 * any sequences of invalid UTF-8. To replace invalid byte sequences, pass
1097 * `true` as the optional `$strip` parameter.
1098 *
1099 * Consider using {@see wp_scrub_utf8()} instead which does not depend on
1100 * the value of `blog_charset`.
1101 *
1102 * Example:
1103 *
1104 * // The `blog_charset` is `latin1`, so this returns the input unchanged.
1105 * $every_possible_input === wp_check_invalid_utf8( $every_possible_input );
1106 *
1107 * // Valid strings come through unchanged.
1108 * 'test' === wp_check_invalid_utf8( 'test' );
1109 *
1110 * $invalid = "the byte \xC0 is never allowed in a UTF-8 string.";
1111 *
1112 * // Invalid strings are rejected outright.
1113 * '' === wp_check_invalid_utf8( $invalid );
1114 *
1115 * // “Stripping” invalid sequences produces the replacement character instead.
1116 * "the byte \u{FFFD} is never allowed in a UTF-8 string." === wp_check_invalid_utf8( $invalid, true );
1117 * 'the byte � is never allowed in a UTF-8 string.' === wp_check_invalid_utf8( $invalid, true );
1118 *
1119 * @since 2.8.0
1120 * @since 6.9.0 Stripping replaces invalid byte sequences with the Unicode replacement character U+FFFD (�).
1121 *
1122 * @param string $text String which is expected to be encoded as UTF-8 unless `blog_charset` is another encoding.
1123 * @param bool $strip Optional. Whether to replace invalid sequences of bytes with the Unicode replacement
1124 * character (U+FFFD `�`). Default `false` returns an empty string for invalid UTF-8 inputs.
1125 * @return string The checked text.
1126 */
1127function wp_check_invalid_utf8( $text, $strip = false ) {
1128 $text = (string) $text;
1129
1130 if ( 0 === strlen( $text ) ) {
1131 return '';
1132 }
1133
1134 // Store the site charset as a static to avoid multiple calls to get_option().
1135 static $is_utf8 = null;
1136 if ( ! isset( $is_utf8 ) ) {
1137 $is_utf8 = is_utf8_charset();
1138 }
1139
1140 if ( ! $is_utf8 || wp_is_valid_utf8( $text ) ) {
1141 return $text;
1142 }
1143
1144 return $strip
1145 ? wp_scrub_utf8( $text )
1146 : '';
1147}
1148
1149/**
1150 * Encodes the Unicode values to be used in the URI.
1151 *
1152 * @since 1.5.0
1153 * @since 5.8.3 Added the `encode_ascii_characters` parameter.
1154 *
1155 * @param string $utf8_string String to encode.
1156 * @param int $length Max length of the string.
1157 * @param bool $encode_ascii_characters Whether to encode ascii characters such as < " '
1158 * @return string String with Unicode encoded for URI.
1159 */
1160function utf8_uri_encode( $utf8_string, $length = 0, $encode_ascii_characters = false ) {
1161 $unicode = '';
1162 $values = array();
1163 $num_octets = 1;
1164 $unicode_length = 0;
1165
1166 mbstring_binary_safe_encoding();
1167 $string_length = strlen( $utf8_string );
1168 reset_mbstring_encoding();
1169
1170 for ( $i = 0; $i < $string_length; $i++ ) {
1171
1172 $value = ord( $utf8_string[ $i ] );
1173
1174 if ( $value < 128 ) {
1175 $char = chr( $value );
1176 $encoded_char = $encode_ascii_characters ? rawurlencode( $char ) : $char;
1177 $encoded_char_length = strlen( $encoded_char );
1178 if ( $length && ( $unicode_length + $encoded_char_length ) > $length ) {
1179 break;
1180 }
1181 $unicode .= $encoded_char;
1182 $unicode_length += $encoded_char_length;
1183 } else {
1184 if ( 0 === count( $values ) ) {
1185 if ( $value < 224 ) {
1186 $num_octets = 2;
1187 } elseif ( $value < 240 ) {
1188 $num_octets = 3;
1189 } else {
1190 $num_octets = 4;
1191 }
1192 }
1193
1194 $values[] = $value;
1195
1196 if ( $length && ( $unicode_length + ( $num_octets * 3 ) ) > $length ) {
1197 break;
1198 }
1199 if ( count( $values ) === $num_octets ) {
1200 for ( $j = 0; $j < $num_octets; $j++ ) {
1201 $unicode .= '%' . dechex( $values[ $j ] );
1202 }
1203
1204 $unicode_length += $num_octets * 3;
1205
1206 $values = array();
1207 $num_octets = 1;
1208 }
1209 }
1210 }
1211
1212 return $unicode;
1213}
1214
1215/**
1216 * Converts all accent characters to ASCII characters.
1217 *
1218 * If there are no accent characters, then the string given is just returned.
1219 *
1220 * **Accent characters converted:**
1221 *
1222 * Currency signs:
1223 *
1224 * | Code | Glyph | Replacement | Description |
1225 * | -------- | ----- | ----------- | ------------------- |
1226 * | U+00A3 | £ | (empty) | British Pound sign |
1227 * | U+20AC | € | E | Euro sign |
1228 *
1229 * Decompositions for Latin-1 Supplement:
1230 *
1231 * | Code | Glyph | Replacement | Description |
1232 * | ------- | ----- | ----------- | -------------------------------------- |
1233 * | U+00AA | ª | a | Feminine ordinal indicator |
1234 * | U+00BA | º | o | Masculine ordinal indicator |
1235 * | U+00C0 | À | A | Latin capital letter A with grave |
1236 * | U+00C1 | Á | A | Latin capital letter A with acute |
1237 * | U+00C2 | Â | A | Latin capital letter A with circumflex |
1238 * | U+00C3 | Ã | A | Latin capital letter A with tilde |
1239 * | U+00C4 | Ä | A | Latin capital letter A with diaeresis |
1240 * | U+00C5 | Å | A | Latin capital letter A with ring above |
1241 * | U+00C6 | Æ | AE | Latin capital letter AE |
1242 * | U+00C7 | Ç | C | Latin capital letter C with cedilla |
1243 * | U+00C8 | È | E | Latin capital letter E with grave |
1244 * | U+00C9 | É | E | Latin capital letter E with acute |
1245 * | U+00CA | Ê | E | Latin capital letter E with circumflex |
1246 * | U+00CB | Ë | E | Latin capital letter E with diaeresis |
1247 * | U+00CC | Ì | I | Latin capital letter I with grave |
1248 * | U+00CD | Í | I | Latin capital letter I with acute |
1249 * | U+00CE | Î | I | Latin capital letter I with circumflex |
1250 * | U+00CF | Ï | I | Latin capital letter I with diaeresis |
1251 * | U+00D0 | Ð | D | Latin capital letter Eth |
1252 * | U+00D1 | Ñ | N | Latin capital letter N with tilde |
1253 * | U+00D2 | Ò | O | Latin capital letter O with grave |
1254 * | U+00D3 | Ó | O | Latin capital letter O with acute |
1255 * | U+00D4 | Ô | O | Latin capital letter O with circumflex |
1256 * | U+00D5 | Õ | O | Latin capital letter O with tilde |
1257 * | U+00D6 | Ö | O | Latin capital letter O with diaeresis |
1258 * | U+00D8 | Ø | O | Latin capital letter O with stroke |
1259 * | U+00D9 | Ù | U | Latin capital letter U with grave |
1260 * | U+00DA | Ú | U | Latin capital letter U with acute |
1261 * | U+00DB | Û | U | Latin capital letter U with circumflex |
1262 * | U+00DC | Ü | U | Latin capital letter U with diaeresis |
1263 * | U+00DD | Ý | Y | Latin capital letter Y with acute |
1264 * | U+00DE | Þ | TH | Latin capital letter Thorn |
1265 * | U+00DF | ß | s | Latin small letter sharp s |
1266 * | U+00E0 | à | a | Latin small letter a with grave |
1267 * | U+00E1 | á | a | Latin small letter a with acute |
1268 * | U+00E2 | â | a | Latin small letter a with circumflex |
1269 * | U+00E3 | ã | a | Latin small letter a with tilde |
1270 * | U+00E4 | ä | a | Latin small letter a with diaeresis |
1271 * | U+00E5 | å | a | Latin small letter a with ring above |
1272 * | U+00E6 | æ | ae | Latin small letter ae |
1273 * | U+00E7 | ç | c | Latin small letter c with cedilla |
1274 * | U+00E8 | è | e | Latin small letter e with grave |
1275 * | U+00E9 | é | e | Latin small letter e with acute |
1276 * | U+00EA | ê | e | Latin small letter e with circumflex |
1277 * | U+00EB | ë | e | Latin small letter e with diaeresis |
1278 * | U+00EC | ì | i | Latin small letter i with grave |
1279 * | U+00ED | í | i | Latin small letter i with acute |
1280 * | U+00EE | î | i | Latin small letter i with circumflex |
1281 * | U+00EF | ï | i | Latin small letter i with diaeresis |
1282 * | U+00F0 | ð | d | Latin small letter Eth |
1283 * | U+00F1 | ñ | n | Latin small letter n with tilde |
1284 * | U+00F2 | ò | o | Latin small letter o with grave |
1285 * | U+00F3 | ó | o | Latin small letter o with acute |
1286 * | U+00F4 | ô | o | Latin small letter o with circumflex |
1287 * | U+00F5 | õ | o | Latin small letter o with tilde |
1288 * | U+00F6 | ö | o | Latin small letter o with diaeresis |
1289 * | U+00F8 | ø | o | Latin small letter o with stroke |
1290 * | U+00F9 | ù | u | Latin small letter u with grave |
1291 * | U+00FA | ú | u | Latin small letter u with acute |
1292 * | U+00FB | û | u | Latin small letter u with circumflex |
1293 * | U+00FC | ü | u | Latin small letter u with diaeresis |
1294 * | U+00FD | ý | y | Latin small letter y with acute |
1295 * | U+00FE | þ | th | Latin small letter Thorn |
1296 * | U+00FF | ÿ | y | Latin small letter y with diaeresis |
1297 *
1298 * Decompositions for Latin Extended-A:
1299 *
1300 * | Code | Glyph | Replacement | Description |
1301 * | ------- | ----- | ----------- | ------------------------------------------------- |
1302 * | U+0100 | Ā | A | Latin capital letter A with macron |
1303 * | U+0101 | ā | a | Latin small letter a with macron |
1304 * | U+0102 | Ă | A | Latin capital letter A with breve |
1305 * | U+0103 | ă | a | Latin small letter a with breve |
1306 * | U+0104 | Ą | A | Latin capital letter A with ogonek |
1307 * | U+0105 | ą | a | Latin small letter a with ogonek |
1308 * | U+01006 | Ć | C | Latin capital letter C with acute |
1309 * | U+0107 | ć | c | Latin small letter c with acute |
1310 * | U+0108 | Ĉ | C | Latin capital letter C with circumflex |
1311 * | U+0109 | ĉ | c | Latin small letter c with circumflex |
1312 * | U+010A | Ċ | C | Latin capital letter C with dot above |
1313 * | U+010B | ċ | c | Latin small letter c with dot above |
1314 * | U+010C | Č | C | Latin capital letter C with caron |
1315 * | U+010D | č | c | Latin small letter c with caron |
1316 * | U+010E | Ď | D | Latin capital letter D with caron |
1317 * | U+010F | ď | d | Latin small letter d with caron |
1318 * | U+0110 | Đ | D | Latin capital letter D with stroke |
1319 * | U+0111 | đ | d | Latin small letter d with stroke |
1320 * | U+0112 | Ē | E | Latin capital letter E with macron |
1321 * | U+0113 | ē | e | Latin small letter e with macron |
1322 * | U+0114 | Ĕ | E | Latin capital letter E with breve |
1323 * | U+0115 | ĕ | e | Latin small letter e with breve |
1324 * | U+0116 | Ė | E | Latin capital letter E with dot above |
1325 * | U+0117 | ė | e | Latin small letter e with dot above |
1326 * | U+0118 | Ę | E | Latin capital letter E with ogonek |
1327 * | U+0119 | ę | e | Latin small letter e with ogonek |
1328 * | U+011A | Ě | E | Latin capital letter E with caron |
1329 * | U+011B | ě | e | Latin small letter e with caron |
1330 * | U+011C | Ĝ | G | Latin capital letter G with circumflex |
1331 * | U+011D | ĝ | g | Latin small letter g with circumflex |
1332 * | U+011E | Ğ | G | Latin capital letter G with breve |
1333 * | U+011F | ğ | g | Latin small letter g with breve |
1334 * | U+0120 | Ġ | G | Latin capital letter G with dot above |
1335 * | U+0121 | ġ | g | Latin small letter g with dot above |
1336 * | U+0122 | Ģ | G | Latin capital letter G with cedilla |
1337 * | U+0123 | ģ | g | Latin small letter g with cedilla |
1338 * | U+0124 | Ĥ | H | Latin capital letter H with circumflex |
1339 * | U+0125 | ĥ | h | Latin small letter h with circumflex |
1340 * | U+0126 | Ħ | H | Latin capital letter H with stroke |
1341 * | U+0127 | ħ | h | Latin small letter h with stroke |
1342 * | U+0128 | Ĩ | I | Latin capital letter I with tilde |
1343 * | U+0129 | ĩ | i | Latin small letter i with tilde |
1344 * | U+012A | Ī | I | Latin capital letter I with macron |
1345 * | U+012B | ī | i | Latin small letter i with macron |
1346 * | U+012C | Ĭ | I | Latin capital letter I with breve |
1347 * | U+012D | ĭ | i | Latin small letter i with breve |
1348 * | U+012E | Į | I | Latin capital letter I with ogonek |
1349 * | U+012F | į | i | Latin small letter i with ogonek |
1350 * | U+0130 | İ | I | Latin capital letter I with dot above |
1351 * | U+0131 | ı | i | Latin small letter dotless i |
1352 * | U+0132 | IJ | IJ | Latin capital ligature IJ |
1353 * | U+0133 | ij | ij | Latin small ligature ij |
1354 * | U+0134 | Ĵ | J | Latin capital letter J with circumflex |
1355 * | U+0135 | ĵ | j | Latin small letter j with circumflex |
1356 * | U+0136 | Ķ | K | Latin capital letter K with cedilla |
1357 * | U+0137 | ķ | k | Latin small letter k with cedilla |
1358 * | U+0138 | ĸ | k | Latin small letter Kra |
1359 * | U+0139 | Ĺ | L | Latin capital letter L with acute |
1360 * | U+013A | ĺ | l | Latin small letter l with acute |
1361 * | U+013B | Ļ | L | Latin capital letter L with cedilla |
1362 * | U+013C | ļ | l | Latin small letter l with cedilla |
1363 * | U+013D | Ľ | L | Latin capital letter L with caron |
1364 * | U+013E | ľ | l | Latin small letter l with caron |
1365 * | U+013F | Ŀ | L | Latin capital letter L with middle dot |
1366 * | U+0140 | ŀ | l | Latin small letter l with middle dot |
1367 * | U+0141 | Ł | L | Latin capital letter L with stroke |
1368 * | U+0142 | ł | l | Latin small letter l with stroke |
1369 * | U+0143 | Ń | N | Latin capital letter N with acute |
1370 * | U+0144 | ń | n | Latin small letter N with acute |
1371 * | U+0145 | Ņ | N | Latin capital letter N with cedilla |
1372 * | U+0146 | ņ | n | Latin small letter n with cedilla |
1373 * | U+0147 | Ň | N | Latin capital letter N with caron |
1374 * | U+0148 | ň | n | Latin small letter n with caron |
1375 * | U+0149 | ʼn | n | Latin small letter n preceded by apostrophe |
1376 * | U+014A | Ŋ | N | Latin capital letter Eng |
1377 * | U+014B | ŋ | n | Latin small letter Eng |
1378 * | U+014C | Ō | O | Latin capital letter O with macron |
1379 * | U+014D | ō | o | Latin small letter o with macron |
1380 * | U+014E | Ŏ | O | Latin capital letter O with breve |
1381 * | U+014F | ŏ | o | Latin small letter o with breve |
1382 * | U+0150 | Ő | O | Latin capital letter O with double acute |
1383 * | U+0151 | ő | o | Latin small letter o with double acute |
1384 * | U+0152 | Œ | OE | Latin capital ligature OE |
1385 * | U+0153 | œ | oe | Latin small ligature oe |
1386 * | U+0154 | Ŕ | R | Latin capital letter R with acute |
1387 * | U+0155 | ŕ | r | Latin small letter r with acute |
1388 * | U+0156 | Ŗ | R | Latin capital letter R with cedilla |
1389 * | U+0157 | ŗ | r | Latin small letter r with cedilla |
1390 * | U+0158 | Ř | R | Latin capital letter R with caron |
1391 * | U+0159 | ř | r | Latin small letter r with caron |
1392 * | U+015A | Ś | S | Latin capital letter S with acute |
1393 * | U+015B | ś | s | Latin small letter s with acute |
1394 * | U+015C | Ŝ | S | Latin capital letter S with circumflex |
1395 * | U+015D | ŝ | s | Latin small letter s with circumflex |
1396 * | U+015E | Ş | S | Latin capital letter S with cedilla |
1397 * | U+015F | ş | s | Latin small letter s with cedilla |
1398 * | U+0160 | Š | S | Latin capital letter S with caron |
1399 * | U+0161 | š | s | Latin small letter s with caron |
1400 * | U+0162 | Ţ | T | Latin capital letter T with cedilla |
1401 * | U+0163 | ţ | t | Latin small letter t with cedilla |
1402 * | U+0164 | Ť | T | Latin capital letter T with caron |
1403 * | U+0165 | ť | t | Latin small letter t with caron |
1404 * | U+0166 | Ŧ | T | Latin capital letter T with stroke |
1405 * | U+0167 | ŧ | t | Latin small letter t with stroke |
1406 * | U+0168 | Ũ | U | Latin capital letter U with tilde |
1407 * | U+0169 | ũ | u | Latin small letter u with tilde |
1408 * | U+016A | Ū | U | Latin capital letter U with macron |
1409 * | U+016B | ū | u | Latin small letter u with macron |
1410 * | U+016C | Ŭ | U | Latin capital letter U with breve |
1411 * | U+016D | ŭ | u | Latin small letter u with breve |
1412 * | U+016E | Ů | U | Latin capital letter U with ring above |
1413 * | U+016F | ů | u | Latin small letter u with ring above |
1414 * | U+0170 | Ű | U | Latin capital letter U with double acute |
1415 * | U+0171 | ű | u | Latin small letter u with double acute |
1416 * | U+0172 | Ų | U | Latin capital letter U with ogonek |
1417 * | U+0173 | ų | u | Latin small letter u with ogonek |
1418 * | U+0174 | Ŵ | W | Latin capital letter W with circumflex |
1419 * | U+0175 | ŵ | w | Latin small letter w with circumflex |
1420 * | U+0176 | Ŷ | Y | Latin capital letter Y with circumflex |
1421 * | U+0177 | ŷ | y | Latin small letter y with circumflex |
1422 * | U+0178 | Ÿ | Y | Latin capital letter Y with diaeresis |
1423 * | U+0179 | Ź | Z | Latin capital letter Z with acute |
1424 * | U+017A | ź | z | Latin small letter z with acute |
1425 * | U+017B | Ż | Z | Latin capital letter Z with dot above |
1426 * | U+017C | ż | z | Latin small letter z with dot above |
1427 * | U+017D | Ž | Z | Latin capital letter Z with caron |
1428 * | U+017E | ž | z | Latin small letter z with caron |
1429 * | U+017F | ſ | s | Latin small letter long s |
1430 * | U+01A0 | Ơ | O | Latin capital letter O with horn |
1431 * | U+01A1 | ơ | o | Latin small letter o with horn |
1432 * | U+01AF | Ư | U | Latin capital letter U with horn |
1433 * | U+01B0 | ư | u | Latin small letter u with horn |
1434 * | U+01CD | Ǎ | A | Latin capital letter A with caron |
1435 * | U+01CE | ǎ | a | Latin small letter a with caron |
1436 * | U+01CF | Ǐ | I | Latin capital letter I with caron |
1437 * | U+01D0 | ǐ | i | Latin small letter i with caron |
1438 * | U+01D1 | Ǒ | O | Latin capital letter O with caron |
1439 * | U+01D2 | ǒ | o | Latin small letter o with caron |
1440 * | U+01D3 | Ǔ | U | Latin capital letter U with caron |
1441 * | U+01D4 | ǔ | u | Latin small letter u with caron |
1442 * | U+01D5 | Ǖ | U | Latin capital letter U with diaeresis and macron |
1443 * | U+01D6 | ǖ | u | Latin small letter u with diaeresis and macron |
1444 * | U+01D7 | Ǘ | U | Latin capital letter U with diaeresis and acute |
1445 * | U+01D8 | ǘ | u | Latin small letter u with diaeresis and acute |
1446 * | U+01D9 | Ǚ | U | Latin capital letter U with diaeresis and caron |
1447 * | U+01DA | ǚ | u | Latin small letter u with diaeresis and caron |
1448 * | U+01DB | Ǜ | U | Latin capital letter U with diaeresis and grave |
1449 * | U+01DC | ǜ | u | Latin small letter u with diaeresis and grave |
1450 *
1451 * Decompositions for Latin Extended-B:
1452 *
1453 * | Code | Glyph | Replacement | Description |
1454 * | -------- | ----- | ----------- | ----------------------------------------- |
1455 * | U+018F | Ə | E | Latin capital letter Ə |
1456 * | U+0259 | ǝ | e | Latin small letter ǝ |
1457 * | U+0218 | Ș | S | Latin capital letter S with comma below |
1458 * | U+0219 | ș | s | Latin small letter s with comma below |
1459 * | U+021A | Ț | T | Latin capital letter T with comma below |
1460 * | U+021B | ț | t | Latin small letter t with comma below |
1461 *
1462 * Vowels with diacritic (Chinese, Hanyu Pinyin):
1463 *
1464 * | Code | Glyph | Replacement | Description |
1465 * | -------- | ----- | ----------- | ----------------------------------------------------- |
1466 * | U+0251 | ɑ | a | Latin small letter alpha |
1467 * | U+1EA0 | Ạ | A | Latin capital letter A with dot below |
1468 * | U+1EA1 | ạ | a | Latin small letter a with dot below |
1469 * | U+1EA2 | Ả | A | Latin capital letter A with hook above |
1470 * | U+1EA3 | ả | a | Latin small letter a with hook above |
1471 * | U+1EA4 | Ấ | A | Latin capital letter A with circumflex and acute |
1472 * | U+1EA5 | ấ | a | Latin small letter a with circumflex and acute |
1473 * | U+1EA6 | Ầ | A | Latin capital letter A with circumflex and grave |
1474 * | U+1EA7 | ầ | a | Latin small letter a with circumflex and grave |
1475 * | U+1EA8 | Ẩ | A | Latin capital letter A with circumflex and hook above |
1476 * | U+1EA9 | ẩ | a | Latin small letter a with circumflex and hook above |
1477 * | U+1EAA | Ẫ | A | Latin capital letter A with circumflex and tilde |
1478 * | U+1EAB | ẫ | a | Latin small letter a with circumflex and tilde |
1479 * | U+1EA6 | Ậ | A | Latin capital letter A with circumflex and dot below |
1480 * | U+1EAD | ậ | a | Latin small letter a with circumflex and dot below |
1481 * | U+1EAE | Ắ | A | Latin capital letter A with breve and acute |
1482 * | U+1EAF | ắ | a | Latin small letter a with breve and acute |
1483 * | U+1EB0 | Ằ | A | Latin capital letter A with breve and grave |
1484 * | U+1EB1 | ằ | a | Latin small letter a with breve and grave |
1485 * | U+1EB2 | Ẳ | A | Latin capital letter A with breve and hook above |
1486 * | U+1EB3 | ẳ | a | Latin small letter a with breve and hook above |
1487 * | U+1EB4 | Ẵ | A | Latin capital letter A with breve and tilde |
1488 * | U+1EB5 | ẵ | a | Latin small letter a with breve and tilde |
1489 * | U+1EB6 | Ặ | A | Latin capital letter A with breve and dot below |
1490 * | U+1EB7 | ặ | a | Latin small letter a with breve and dot below |
1491 * | U+1EB8 | Ẹ | E | Latin capital letter E with dot below |
1492 * | U+1EB9 | ẹ | e | Latin small letter e with dot below |
1493 * | U+1EBA | Ẻ | E | Latin capital letter E with hook above |
1494 * | U+1EBB | ẻ | e | Latin small letter e with hook above |
1495 * | U+1EBC | Ẽ | E | Latin capital letter E with tilde |
1496 * | U+1EBD | ẽ | e | Latin small letter e with tilde |
1497 * | U+1EBE | Ế | E | Latin capital letter E with circumflex and acute |
1498 * | U+1EBF | ế | e | Latin small letter e with circumflex and acute |
1499 * | U+1EC0 | Ề | E | Latin capital letter E with circumflex and grave |
1500 * | U+1EC1 | ề | e | Latin small letter e with circumflex and grave |
1501 * | U+1EC2 | Ể | E | Latin capital letter E with circumflex and hook above |
1502 * | U+1EC3 | ể | e | Latin small letter e with circumflex and hook above |
1503 * | U+1EC4 | Ễ | E | Latin capital letter E with circumflex and tilde |
1504 * | U+1EC5 | ễ | e | Latin small letter e with circumflex and tilde |
1505 * | U+1EC6 | Ệ | E | Latin capital letter E with circumflex and dot below |
1506 * | U+1EC7 | ệ | e | Latin small letter e with circumflex and dot below |
1507 * | U+1EC8 | Ỉ | I | Latin capital letter I with hook above |
1508 * | U+1EC9 | ỉ | i | Latin small letter i with hook above |
1509 * | U+1ECA | Ị | I | Latin capital letter I with dot below |
1510 * | U+1ECB | ị | i | Latin small letter i with dot below |
1511 * | U+1ECC | Ọ | O | Latin capital letter O with dot below |
1512 * | U+1ECD | ọ | o | Latin small letter o with dot below |
1513 * | U+1ECE | Ỏ | O | Latin capital letter O with hook above |
1514 * | U+1ECF | ỏ | o | Latin small letter o with hook above |
1515 * | U+1ED0 | Ố | O | Latin capital letter O with circumflex and acute |
1516 * | U+1ED1 | ố | o | Latin small letter o with circumflex and acute |
1517 * | U+1ED2 | Ồ | O | Latin capital letter O with circumflex and grave |
1518 * | U+1ED3 | ồ | o | Latin small letter o with circumflex and grave |
1519 * | U+1ED4 | Ổ | O | Latin capital letter O with circumflex and hook above |
1520 * | U+1ED5 | ổ | o | Latin small letter o with circumflex and hook above |
1521 * | U+1ED6 | Ỗ | O | Latin capital letter O with circumflex and tilde |
1522 * | U+1ED7 | ỗ | o | Latin small letter o with circumflex and tilde |
1523 * | U+1ED8 | Ộ | O | Latin capital letter O with circumflex and dot below |
1524 * | U+1ED9 | ộ | o | Latin small letter o with circumflex and dot below |
1525 * | U+1EDA | Ớ | O | Latin capital letter O with horn and acute |
1526 * | U+1EDB | ớ | o | Latin small letter o with horn and acute |
1527 * | U+1EDC | Ờ | O | Latin capital letter O with horn and grave |
1528 * | U+1EDD | ờ | o | Latin small letter o with horn and grave |
1529 * | U+1EDE | Ở | O | Latin capital letter O with horn and hook above |
1530 * | U+1EDF | ở | o | Latin small letter o with horn and hook above |
1531 * | U+1EE0 | Ỡ | O | Latin capital letter O with horn and tilde |
1532 * | U+1EE1 | ỡ | o | Latin small letter o with horn and tilde |
1533 * | U+1EE2 | Ợ | O | Latin capital letter O with horn and dot below |
1534 * | U+1EE3 | ợ | o | Latin small letter o with horn and dot below |
1535 * | U+1EE4 | Ụ | U | Latin capital letter U with dot below |
1536 * | U+1EE5 | ụ | u | Latin small letter u with dot below |
1537 * | U+1EE6 | Ủ | U | Latin capital letter U with hook above |
1538 * | U+1EE7 | ủ | u | Latin small letter u with hook above |
1539 * | U+1EE8 | Ứ | U | Latin capital letter U with horn and acute |
1540 * | U+1EE9 | ứ | u | Latin small letter u with horn and acute |
1541 * | U+1EEA | Ừ | U | Latin capital letter U with horn and grave |
1542 * | U+1EEB | ừ | u | Latin small letter u with horn and grave |
1543 * | U+1EEC | Ử | U | Latin capital letter U with horn and hook above |
1544 * | U+1EED | ử | u | Latin small letter u with horn and hook above |
1545 * | U+1EEE | Ữ | U | Latin capital letter U with horn and tilde |
1546 * | U+1EEF | ữ | u | Latin small letter u with horn and tilde |
1547 * | U+1EF0 | Ự | U | Latin capital letter U with horn and dot below |
1548 * | U+1EF1 | ự | u | Latin small letter u with horn and dot below |
1549 * | U+1EF2 | Ỳ | Y | Latin capital letter Y with grave |
1550 * | U+1EF3 | ỳ | y | Latin small letter y with grave |
1551 * | U+1EF4 | Ỵ | Y | Latin capital letter Y with dot below |
1552 * | U+1EF5 | ỵ | y | Latin small letter y with dot below |
1553 * | U+1EF6 | Ỷ | Y | Latin capital letter Y with hook above |
1554 * | U+1EF7 | ỷ | y | Latin small letter y with hook above |
1555 * | U+1EF8 | Ỹ | Y | Latin capital letter Y with tilde |
1556 * | U+1EF9 | ỹ | y | Latin small letter y with tilde |
1557 *
1558 * German (`de_DE`), German formal (`de_DE_formal`), German (Switzerland) formal (`de_CH`),
1559 * German (Switzerland) informal (`de_CH_informal`), and German (Austria) (`de_AT`) locales:
1560 *
1561 * | Code | Glyph | Replacement | Description |
1562 * | -------- | ----- | ----------- | --------------------------------------- |
1563 * | U+00C4 | Ä | Ae | Latin capital letter A with diaeresis |
1564 * | U+00E4 | ä | ae | Latin small letter a with diaeresis |
1565 * | U+00D6 | Ö | Oe | Latin capital letter O with diaeresis |
1566 * | U+00F6 | ö | oe | Latin small letter o with diaeresis |
1567 * | U+00DC | Ü | Ue | Latin capital letter U with diaeresis |
1568 * | U+00FC | ü | ue | Latin small letter u with diaeresis |
1569 * | U+00DF | ß | ss | Latin small letter sharp s |
1570 *
1571 * Danish (`da_DK`) locale:
1572 *
1573 * | Code | Glyph | Replacement | Description |
1574 * | -------- | ----- | ----------- | --------------------------------------- |
1575 * | U+00C6 | Æ | Ae | Latin capital letter AE |
1576 * | U+00E6 | æ | ae | Latin small letter ae |
1577 * | U+00D8 | Ø | Oe | Latin capital letter O with stroke |
1578 * | U+00F8 | ø | oe | Latin small letter o with stroke |
1579 * | U+00C5 | Å | Aa | Latin capital letter A with ring above |
1580 * | U+00E5 | å | aa | Latin small letter a with ring above |
1581 *
1582 * Catalan (`ca`) locale:
1583 *
1584 * | Code | Glyph | Replacement | Description |
1585 * | -------- | ----- | ----------- | --------------------------------------- |
1586 * | U+00B7 | l·l | ll | Flown dot (between two Ls) |
1587 *
1588 * Serbian (`sr_RS`) and Bosnian (`bs_BA`) locales:
1589 *
1590 * | Code | Glyph | Replacement | Description |
1591 * | -------- | ----- | ----------- | --------------------------------------- |
1592 * | U+0110 | Đ | DJ | Latin capital letter D with stroke |
1593 * | U+0111 | đ | dj | Latin small letter d with stroke |
1594 *
1595 * @since 1.2.1
1596 * @since 4.6.0 Added locale support for `de_CH`, `de_CH_informal`, and `ca`.
1597 * @since 4.7.0 Added locale support for `sr_RS`.
1598 * @since 4.8.0 Added locale support for `bs_BA`.
1599 * @since 5.7.0 Added locale support for `de_AT`.
1600 * @since 6.0.0 Added the `$locale` parameter.
1601 * @since 6.1.0 Added Unicode NFC encoding normalization support.
1602 *
1603 * @param string $text Text that might have accent characters.
1604 * @param string $locale Optional. The locale to use for accent removal. Some character
1605 * replacements depend on the locale being used (e.g. 'de_DE').
1606 * Defaults to the current locale.
1607 * @return string Filtered string with replaced "nice" characters.
1608 */
1609function remove_accents( $text, $locale = '' ) {
1610 if ( ! preg_match( '/[\x80-\xff]/', $text ) ) {
1611 return $text;
1612 }
1613
1614 if ( wp_is_valid_utf8( $text ) ) {
1615
1616 /*
1617 * Unicode sequence normalization from NFD (Normalization Form Decomposed)
1618 * to NFC (Normalization Form [Pre]Composed), the encoding used in this function.
1619 */
1620 if ( function_exists( 'normalizer_is_normalized' )
1621 && function_exists( 'normalizer_normalize' )
1622 ) {
1623 if ( ! normalizer_is_normalized( $text ) ) {
1624 $text = normalizer_normalize( $text );
1625 }
1626 }
1627
1628 $chars = array(
1629 // Decompositions for Latin-1 Supplement.
1630 'ª' => 'a',
1631 'º' => 'o',
1632 'À' => 'A',
1633 'Á' => 'A',
1634 'Â' => 'A',
1635 'Ã' => 'A',
1636 'Ä' => 'A',
1637 'Å' => 'A',
1638 'Æ' => 'AE',
1639 'Ç' => 'C',
1640 'È' => 'E',
1641 'É' => 'E',
1642 'Ê' => 'E',
1643 'Ë' => 'E',
1644 'Ì' => 'I',
1645 'Í' => 'I',
1646 'Î' => 'I',
1647 'Ï' => 'I',
1648 'Ð' => 'D',
1649 'Ñ' => 'N',
1650 'Ò' => 'O',
1651 'Ó' => 'O',
1652 'Ô' => 'O',
1653 'Õ' => 'O',
1654 'Ö' => 'O',
1655 'Ù' => 'U',
1656 'Ú' => 'U',
1657 'Û' => 'U',
1658 'Ü' => 'U',
1659 'Ý' => 'Y',
1660 'Þ' => 'TH',
1661 'ß' => 's',
1662 'à' => 'a',
1663 'á' => 'a',
1664 'â' => 'a',
1665 'ã' => 'a',
1666 'ä' => 'a',
1667 'å' => 'a',
1668 'æ' => 'ae',
1669 'ç' => 'c',
1670 'è' => 'e',
1671 'é' => 'e',
1672 'ê' => 'e',
1673 'ë' => 'e',
1674 'ì' => 'i',
1675 'í' => 'i',
1676 'î' => 'i',
1677 'ï' => 'i',
1678 'ð' => 'd',
1679 'ñ' => 'n',
1680 'ò' => 'o',
1681 'ó' => 'o',
1682 'ô' => 'o',
1683 'õ' => 'o',
1684 'ö' => 'o',
1685 'ø' => 'o',
1686 'ù' => 'u',
1687 'ú' => 'u',
1688 'û' => 'u',
1689 'ü' => 'u',
1690 'ý' => 'y',
1691 'þ' => 'th',
1692 'ÿ' => 'y',
1693 'Ø' => 'O',
1694 // Decompositions for Latin Extended-A.
1695 'Ā' => 'A',
1696 'ā' => 'a',
1697 'Ă' => 'A',
1698 'ă' => 'a',
1699 'Ą' => 'A',
1700 'ą' => 'a',
1701 'Ć' => 'C',
1702 'ć' => 'c',
1703 'Ĉ' => 'C',
1704 'ĉ' => 'c',
1705 'Ċ' => 'C',
1706 'ċ' => 'c',
1707 'Č' => 'C',
1708 'č' => 'c',
1709 'Ď' => 'D',
1710 'ď' => 'd',
1711 'Đ' => 'D',
1712 'đ' => 'd',
1713 'Ē' => 'E',
1714 'ē' => 'e',
1715 'Ĕ' => 'E',
1716 'ĕ' => 'e',
1717 'Ė' => 'E',
1718 'ė' => 'e',
1719 'Ę' => 'E',
1720 'ę' => 'e',
1721 'Ě' => 'E',
1722 'ě' => 'e',
1723 'Ĝ' => 'G',
1724 'ĝ' => 'g',
1725 'Ğ' => 'G',
1726 'ğ' => 'g',
1727 'Ġ' => 'G',
1728 'ġ' => 'g',
1729 'Ģ' => 'G',
1730 'ģ' => 'g',
1731 'Ĥ' => 'H',
1732 'ĥ' => 'h',
1733 'Ħ' => 'H',
1734 'ħ' => 'h',
1735 'Ĩ' => 'I',
1736 'ĩ' => 'i',
1737 'Ī' => 'I',
1738 'ī' => 'i',
1739 'Ĭ' => 'I',
1740 'ĭ' => 'i',
1741 'Į' => 'I',
1742 'į' => 'i',
1743 'İ' => 'I',
1744 'ı' => 'i',
1745 'IJ' => 'IJ',
1746 'ij' => 'ij',
1747 'Ĵ' => 'J',
1748 'ĵ' => 'j',
1749 'Ķ' => 'K',
1750 'ķ' => 'k',
1751 'ĸ' => 'k',
1752 'Ĺ' => 'L',
1753 'ĺ' => 'l',
1754 'Ļ' => 'L',
1755 'ļ' => 'l',
1756 'Ľ' => 'L',
1757 'ľ' => 'l',
1758 'Ŀ' => 'L',
1759 'ŀ' => 'l',
1760 'Ł' => 'L',
1761 'ł' => 'l',
1762 'Ń' => 'N',
1763 'ń' => 'n',
1764 'Ņ' => 'N',
1765 'ņ' => 'n',
1766 'Ň' => 'N',
1767 'ň' => 'n',
1768 'ʼn' => 'n',
1769 'Ŋ' => 'N',
1770 'ŋ' => 'n',
1771 'Ō' => 'O',
1772 'ō' => 'o',
1773 'Ŏ' => 'O',
1774 'ŏ' => 'o',
1775 'Ő' => 'O',
1776 'ő' => 'o',
1777 'Œ' => 'OE',
1778 'œ' => 'oe',
1779 'Ŕ' => 'R',
1780 'ŕ' => 'r',
1781 'Ŗ' => 'R',
1782 'ŗ' => 'r',
1783 'Ř' => 'R',
1784 'ř' => 'r',
1785 'Ś' => 'S',
1786 'ś' => 's',
1787 'Ŝ' => 'S',
1788 'ŝ' => 's',
1789 'Ş' => 'S',
1790 'ş' => 's',
1791 'Š' => 'S',
1792 'š' => 's',
1793 'Ţ' => 'T',
1794 'ţ' => 't',
1795 'Ť' => 'T',
1796 'ť' => 't',
1797 'Ŧ' => 'T',
1798 'ŧ' => 't',
1799 'Ũ' => 'U',
1800 'ũ' => 'u',
1801 'Ū' => 'U',
1802 'ū' => 'u',
1803 'Ŭ' => 'U',
1804 'ŭ' => 'u',
1805 'Ů' => 'U',
1806 'ů' => 'u',
1807 'Ű' => 'U',
1808 'ű' => 'u',
1809 'Ų' => 'U',
1810 'ų' => 'u',
1811 'Ŵ' => 'W',
1812 'ŵ' => 'w',
1813 'Ŷ' => 'Y',
1814 'ŷ' => 'y',
1815 'Ÿ' => 'Y',
1816 'Ź' => 'Z',
1817 'ź' => 'z',
1818 'Ż' => 'Z',
1819 'ż' => 'z',
1820 'Ž' => 'Z',
1821 'ž' => 'z',
1822 'ſ' => 's',
1823 // Decompositions for Latin Extended-B.
1824 'Ə' => 'E',
1825 'ǝ' => 'e',
1826 'Ș' => 'S',
1827 'ș' => 's',
1828 'Ț' => 'T',
1829 'ț' => 't',
1830 // Euro sign.
1831 '€' => 'E',
1832 // GBP (Pound) sign.
1833 '£' => '',
1834 // Vowels with diacritic (Vietnamese). Unmarked.
1835 'Ơ' => 'O',
1836 'ơ' => 'o',
1837 'Ư' => 'U',
1838 'ư' => 'u',
1839 // Grave accent.
1840 'Ầ' => 'A',
1841 'ầ' => 'a',
1842 'Ằ' => 'A',
1843 'ằ' => 'a',
1844 'Ề' => 'E',
1845 'ề' => 'e',
1846 'Ồ' => 'O',
1847 'ồ' => 'o',
1848 'Ờ' => 'O',
1849 'ờ' => 'o',
1850 'Ừ' => 'U',
1851 'ừ' => 'u',
1852 'Ỳ' => 'Y',
1853 'ỳ' => 'y',
1854 // Hook.
1855 'Ả' => 'A',
1856 'ả' => 'a',
1857 'Ẩ' => 'A',
1858 'ẩ' => 'a',
1859 'Ẳ' => 'A',
1860 'ẳ' => 'a',
1861 'Ẻ' => 'E',
1862 'ẻ' => 'e',
1863 'Ể' => 'E',
1864 'ể' => 'e',
1865 'Ỉ' => 'I',
1866 'ỉ' => 'i',
1867 'Ỏ' => 'O',
1868 'ỏ' => 'o',
1869 'Ổ' => 'O',
1870 'ổ' => 'o',
1871 'Ở' => 'O',
1872 'ở' => 'o',
1873 'Ủ' => 'U',
1874 'ủ' => 'u',
1875 'Ử' => 'U',
1876 'ử' => 'u',
1877 'Ỷ' => 'Y',
1878 'ỷ' => 'y',
1879 // Tilde.
1880 'Ẫ' => 'A',
1881 'ẫ' => 'a',
1882 'Ẵ' => 'A',
1883 'ẵ' => 'a',
1884 'Ẽ' => 'E',
1885 'ẽ' => 'e',
1886 'Ễ' => 'E',
1887 'ễ' => 'e',
1888 'Ỗ' => 'O',
1889 'ỗ' => 'o',
1890 'Ỡ' => 'O',
1891 'ỡ' => 'o',
1892 'Ữ' => 'U',
1893 'ữ' => 'u',
1894 'Ỹ' => 'Y',
1895 'ỹ' => 'y',
1896 // Acute accent.
1897 'Ấ' => 'A',
1898 'ấ' => 'a',
1899 'Ắ' => 'A',
1900 'ắ' => 'a',
1901 'Ế' => 'E',
1902 'ế' => 'e',
1903 'Ố' => 'O',
1904 'ố' => 'o',
1905 'Ớ' => 'O',
1906 'ớ' => 'o',
1907 'Ứ' => 'U',
1908 'ứ' => 'u',
1909 // Dot below.
1910 'Ạ' => 'A',
1911 'ạ' => 'a',
1912 'Ậ' => 'A',
1913 'ậ' => 'a',
1914 'Ặ' => 'A',
1915 'ặ' => 'a',
1916 'Ẹ' => 'E',
1917 'ẹ' => 'e',
1918 'Ệ' => 'E',
1919 'ệ' => 'e',
1920 'Ị' => 'I',
1921 'ị' => 'i',
1922 'Ọ' => 'O',
1923 'ọ' => 'o',
1924 'Ộ' => 'O',
1925 'ộ' => 'o',
1926 'Ợ' => 'O',
1927 'ợ' => 'o',
1928 'Ụ' => 'U',
1929 'ụ' => 'u',
1930 'Ự' => 'U',
1931 'ự' => 'u',
1932 'Ỵ' => 'Y',
1933 'ỵ' => 'y',
1934 // Vowels with diacritic (Chinese, Hanyu Pinyin).
1935 'ɑ' => 'a',
1936 // Macron.
1937 'Ǖ' => 'U',
1938 'ǖ' => 'u',
1939 // Acute accent.
1940 'Ǘ' => 'U',
1941 'ǘ' => 'u',
1942 // Caron.
1943 'Ǎ' => 'A',
1944 'ǎ' => 'a',
1945 'Ǐ' => 'I',
1946 'ǐ' => 'i',
1947 'Ǒ' => 'O',
1948 'ǒ' => 'o',
1949 'Ǔ' => 'U',
1950 'ǔ' => 'u',
1951 'Ǚ' => 'U',
1952 'ǚ' => 'u',
1953 // Grave accent.
1954 'Ǜ' => 'U',
1955 'ǜ' => 'u',
1956 );
1957
1958 // Used for locale-specific rules.
1959 if ( empty( $locale ) ) {
1960 $locale = get_locale();
1961 }
1962
1963 /*
1964 * German has various locales (de_DE, de_CH, de_AT, ...) with formal and informal variants.
1965 * There is no 3-letter locale like 'def', so checking for 'de' instead of 'de_' is safe,
1966 * since 'de' itself would be a valid locale too.
1967 */
1968 if ( str_starts_with( $locale, 'de' ) ) {
1969 $chars['Ä'] = 'Ae';
1970 $chars['ä'] = 'ae';
1971 $chars['Ö'] = 'Oe';
1972 $chars['ö'] = 'oe';
1973 $chars['Ü'] = 'Ue';
1974 $chars['ü'] = 'ue';
1975 $chars['ß'] = 'ss';
1976 } elseif ( 'da_DK' === $locale ) {
1977 $chars['Æ'] = 'Ae';
1978 $chars['æ'] = 'ae';
1979 $chars['Ø'] = 'Oe';
1980 $chars['ø'] = 'oe';
1981 $chars['Å'] = 'Aa';
1982 $chars['å'] = 'aa';
1983 } elseif ( 'ca' === $locale ) {
1984 $chars['l·l'] = 'll';
1985 } elseif ( 'sr_RS' === $locale || 'bs_BA' === $locale ) {
1986 $chars['Đ'] = 'DJ';
1987 $chars['đ'] = 'dj';
1988 }
1989
1990 $text = strtr( $text, $chars );
1991 } else {
1992 $chars = array();
1993 // Assume ISO-8859-1 if not UTF-8.
1994 $chars['in'] = "\x80\x83\x8a\x8e\x9a\x9e"
1995 . "\x9f\xa2\xa5\xb5\xc0\xc1\xc2"
1996 . "\xc3\xc4\xc5\xc7\xc8\xc9\xca"
1997 . "\xcb\xcc\xcd\xce\xcf\xd1\xd2"
1998 . "\xd3\xd4\xd5\xd6\xd8\xd9\xda"
1999 . "\xdb\xdc\xdd\xe0\xe1\xe2\xe3"
2000 . "\xe4\xe5\xe7\xe8\xe9\xea\xeb"
2001 . "\xec\xed\xee\xef\xf1\xf2\xf3"
2002 . "\xf4\xf5\xf6\xf8\xf9\xfa\xfb"
2003 . "\xfc\xfd\xff";
2004
2005 $chars['out'] = 'EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy';
2006
2007 $text = strtr( $text, $chars['in'], $chars['out'] );
2008 $double_chars = array();
2009 $double_chars['in'] = array( "\x8c", "\x9c", "\xc6", "\xd0", "\xde", "\xdf", "\xe6", "\xf0", "\xfe" );
2010 $double_chars['out'] = array( 'OE', 'oe', 'AE', 'DH', 'TH', 'ss', 'ae', 'dh', 'th' );
2011 $text = str_replace( $double_chars['in'], $double_chars['out'], $text );
2012 }
2013
2014 return $text;
2015}
2016
2017/**
2018 * Sanitizes a filename, replacing whitespace with dashes.
2019 *
2020 * Removes special characters that are illegal in filenames on certain
2021 * operating systems and special characters requiring special escaping
2022 * to manipulate at the command line. Replaces spaces and consecutive
2023 * dashes with a single dash. Trims period, dash and underscore from beginning
2024 * and end of filename. It is not guaranteed that this function will return a
2025 * filename that is allowed to be uploaded.
2026 *
2027 * @since 2.1.0
2028 *
2029 * @param string $filename The filename to be sanitized.
2030 * @return string The sanitized filename.
2031 */
2032function sanitize_file_name( $filename ) {
2033 $filename_raw = $filename;
2034 $filename = remove_accents( $filename );
2035
2036 $special_chars = array( '?', '[', ']', '/', '\\', '=', '<', '>', ':', ';', ',', "'", '"', '&', '$', '#', '*', '(', ')', '|', '~', '`', '!', '{', '}', '%', '+', '’', '«', '»', '”', '“', chr( 0 ) );
2037
2038 if ( ! wp_is_valid_utf8( $filename ) ) {
2039 $_ext = pathinfo( $filename, PATHINFO_EXTENSION );
2040 $_name = pathinfo( $filename, PATHINFO_FILENAME );
2041 $filename = sanitize_title_with_dashes( $_name ) . '.' . $_ext;
2042 }
2043
2044 if ( _wp_can_use_pcre_u() ) {
2045 /**
2046 * Replace all whitespace characters with a basic space (U+0020).
2047 *
2048 * The “Zs” in the pattern selects characters in the `Space_Separator`
2049 * category, which is what Unicode considers space characters.
2050 *
2051 * @see https://www.unicode.org/reports/tr44/#General_Category_Values
2052 * @see https://www.unicode.org/versions/Unicode16.0.0/core-spec/chapter-6/#G17548
2053 * @see https://www.php.net/manual/en/regexp.reference.unicode.php
2054 */
2055 $filename = preg_replace( '#\p{Zs}#siu', ' ', $filename );
2056 }
2057
2058 /**
2059 * Filters the list of characters to remove from a filename.
2060 *
2061 * @since 2.8.0
2062 *
2063 * @param string[] $special_chars Array of characters to remove.
2064 * @param string $filename_raw The original filename to be sanitized.
2065 */
2066 $special_chars = apply_filters( 'sanitize_file_name_chars', $special_chars, $filename_raw );
2067
2068 $filename = str_replace( $special_chars, '', $filename );
2069 $filename = str_replace( array( '%20', '+' ), '-', $filename );
2070 $filename = preg_replace( '/\.{2,}/', '.', $filename );
2071 $filename = preg_replace( '/[\r\n\t -]+/', '-', $filename );
2072 $filename = trim( $filename, '.-_' );
2073
2074 if ( ! str_contains( $filename, '.' ) ) {
2075 $mime_types = wp_get_mime_types();
2076 $filetype = wp_check_filetype( 'test.' . $filename, $mime_types );
2077 if ( $filetype['ext'] === $filename ) {
2078 $filename = 'unnamed-file.' . $filetype['ext'];
2079 }
2080 }
2081
2082 // Split the filename into a base and extension[s].
2083 $parts = explode( '.', $filename );
2084
2085 // Return if only one extension.
2086 if ( count( $parts ) <= 2 ) {
2087 /** This filter is documented in wp-includes/formatting.php */
2088 return apply_filters( 'sanitize_file_name', $filename, $filename_raw );
2089 }
2090
2091 // Process multiple extensions.
2092 $filename = array_shift( $parts );
2093 $extension = array_pop( $parts );
2094 $mimes = get_allowed_mime_types();
2095
2096 /*
2097 * Loop over any intermediate extensions. Postfix them with a trailing underscore
2098 * if they are a 2 - 5 character long alpha string not in the allowed extension list.
2099 */
2100 foreach ( (array) $parts as $part ) {
2101 $filename .= '.' . $part;
2102
2103 if ( preg_match( '/^[a-zA-Z]{2,5}\d?$/', $part ) ) {
2104 $allowed = false;
2105 foreach ( $mimes as $ext_preg => $mime_match ) {
2106 $ext_preg = '!^(' . $ext_preg . ')$!i';
2107 if ( preg_match( $ext_preg, $part ) ) {
2108 $allowed = true;
2109 break;
2110 }
2111 }
2112 if ( ! $allowed ) {
2113 $filename .= '_';
2114 }
2115 }
2116 }
2117
2118 $filename .= '.' . $extension;
2119
2120 /**
2121 * Filters a sanitized filename string.
2122 *
2123 * @since 2.8.0
2124 *
2125 * @param string $filename Sanitized filename.
2126 * @param string $filename_raw The filename prior to sanitization.
2127 */
2128 return apply_filters( 'sanitize_file_name', $filename, $filename_raw );
2129}
2130
2131/**
2132 * Sanitizes a username, stripping out unsafe characters.
2133 *
2134 * Removes tags, percent-encoded characters, HTML entities, and if strict is enabled,
2135 * will only keep alphanumeric, _, space, ., -, @. After sanitizing, it passes the username,
2136 * raw username (the username in the parameter), and the value of $strict as parameters
2137 * for the {@see 'sanitize_user'} filter.
2138 *
2139 * @since 2.0.0
2140 *
2141 * @param string $username The username to be sanitized.
2142 * @param bool $strict Optional. If set to true, limits $username to specific characters.
2143 * Default false.
2144 * @return string The sanitized username, after passing through filters.
2145 */
2146function sanitize_user( $username, $strict = false ) {
2147 $raw_username = $username;
2148 $username = wp_strip_all_tags( $username );
2149 $username = remove_accents( $username );
2150 // Remove percent-encoded characters.
2151 $username = preg_replace( '|%([a-fA-F0-9][a-fA-F0-9])|', '', $username );
2152 // Remove HTML entities.
2153 $username = preg_replace( '/&.+?;/', '', $username );
2154
2155 // If strict, reduce to ASCII for max portability.
2156 if ( $strict ) {
2157 $username = preg_replace( '|[^a-z0-9 _.\-@]|i', '', $username );
2158 }
2159
2160 $username = trim( $username );
2161 // Consolidate contiguous whitespace.
2162 $username = preg_replace( '|\s+|', ' ', $username );
2163
2164 /**
2165 * Filters a sanitized username string.
2166 *
2167 * @since 2.0.1
2168 *
2169 * @param string $username Sanitized username.
2170 * @param string $raw_username The username prior to sanitization.
2171 * @param bool $strict Whether to limit the sanitization to specific characters.
2172 */
2173 return apply_filters( 'sanitize_user', $username, $raw_username, $strict );
2174}
2175
2176/**
2177 * Sanitizes a string key.
2178 *
2179 * Keys are used as internal identifiers. Lowercase alphanumeric characters,
2180 * dashes, and underscores are allowed.
2181 *
2182 * @since 3.0.0
2183 *
2184 * @param string $key String key.
2185 * @return string Sanitized key.
2186 */
2187function sanitize_key( $key ) {
2188 $sanitized_key = '';
2189
2190 if ( is_scalar( $key ) ) {
2191 $sanitized_key = strtolower( $key );
2192 $sanitized_key = preg_replace( '/[^a-z0-9_\-]/', '', $sanitized_key );
2193 }
2194
2195 /**
2196 * Filters a sanitized key string.
2197 *
2198 * @since 3.0.0
2199 *
2200 * @param string $sanitized_key Sanitized key.
2201 * @param string $key The key prior to sanitization.
2202 */
2203 return apply_filters( 'sanitize_key', $sanitized_key, $key );
2204}
2205
2206/**
2207 * Sanitizes a string into a slug, which can be used in URLs or HTML attributes.
2208 *
2209 * By default, converts accent characters to ASCII characters and further
2210 * limits the output to alphanumeric characters, underscore (_) and dash (-)
2211 * through the {@see 'sanitize_title'} filter.
2212 *
2213 * If `$title` is empty and `$fallback_title` is set, the latter will be used.
2214 *
2215 * @since 1.0.0
2216 *
2217 * @param string $title The string to be sanitized.
2218 * @param string $fallback_title Optional. A title to use if $title is empty. Default empty.
2219 * @param string $context Optional. The operation for which the string is sanitized.
2220 * When set to 'save', the string runs through remove_accents().
2221 * Default 'save'.
2222 * @return string The sanitized string.
2223 */
2224function sanitize_title( $title, $fallback_title = '', $context = 'save' ) {
2225 $raw_title = $title;
2226
2227 if ( 'save' === $context ) {
2228 $title = remove_accents( $title );
2229 }
2230
2231 /**
2232 * Filters a sanitized title string.
2233 *
2234 * @since 1.2.0
2235 *
2236 * @param string $title Sanitized title.
2237 * @param string $raw_title The title prior to sanitization.
2238 * @param string $context The context for which the title is being sanitized.
2239 */
2240 $title = apply_filters( 'sanitize_title', $title, $raw_title, $context );
2241
2242 if ( '' === $title || false === $title ) {
2243 $title = $fallback_title;
2244 }
2245
2246 return $title;
2247}
2248
2249/**
2250 * Sanitizes a title with the 'query' context.
2251 *
2252 * Used for querying the database for a value from URL.
2253 *
2254 * @since 3.1.0
2255 *
2256 * @param string $title The string to be sanitized.
2257 * @return string The sanitized string.
2258 */
2259function sanitize_title_for_query( $title ) {
2260 return sanitize_title( $title, '', 'query' );
2261}
2262
2263/**
2264 * Sanitizes a title, replacing whitespace and a few other characters with dashes.
2265 *
2266 * Limits the output to alphanumeric characters, underscore (_) and dash (-).
2267 * Whitespace becomes a dash.
2268 *
2269 * @since 1.2.0
2270 *
2271 * @param string $title The title to be sanitized.
2272 * @param string $raw_title Optional. Not used. Default empty.
2273 * @param string $context Optional. The operation for which the string is sanitized.
2274 * When set to 'save', additional entities are converted to hyphens
2275 * or stripped entirely. Default 'display'.
2276 * @return string The sanitized title.
2277 */
2278function sanitize_title_with_dashes( $title, $raw_title = '', $context = 'display' ) {
2279 $title = strip_tags( $title );
2280 // Preserve escaped octets.
2281 $title = preg_replace( '|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title );
2282 // Remove percent signs that are not part of an octet.
2283 $title = str_replace( '%', '', $title );
2284 // Restore octets.
2285 $title = preg_replace( '|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title );
2286
2287 if ( wp_is_valid_utf8( $title ) ) {
2288 if ( function_exists( 'mb_strtolower' ) ) {
2289 $title = mb_strtolower( $title, 'UTF-8' );
2290 }
2291 $title = utf8_uri_encode( $title, 200 );
2292 }
2293
2294 $title = strtolower( $title );
2295
2296 if ( 'save' === $context ) {
2297 // Convert  , non-breaking hyphen, &ndash, and &mdash to hyphens.
2298 $title = str_replace( array( '%c2%a0', '%e2%80%91', '%e2%80%93', '%e2%80%94' ), '-', $title );
2299 // Convert  , non-breaking hyphen, &ndash, and &mdash HTML entities to hyphens.
2300 $title = str_replace( array( ' ', '‑', ' ', '–', '–', '—', '—' ), '-', $title );
2301 // Convert forward slash to hyphen.
2302 $title = str_replace( '/', '-', $title );
2303
2304 // Strip these characters entirely.
2305 $title = str_replace(
2306 array(
2307 // Soft hyphens.
2308 '%c2%ad',
2309 // ¡ and ¿.
2310 '%c2%a1',
2311 '%c2%bf',
2312 // Angle quotes.
2313 '%c2%ab',
2314 '%c2%bb',
2315 '%e2%80%b9',
2316 '%e2%80%ba',
2317 // Curly quotes.
2318 '%e2%80%98',
2319 '%e2%80%99',
2320 '%e2%80%9c',
2321 '%e2%80%9d',
2322 '%e2%80%9a',
2323 '%e2%80%9b',
2324 '%e2%80%9e',
2325 '%e2%80%9f',
2326 // Bullet.
2327 '%e2%80%a2',
2328 // ©, ®, °, &hellip, and &trade.
2329 '%c2%a9',
2330 '%c2%ae',
2331 '%c2%b0',
2332 '%e2%80%a6',
2333 '%e2%84%a2',
2334 // Acute accents.
2335 '%c2%b4',
2336 '%cb%8a',
2337 '%cc%81',
2338 '%cd%81',
2339 // Grave accent, macron, caron.
2340 '%cc%80',
2341 '%cc%84',
2342 '%cc%8c',
2343 // Non-visible characters that display without a width.
2344 '%e2%80%8b', // Zero width space.
2345 '%e2%80%8c', // Zero width non-joiner.
2346 '%e2%80%8d', // Zero width joiner.
2347 '%e2%80%8e', // Left-to-right mark.
2348 '%e2%80%8f', // Right-to-left mark.
2349 '%e2%80%aa', // Left-to-right embedding.
2350 '%e2%80%ab', // Right-to-left embedding.
2351 '%e2%80%ac', // Pop directional formatting.
2352 '%e2%80%ad', // Left-to-right override.
2353 '%e2%80%ae', // Right-to-left override.
2354 '%ef%bb%bf', // Byte order mark.
2355 '%ef%bf%bc', // Object replacement character.
2356 ),
2357 '',
2358 $title
2359 );
2360
2361 // Convert non-visible characters that display with a width to hyphen.
2362 $title = str_replace(
2363 array(
2364 '%e2%80%80', // En quad.
2365 '%e2%80%81', // Em quad.
2366 '%e2%80%82', // En space.
2367 '%e2%80%83', // Em space.
2368 '%e2%80%84', // Three-per-em space.
2369 '%e2%80%85', // Four-per-em space.
2370 '%e2%80%86', // Six-per-em space.
2371 '%e2%80%87', // Figure space.
2372 '%e2%80%88', // Punctuation space.
2373 '%e2%80%89', // Thin space.
2374 '%e2%80%8a', // Hair space.
2375 '%e2%80%a8', // Line separator.
2376 '%e2%80%a9', // Paragraph separator.
2377 '%e2%80%af', // Narrow no-break space.
2378 ),
2379 '-',
2380 $title
2381 );
2382
2383 // Convert × to 'x'.
2384 $title = str_replace( '%c3%97', 'x', $title );
2385 }
2386
2387 // Remove HTML entities.
2388 $title = preg_replace( '/&.+?;/', '', $title );
2389 $title = str_replace( '.', '-', $title );
2390
2391 $title = preg_replace( '/[^%a-z0-9 _-]/', '', $title );
2392 $title = preg_replace( '/\s+/', '-', $title );
2393 $title = preg_replace( '|-+|', '-', $title );
2394 $title = trim( $title, '-' );
2395
2396 return $title;
2397}
2398
2399/**
2400 * Ensures a string is a valid SQL 'order by' clause.
2401 *
2402 * Accepts one or more columns, with or without a sort order (ASC / DESC).
2403 * e.g. 'column_1', 'column_1, column_2', 'column_1 ASC, column_2 DESC' etc.
2404 *
2405 * Also accepts 'RAND()'.
2406 *
2407 * @since 2.5.1
2408 *
2409 * @param string $orderby Order by clause to be validated.
2410 * @return string|false Returns $orderby if valid, false otherwise.
2411 */
2412function sanitize_sql_orderby( $orderby ) {
2413 if ( preg_match( '/^\s*(([a-z0-9_]+|`[a-z0-9_]+`)(\s+(ASC|DESC))?\s*(,\s*(?=[a-z0-9_`])|$))+$/i', $orderby ) || preg_match( '/^\s*RAND\(\s*\)\s*$/i', $orderby ) ) {
2414 return $orderby;
2415 }
2416 return false;
2417}
2418
2419/**
2420 * Sanitizes an HTML classname to ensure it only contains valid characters.
2421 *
2422 * Strips the string down to A-Z,a-z,0-9,_,-. If this results in an empty
2423 * string then it will return the alternative value supplied.
2424 *
2425 * @todo Expand to support the full range of CDATA that a class attribute can contain.
2426 *
2427 * @since 2.8.0
2428 *
2429 * @param string $classname The classname to be sanitized.
2430 * @param string $fallback Optional. The value to return if the sanitization ends up as an empty string.
2431 * Default empty string.
2432 * @return string The sanitized value.
2433 */
2434function sanitize_html_class( $classname, $fallback = '' ) {
2435 // Strip out any percent-encoded characters.
2436 $sanitized = preg_replace( '|%[a-fA-F0-9][a-fA-F0-9]|', '', $classname );
2437
2438 // Limit to A-Z, a-z, 0-9, '_', '-'.
2439 $sanitized = preg_replace( '/[^A-Za-z0-9_-]/', '', $sanitized );
2440
2441 if ( '' === $sanitized && $fallback ) {
2442 return sanitize_html_class( $fallback );
2443 }
2444 /**
2445 * Filters a sanitized HTML class string.
2446 *
2447 * @since 2.8.0
2448 *
2449 * @param string $sanitized The sanitized HTML class.
2450 * @param string $classname HTML class before sanitization.
2451 * @param string $fallback The fallback string.
2452 */
2453 return apply_filters( 'sanitize_html_class', $sanitized, $classname, $fallback );
2454}
2455
2456/**
2457 * Strips out all characters not allowed in a locale name.
2458 *
2459 * @since 6.2.1
2460 *
2461 * @param string $locale_name The locale name to be sanitized.
2462 * @return string The sanitized value.
2463 */
2464function sanitize_locale_name( $locale_name ) {
2465 // Limit to A-Z, a-z, 0-9, '_', '-'.
2466 $sanitized = preg_replace( '/[^A-Za-z0-9_-]/', '', $locale_name );
2467
2468 /**
2469 * Filters a sanitized locale name string.
2470 *
2471 * @since 6.2.1
2472 *
2473 * @param string $sanitized The sanitized locale name.
2474 * @param string $locale_name The locale name before sanitization.
2475 */
2476 return apply_filters( 'sanitize_locale_name', $sanitized, $locale_name );
2477}
2478
2479/**
2480 * Converts lone & characters into `&` (a.k.a. `&`)
2481 *
2482 * @since 0.71
2483 *
2484 * @param string $content String of characters to be converted.
2485 * @param string $deprecated Not used.
2486 * @return string Converted string.
2487 */
2488function convert_chars( $content, $deprecated = '' ) {
2489 if ( ! empty( $deprecated ) ) {
2490 _deprecated_argument( __FUNCTION__, '0.71' );
2491 }
2492
2493 if ( str_contains( $content, '&' ) ) {
2494 $content = preg_replace( '/&([^#])(?![a-z1-4]{1,8};)/i', '&$1', $content );
2495 }
2496
2497 return $content;
2498}
2499
2500/**
2501 * Converts invalid Unicode references range to valid range.
2502 *
2503 * @since 4.3.0
2504 *
2505 * @param string $content String with entities that need converting.
2506 * @return string Converted string.
2507 */
2508function convert_invalid_entities( $content ) {
2509 $wp_htmltranswinuni = array(
2510 '€' => '€', // The Euro sign.
2511 '' => '',
2512 '‚' => '‚', // These are Windows CP1252 specific characters.
2513 'ƒ' => 'ƒ', // They would look weird on non-Windows browsers.
2514 '„' => '„',
2515 '…' => '…',
2516 '†' => '†',
2517 '‡' => '‡',
2518 'ˆ' => 'ˆ',
2519 '‰' => '‰',
2520 'Š' => 'Š',
2521 '‹' => '‹',
2522 'Œ' => 'Œ',
2523 '' => '',
2524 'Ž' => 'Ž',
2525 '' => '',
2526 '' => '',
2527 '‘' => '‘',
2528 '’' => '’',
2529 '“' => '“',
2530 '”' => '”',
2531 '•' => '•',
2532 '–' => '–',
2533 '—' => '—',
2534 '˜' => '˜',
2535 '™' => '™',
2536 'š' => 'š',
2537 '›' => '›',
2538 'œ' => 'œ',
2539 '' => '',
2540 'ž' => 'ž',
2541 'Ÿ' => 'Ÿ',
2542 );
2543
2544 if ( str_contains( $content, '' ) ) {
2545 $content = strtr( $content, $wp_htmltranswinuni );
2546 }
2547
2548 return $content;
2549}
2550
2551/**
2552 * Balances tags if forced to, or if the 'use_balanceTags' option is set to true.
2553 *
2554 * @since 0.71
2555 *
2556 * @param string $text Text to be balanced.
2557 * @param bool $force If true, forces balancing, ignoring the value of the option. Default false.
2558 * @return string Balanced text.
2559 */
2560function balanceTags( $text, $force = false ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
2561 if ( $force || 1 === (int) get_option( 'use_balanceTags' ) ) {
2562 return force_balance_tags( $text );
2563 } else {
2564 return $text;
2565 }
2566}
2567
2568/**
2569 * Balances tags of string using a modified stack.
2570 *
2571 * {@internal Modified by Scott Reilly (coffee2code) 02 Aug 2004
2572 * 1.1 Fixed handling of append/stack pop order of end text
2573 * Added Cleaning Hooks
2574 * 1.0 First Version}
2575 *
2576 * @since 2.0.4
2577 * @since 5.3.0 Improve accuracy and add support for custom element tags.
2578 *
2579 * @author Leonard Lin <leonard@acm.org>
2580 * @license GPL
2581 * @copyright November 4, 2001
2582 * @version 1.1
2583 * @todo Make better - change loop condition to $text in 1.2
2584 *
2585 * @param string $text Text to be balanced.
2586 * @return string Balanced text.
2587 */
2588function force_balance_tags( $text ) {
2589 $tagstack = array();
2590 $stacksize = 0;
2591 $tagqueue = '';
2592 $newtext = '';
2593 // Known single-entity/self-closing tags.
2594 $single_tags = array( 'area', 'base', 'basefont', 'br', 'col', 'command', 'embed', 'frame', 'hr', 'img', 'input', 'isindex', 'link', 'meta', 'param', 'source', 'track', 'wbr' );
2595 // Tags that can be immediately nested within themselves.
2596 $nestable_tags = array( 'article', 'aside', 'blockquote', 'details', 'div', 'figure', 'object', 'q', 'section', 'span' );
2597
2598 // WP bug fix for comments - in case you REALLY meant to type '< !--'.
2599 $text = str_replace( '< !--', '< !--', $text );
2600 // WP bug fix for LOVE <3 (and other situations with '<' before a number).
2601 $text = preg_replace( '#<([0-9]{1})#', '<$1', $text );
2602
2603 /**
2604 * Matches supported tags.
2605 *
2606 * To get the pattern as a string without the comments paste into a PHP
2607 * REPL like `php -a`.
2608 *
2609 * @see https://html.spec.whatwg.org/#elements-2
2610 * @see https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
2611 *
2612 * @example
2613 * ~# php -a
2614 * php > $s = [paste copied contents of expression below including parentheses];
2615 * php > echo $s;
2616 */
2617 $tag_pattern = (
2618 '#<' . // Start with an opening bracket.
2619 '(/?)' . // Group 1 - If it's a closing tag it'll have a leading slash.
2620 '(' . // Group 2 - Tag name.
2621 // Custom element tags have more lenient rules than HTML tag names.
2622 '(?:[a-z](?:[a-z0-9._]*)-(?:[a-z0-9._-]+)+)' .
2623 '|' .
2624 // Traditional tag rules approximate HTML tag names.
2625 '(?:[\w:]+)' .
2626 ')' .
2627 '(?:' .
2628 // We either immediately close the tag with its '>' and have nothing here.
2629 '\s*' .
2630 '(/?)' . // Group 3 - "attributes" for empty tag.
2631 '|' .
2632 // Or we must start with space characters to separate the tag name from the attributes (or whitespace).
2633 '(\s+)' . // Group 4 - Pre-attribute whitespace.
2634 '([^>]*)' . // Group 5 - Attributes.
2635 ')' .
2636 '>#' // End with a closing bracket.
2637 );
2638
2639 while ( preg_match( $tag_pattern, $text, $regex ) ) {
2640 $full_match = $regex[0];
2641 $has_leading_slash = ! empty( $regex[1] );
2642 $tag_name = $regex[2];
2643 $tag = strtolower( $tag_name );
2644 $is_single_tag = in_array( $tag, $single_tags, true );
2645 $pre_attribute_ws = isset( $regex[4] ) ? $regex[4] : '';
2646 $attributes = trim( isset( $regex[5] ) ? $regex[5] : $regex[3] );
2647 $has_self_closer = str_ends_with( $attributes, '/' );
2648
2649 $newtext .= $tagqueue;
2650
2651 $i = strpos( $text, $full_match );
2652 $l = strlen( $full_match );
2653
2654 // Clear the shifter.
2655 $tagqueue = '';
2656 if ( $has_leading_slash ) { // End tag.
2657 // If too many closing tags.
2658 if ( $stacksize <= 0 ) {
2659 $tag = '';
2660 // Or close to be safe $tag = '/' . $tag.
2661
2662 // If stacktop value = tag close value, then pop.
2663 } elseif ( $tagstack[ $stacksize - 1 ] === $tag ) { // Found closing tag.
2664 $tag = '</' . $tag . '>'; // Close tag.
2665 array_pop( $tagstack );
2666 --$stacksize;
2667 } else { // Closing tag not at top, search for it.
2668 for ( $j = $stacksize - 1; $j >= 0; $j-- ) {
2669 if ( $tagstack[ $j ] === $tag ) {
2670 // Add tag to tagqueue.
2671 for ( $k = $stacksize - 1; $k >= $j; $k-- ) {
2672 $tagqueue .= '</' . array_pop( $tagstack ) . '>';
2673 --$stacksize;
2674 }
2675 break;
2676 }
2677 }
2678 $tag = '';
2679 }
2680 } else { // Begin tag.
2681 if ( $has_self_closer ) {
2682 /*
2683 * If it presents itself as a self-closing tag, but it isn't a known single-entity self-closing tag,
2684 * then don't let it be treated as such and immediately close it with a closing tag.
2685 * The tag will encapsulate no text as a result.
2686 */
2687 if ( ! $is_single_tag ) {
2688 $attributes = trim( substr( $attributes, 0, -1 ) ) . "></$tag";
2689 }
2690 } elseif ( $is_single_tag ) {
2691 // Else if it's a known single-entity tag but it doesn't close itself, do so.
2692 $pre_attribute_ws = ' ';
2693 $attributes .= '/';
2694 } else {
2695 /*
2696 * It's not a single-entity tag.
2697 * If the top of the stack is the same as the tag we want to push, close previous tag.
2698 */
2699 if ( $stacksize > 0 && ! in_array( $tag, $nestable_tags, true ) && $tagstack[ $stacksize - 1 ] === $tag ) {
2700 $tagqueue = '</' . array_pop( $tagstack ) . '>';
2701 --$stacksize;
2702 }
2703 $stacksize = array_push( $tagstack, $tag );
2704 }
2705
2706 // Attributes.
2707 if ( $has_self_closer && $is_single_tag ) {
2708 // We need some space - avoid <br/> and prefer <br />.
2709 $pre_attribute_ws = ' ';
2710 }
2711
2712 $tag = '<' . $tag . $pre_attribute_ws . $attributes . '>';
2713 // If already queuing a close tag, then put this tag on too.
2714 if ( ! empty( $tagqueue ) ) {
2715 $tagqueue .= $tag;
2716 $tag = '';
2717 }
2718 }
2719 $newtext .= substr( $text, 0, $i ) . $tag;
2720 $text = substr( $text, $i + $l );
2721 }
2722
2723 // Clear tag queue.
2724 $newtext .= $tagqueue;
2725
2726 // Add remaining text.
2727 $newtext .= $text;
2728
2729 while ( $x = array_pop( $tagstack ) ) {
2730 $newtext .= '</' . $x . '>'; // Add remaining tags to close.
2731 }
2732
2733 // WP fix for the bug with HTML comments.
2734 $newtext = str_replace( '< !--', '<!--', $newtext );
2735 $newtext = str_replace( '< !--', '< !--', $newtext );
2736
2737 return $newtext;
2738}
2739
2740/**
2741 * Acts on text which is about to be edited.
2742 *
2743 * The $content is run through esc_textarea(), which uses htmlspecialchars()
2744 * to convert special characters to HTML entities. If `$richedit` is set to true,
2745 * it is simply a holder for the {@see 'format_to_edit'} filter.
2746 *
2747 * @since 0.71
2748 * @since 4.4.0 The `$richedit` parameter was renamed to `$rich_text` for clarity.
2749 *
2750 * @param string $content The text about to be edited.
2751 * @param bool $rich_text Optional. Whether `$content` should be considered rich text,
2752 * in which case it would not be passed through esc_textarea().
2753 * Default false.
2754 * @return string The text after the filter (and possibly htmlspecialchars()) has been run.
2755 */
2756function format_to_edit( $content, $rich_text = false ) {
2757 /**
2758 * Filters the text to be formatted for editing.
2759 *
2760 * @since 1.2.0
2761 *
2762 * @param string $content The text, prior to formatting for editing.
2763 */
2764 $content = apply_filters( 'format_to_edit', $content );
2765 if ( ! $rich_text ) {
2766 $content = esc_textarea( $content );
2767 }
2768 return $content;
2769}
2770
2771/**
2772 * Add leading zeros when necessary.
2773 *
2774 * If you set the threshold to '4' and the number is '10', then you will get
2775 * back '0010'. If you set the threshold to '4' and the number is '5000', then you
2776 * will get back '5000'.
2777 *
2778 * Uses sprintf to append the amount of zeros based on the $threshold parameter
2779 * and the size of the number. If the number is large enough, then no zeros will
2780 * be appended.
2781 *
2782 * @since 0.71
2783 *
2784 * @param int $number Number to append zeros to if not greater than threshold.
2785 * @param int $threshold Digit places number needs to be to not have zeros added.
2786 * @return string Adds leading zeros to number if needed.
2787 */
2788function zeroise( $number, $threshold ) {
2789 return sprintf( '%0' . $threshold . 's', $number );
2790}
2791
2792/**
2793 * Adds backslashes before letters and before a number at the start of a string.
2794 *
2795 * @since 0.71
2796 *
2797 * @param string $value Value to which backslashes will be added.
2798 * @return string String with backslashes inserted.
2799 */
2800function backslashit( $value ) {
2801 if ( isset( $value[0] ) && $value[0] >= '0' && $value[0] <= '9' ) {
2802 $value = '\\\\' . $value;
2803 }
2804 return addcslashes( $value, 'A..Za..z' );
2805}
2806
2807/**
2808 * Appends a trailing slash.
2809 *
2810 * Will remove trailing forward and backslashes if it exists already before adding
2811 * a trailing forward slash. This prevents double slashing a string or path.
2812 *
2813 * The primary use of this is for paths and thus should be used for paths. It is
2814 * not restricted to paths and offers no specific path support.
2815 *
2816 * @since 1.2.0
2817 *
2818 * @param string $value Value to which trailing slash will be added.
2819 * @return string String with trailing slash added.
2820 */
2821function trailingslashit( $value ) {
2822 return untrailingslashit( $value ) . '/';
2823}
2824
2825/**
2826 * Removes trailing forward slashes and backslashes if they exist.
2827 *
2828 * The primary use of this is for paths and thus should be used for paths. It is
2829 * not restricted to paths and offers no specific path support.
2830 *
2831 * @since 2.2.0
2832 *
2833 * @param string $value Value from which trailing slashes will be removed.
2834 * @return string String without the trailing slashes.
2835 */
2836function untrailingslashit( $value ) {
2837 return rtrim( $value, '/\\' );
2838}
2839
2840/**
2841 * Adds slashes to a string or recursively adds slashes to strings within an array.
2842 *
2843 * @since 0.71
2844 *
2845 * @param string|array $gpc String or array of data to slash.
2846 * @return string|array Slashed `$gpc`.
2847 */
2848function addslashes_gpc( $gpc ) {
2849 return wp_slash( $gpc );
2850}
2851
2852/**
2853 * Navigates through an array, object, or scalar, and removes slashes from the values.
2854 *
2855 * @since 2.0.0
2856 *
2857 * @param mixed $value The value to be stripped.
2858 * @return mixed Stripped value.
2859 */
2860function stripslashes_deep( $value ) {
2861 return map_deep( $value, 'stripslashes_from_strings_only' );
2862}
2863
2864/**
2865 * Callback function for `stripslashes_deep()` which strips slashes from strings.
2866 *
2867 * @since 4.4.0
2868 *
2869 * @param mixed $value The array or string to be stripped.
2870 * @return mixed The stripped value.
2871 */
2872function stripslashes_from_strings_only( $value ) {
2873 return is_string( $value ) ? stripslashes( $value ) : $value;
2874}
2875
2876/**
2877 * Navigates through an array, object, or scalar, and encodes the values to be used in a URL.
2878 *
2879 * @since 2.2.0
2880 *
2881 * @param mixed $value The array or string to be encoded.
2882 * @return mixed The encoded value.
2883 */
2884function urlencode_deep( $value ) {
2885 return map_deep( $value, 'urlencode' );
2886}
2887
2888/**
2889 * Navigates through an array, object, or scalar, and raw-encodes the values to be used in a URL.
2890 *
2891 * @since 3.4.0
2892 *
2893 * @param mixed $value The array or string to be encoded.
2894 * @return mixed The encoded value.
2895 */
2896function rawurlencode_deep( $value ) {
2897 return map_deep( $value, 'rawurlencode' );
2898}
2899
2900/**
2901 * Navigates through an array, object, or scalar, and decodes URL-encoded values
2902 *
2903 * @since 4.4.0
2904 *
2905 * @param mixed $value The array or string to be decoded.
2906 * @return mixed The decoded value.
2907 */
2908function urldecode_deep( $value ) {
2909 return map_deep( $value, 'urldecode' );
2910}
2911
2912/**
2913 * Converts email addresses characters to HTML entities to block spam bots.
2914 *
2915 * @since 0.71
2916 *
2917 * @param string $email_address Email address.
2918 * @param int $hex_encoding Optional. Set to 1 to enable hex encoding.
2919 * @return string Converted email address.
2920 */
2921function antispambot( $email_address, $hex_encoding = 0 ) {
2922 $email_no_spam_address = '';
2923
2924 for ( $i = 0, $len = strlen( $email_address ); $i < $len; $i++ ) {
2925 $j = rand( 0, 1 + $hex_encoding );
2926
2927 if ( 0 === $j ) {
2928 $email_no_spam_address .= '&#' . ord( $email_address[ $i ] ) . ';';
2929 } elseif ( 1 === $j ) {
2930 $email_no_spam_address .= $email_address[ $i ];
2931 } elseif ( 2 === $j ) {
2932 $email_no_spam_address .= '%' . zeroise( dechex( ord( $email_address[ $i ] ) ), 2 );
2933 }
2934 }
2935
2936 return str_replace( '@', '@', $email_no_spam_address );
2937}
2938
2939/**
2940 * Callback to convert URI match to HTML A element.
2941 *
2942 * This function was backported from 2.5.0 to 2.3.2. Regex callback for make_clickable().
2943 *
2944 * @since 2.3.2
2945 * @access private
2946 *
2947 * @param array $matches Single Regex Match.
2948 * @return string HTML A element with URI address.
2949 */
2950function _make_url_clickable_cb( $matches ) {
2951 $url = $matches[2];
2952
2953 if ( ')' === $matches[3] && strpos( $url, '(' ) ) {
2954 /*
2955 * If the trailing character is a closing parenthesis, and the URL has an opening parenthesis in it,
2956 * add the closing parenthesis to the URL. Then we can let the parenthesis balancer do its thing below.
2957 */
2958 $url .= $matches[3];
2959 $suffix = '';
2960 } else {
2961 $suffix = $matches[3];
2962 }
2963
2964 if ( isset( $matches[4] ) && ! empty( $matches[4] ) ) {
2965 $url .= $matches[4];
2966 }
2967
2968 // Include parentheses in the URL only if paired.
2969 while ( substr_count( $url, '(' ) < substr_count( $url, ')' ) ) {
2970 $suffix = strrchr( $url, ')' ) . $suffix;
2971 $url = substr( $url, 0, strrpos( $url, ')' ) );
2972 }
2973
2974 $url = esc_url( $url );
2975 if ( empty( $url ) ) {
2976 return $matches[0];
2977 }
2978
2979 $rel_attr = _make_clickable_rel_attr( $url );
2980
2981 return $matches[1] . "<a href=\"{$url}\"{$rel_attr}>{$url}</a>" . $suffix;
2982}
2983
2984/**
2985 * Callback to convert URL match to HTML A element.
2986 *
2987 * This function was backported from 2.5.0 to 2.3.2. Regex callback for make_clickable().
2988 *
2989 * @since 2.3.2
2990 * @access private
2991 *
2992 * @param array $matches Single Regex Match.
2993 * @return string HTML A element with URL address.
2994 */
2995function _make_web_ftp_clickable_cb( $matches ) {
2996 $ret = '';
2997 $dest = $matches[2];
2998 $dest = 'http://' . $dest;
2999
3000 // Removed trailing [.,;:)] from URL.
3001 $last_char = substr( $dest, -1 );
3002 if ( in_array( $last_char, array( '.', ',', ';', ':', ')' ), true ) ) {
3003 $ret = $last_char;
3004 $dest = substr( $dest, 0, strlen( $dest ) - 1 );
3005 }
3006
3007 $dest = esc_url( $dest );
3008 if ( empty( $dest ) ) {
3009 return $matches[0];
3010 }
3011
3012 $rel_attr = _make_clickable_rel_attr( $dest );
3013
3014 return $matches[1] . "<a href=\"{$dest}\"{$rel_attr}>{$dest}</a>{$ret}";
3015}
3016
3017/**
3018 * Callback to convert email address match to HTML A element.
3019 *
3020 * This function was backported from 2.5.0 to 2.3.2. Regex callback for make_clickable().
3021 *
3022 * @since 2.3.2
3023 * @access private
3024 *
3025 * @param array $matches Single Regex Match.
3026 * @return string HTML A element with email address.
3027 */
3028function _make_email_clickable_cb( $matches ) {
3029 $email = $matches[2] . '@' . $matches[3];
3030
3031 return $matches[1] . "<a href=\"mailto:{$email}\">{$email}</a>";
3032}
3033
3034/**
3035 * Helper function used to build the "rel" attribute for a URL when creating an anchor using make_clickable().
3036 *
3037 * @since 6.2.0
3038 *
3039 * @param string $url The URL.
3040 * @return string The rel attribute for the anchor or an empty string if no rel attribute should be added.
3041 */
3042function _make_clickable_rel_attr( $url ) {
3043 $rel_parts = array();
3044 $scheme = strtolower( wp_parse_url( $url, PHP_URL_SCHEME ) );
3045 $nofollow_schemes = array_intersect( wp_allowed_protocols(), array( 'https', 'http' ) );
3046
3047 // Apply "nofollow" to external links with qualifying URL schemes (mailto:, tel:, etc... shouldn't be followed).
3048 if ( ! wp_is_internal_link( $url ) && in_array( $scheme, $nofollow_schemes, true ) ) {
3049 $rel_parts[] = 'nofollow';
3050 }
3051
3052 // Apply "ugc" when in comment context.
3053 if ( 'comment_text' === current_filter() ) {
3054 $rel_parts[] = 'ugc';
3055 }
3056
3057 $rel = implode( ' ', $rel_parts );
3058
3059 /**
3060 * Filters the rel value that is added to URL matches converted to links.
3061 *
3062 * @since 5.3.0
3063 *
3064 * @param string $rel The rel value.
3065 * @param string $url The matched URL being converted to a link tag.
3066 */
3067 $rel = apply_filters( 'make_clickable_rel', $rel, $url );
3068
3069 $rel_attr = $rel ? ' rel="' . esc_attr( $rel ) . '"' : '';
3070
3071 return $rel_attr;
3072}
3073
3074/**
3075 * Converts plaintext URI to HTML links.
3076 *
3077 * Converts URI, www and ftp, and email addresses. Finishes by fixing links
3078 * within links.
3079 *
3080 * @since 0.71
3081 *
3082 * @param string $text Content to convert URIs.
3083 * @return string Content with converted URIs.
3084 */
3085function make_clickable( $text ) {
3086 $r = '';
3087 $textarr = preg_split( '/(<[^<>]+>)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // Split out HTML tags.
3088 $nested_code_pre = 0; // Keep track of how many levels link is nested inside <pre> or <code>.
3089 foreach ( $textarr as $piece ) {
3090
3091 if ( preg_match( '|^<code[\s>]|i', $piece )
3092 || preg_match( '|^<pre[\s>]|i', $piece )
3093 || preg_match( '|^<script[\s>]|i', $piece )
3094 || preg_match( '|^<style[\s>]|i', $piece )
3095 ) {
3096 ++$nested_code_pre;
3097 } elseif ( $nested_code_pre
3098 && ( '</code>' === strtolower( $piece )
3099 || '</pre>' === strtolower( $piece )
3100 || '</script>' === strtolower( $piece )
3101 || '</style>' === strtolower( $piece )
3102 )
3103 ) {
3104 --$nested_code_pre;
3105 }
3106
3107 if ( $nested_code_pre
3108 || empty( $piece )
3109 || ( '<' === $piece[0] && ! preg_match( '|^<\s*[\w]{1,20}+://|', $piece ) )
3110 ) {
3111 $r .= $piece;
3112 continue;
3113 }
3114
3115 // Long strings might contain expensive edge cases...
3116 if ( 10000 < strlen( $piece ) ) {
3117 // ...break it up.
3118 foreach ( _split_str_by_whitespace( $piece, 2100 ) as $chunk ) { // 2100: Extra room for scheme and leading and trailing parentheses.
3119 if ( 2101 < strlen( $chunk ) ) {
3120 $r .= $chunk; // Too big, no whitespace: bail.
3121 } else {
3122 $r .= make_clickable( $chunk );
3123 }
3124 }
3125 } else {
3126 $ret = " $piece "; // Pad with whitespace to simplify the regexes.
3127
3128 $url_clickable = '~
3129 ([\\s(<.,;:!?]) # 1: Leading whitespace, or punctuation.
3130 ( # 2: URL.
3131 [\\w]{1,20}+:// # Scheme and hier-part prefix.
3132 (?=\S{1,2000}\s) # Limit to URLs less than about 2000 characters long.
3133 [\\w\\x80-\\xff#%\\~/@\\[\\]*(+=&$-]*+ # Non-punctuation URL character.
3134 (?: # Unroll the Loop: Only allow punctuation URL character if followed by a non-punctuation URL character.
3135 [\'.,;:!?)] # Punctuation URL character.
3136 [\\w\\x80-\\xff#%\\~/@\\[\\]*(+=&$-]++ # Non-punctuation URL character.
3137 )*
3138 )
3139 (\)?) # 3: Trailing closing parenthesis (for parenthesis balancing post processing).
3140 (\\.\\w{2,6})? # 4: Allowing file extensions (e.g., .jpg, .png).
3141 ~xS';
3142 /*
3143 * The regex is a non-anchored pattern and does not have a single fixed starting character.
3144 * Tell PCRE to spend more time optimizing since, when used on a page load, it will probably be used several times.
3145 */
3146
3147 $ret = preg_replace_callback( $url_clickable, '_make_url_clickable_cb', $ret );
3148
3149 $ret = preg_replace_callback( '#([\s>])((www|ftp)\.[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]+)#is', '_make_web_ftp_clickable_cb', $ret );
3150 $ret = preg_replace_callback( '#([\s>])([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})#i', '_make_email_clickable_cb', $ret );
3151
3152 $ret = substr( $ret, 1, -1 ); // Remove our whitespace padding.
3153 $r .= $ret;
3154 }
3155 }
3156
3157 // Cleanup of accidental links within links.
3158 return preg_replace( '#(<a([ \r\n\t]+[^>]+?>|>))<a [^>]+?>([^>]+?)</a></a>#i', '$1$3</a>', $r );
3159}
3160
3161/**
3162 * Breaks a string into chunks by splitting at whitespace characters.
3163 *
3164 * The length of each returned chunk is as close to the specified length goal as possible,
3165 * with the caveat that each chunk includes its trailing delimiter.
3166 * Chunks longer than the goal are guaranteed to not have any inner whitespace.
3167 *
3168 * Joining the returned chunks with empty delimiters reconstructs the input string losslessly.
3169 *
3170 * Input string must have no null characters (or eventual transformations on output chunks must not care about null characters)
3171 *
3172 * _split_str_by_whitespace( "1234 67890 1234 67890a cd 1234 890 123456789 1234567890a 45678 1 3 5 7 90 ", 10 ) ==
3173 * array (
3174 * 0 => '1234 67890 ', // 11 characters: Perfect split.
3175 * 1 => '1234 ', // 5 characters: '1234 67890a' was too long.
3176 * 2 => '67890a cd ', // 10 characters: '67890a cd 1234' was too long.
3177 * 3 => '1234 890 ', // 11 characters: Perfect split.
3178 * 4 => '123456789 ', // 10 characters: '123456789 1234567890a' was too long.
3179 * 5 => '1234567890a ', // 12 characters: Too long, but no inner whitespace on which to split.
3180 * 6 => ' 45678 ', // 11 characters: Perfect split.
3181 * 7 => '1 3 5 7 90 ', // 11 characters: End of $text.
3182 * );
3183 *
3184 * @since 3.4.0
3185 * @access private
3186 *
3187 * @param string $text The string to split.
3188 * @param int $goal The desired chunk length.
3189 * @return array Numeric array of chunks.
3190 */
3191function _split_str_by_whitespace( $text, $goal ) {
3192 $chunks = array();
3193
3194 $string_nullspace = strtr( $text, "\r\n\t\v\f ", "\000\000\000\000\000\000" );
3195
3196 while ( $goal < strlen( $string_nullspace ) ) {
3197 $pos = strrpos( substr( $string_nullspace, 0, $goal + 1 ), "\000" );
3198
3199 if ( false === $pos ) {
3200 $pos = strpos( $string_nullspace, "\000", $goal + 1 );
3201 if ( false === $pos ) {
3202 break;
3203 }
3204 }
3205
3206 $chunks[] = substr( $text, 0, $pos + 1 );
3207 $text = substr( $text, $pos + 1 );
3208 $string_nullspace = substr( $string_nullspace, $pos + 1 );
3209 }
3210
3211 if ( $text ) {
3212 $chunks[] = $text;
3213 }
3214
3215 return $chunks;
3216}
3217
3218/**
3219 * Callback to add a rel attribute to HTML A element.
3220 *
3221 * Will remove already existing string before adding to prevent invalidating (X)HTML.
3222 *
3223 * @since 5.3.0
3224 *
3225 * @param array $matches Single match.
3226 * @param string $rel The rel attribute to add.
3227 * @return string HTML A element with the added rel attribute.
3228 */
3229function wp_rel_callback( $matches, $rel ) {
3230 $text = $matches[1];
3231 $atts = wp_kses_hair( $matches[1], wp_allowed_protocols() );
3232
3233 if ( ! empty( $atts['href'] ) && wp_is_internal_link( $atts['href']['value'] ) ) {
3234 $rel = trim( str_replace( 'nofollow', '', $rel ) );
3235 }
3236
3237 if ( ! empty( $atts['rel'] ) ) {
3238 $parts = array_map( 'trim', explode( ' ', $atts['rel']['value'] ) );
3239 $rel_array = array_map( 'trim', explode( ' ', $rel ) );
3240 $parts = array_unique( array_merge( $parts, $rel_array ) );
3241 $rel = implode( ' ', $parts );
3242 unset( $atts['rel'] );
3243
3244 $html = '';
3245 foreach ( $atts as $name => $value ) {
3246 if ( isset( $value['vless'] ) && 'y' === $value['vless'] ) {
3247 $html .= $name . ' ';
3248 } else {
3249 $html .= "{$name}=\"" . esc_attr( $value['value'] ) . '" ';
3250 }
3251 }
3252 $text = trim( $html );
3253 }
3254
3255 $rel_attr = $rel ? ' rel="' . esc_attr( $rel ) . '"' : '';
3256
3257 return "<a {$text}{$rel_attr}>";
3258}
3259
3260/**
3261 * Adds `rel="nofollow"` string to all HTML A elements in content.
3262 *
3263 * @since 1.5.0
3264 *
3265 * @param string $text Content that may contain HTML A elements.
3266 * @return string Converted content.
3267 */
3268function wp_rel_nofollow( $text ) {
3269 // This is a pre-save filter, so text is already escaped.
3270 $text = stripslashes( $text );
3271 $text = preg_replace_callback(
3272 '|<a (.+?)>|i',
3273 static function ( $matches ) {
3274 return wp_rel_callback( $matches, 'nofollow' );
3275 },
3276 $text
3277 );
3278 return wp_slash( $text );
3279}
3280
3281/**
3282 * Callback to add `rel="nofollow"` string to HTML A element.
3283 *
3284 * @since 2.3.0
3285 * @deprecated 5.3.0 Use wp_rel_callback()
3286 *
3287 * @param array $matches Single match.
3288 * @return string HTML A Element with `rel="nofollow"`.
3289 */
3290function wp_rel_nofollow_callback( $matches ) {
3291 return wp_rel_callback( $matches, 'nofollow' );
3292}
3293
3294/**
3295 * Adds `rel="nofollow ugc"` string to all HTML A elements in content.
3296 *
3297 * @since 5.3.0
3298 *
3299 * @param string $text Content that may contain HTML A elements.
3300 * @return string Converted content.
3301 */
3302function wp_rel_ugc( $text ) {
3303 // This is a pre-save filter, so text is already escaped.
3304 $text = stripslashes( $text );
3305 $text = preg_replace_callback(
3306 '|<a (.+?)>|i',
3307 static function ( $matches ) {
3308 return wp_rel_callback( $matches, 'nofollow ugc' );
3309 },
3310 $text
3311 );
3312 return wp_slash( $text );
3313}
3314
3315/**
3316 * Adds `rel="noopener"` to all HTML A elements that have a target.
3317 *
3318 * @since 5.1.0
3319 * @since 5.6.0 Removed 'noreferrer' relationship.
3320 * @deprecated 6.7.0
3321 *
3322 * @param string $text Content that may contain HTML A elements.
3323 * @return string Converted content.
3324 */
3325function wp_targeted_link_rel( $text ) {
3326 _deprecated_function( __FUNCTION__, '6.7.0' );
3327
3328 // Don't run (more expensive) regex if no links with targets.
3329 if ( false === stripos( $text, 'target' ) || false === stripos( $text, '<a ' ) || is_serialized( $text ) ) {
3330 return $text;
3331 }
3332
3333 $script_and_style_regex = '/<(script|style).*?<\/\\1>/si';
3334
3335 preg_match_all( $script_and_style_regex, $text, $matches );
3336 $extra_parts = $matches[0];
3337 $html_parts = preg_split( $script_and_style_regex, $text );
3338
3339 foreach ( $html_parts as &$part ) {
3340 $part = preg_replace_callback( '|<a\s([^>]*target\s*=[^>]*)>|i', 'wp_targeted_link_rel_callback', $part );
3341 }
3342
3343 $text = '';
3344 for ( $i = 0; $i < count( $html_parts ); $i++ ) {
3345 $text .= $html_parts[ $i ];
3346 if ( isset( $extra_parts[ $i ] ) ) {
3347 $text .= $extra_parts[ $i ];
3348 }
3349 }
3350
3351 return $text;
3352}
3353
3354/**
3355 * Callback to add `rel="noopener"` string to HTML A element.
3356 *
3357 * Will not duplicate an existing 'noopener' value to avoid invalidating the HTML.
3358 *
3359 * @since 5.1.0
3360 * @since 5.6.0 Removed 'noreferrer' relationship.
3361 * @deprecated 6.7.0
3362 *
3363 * @param array $matches Single match.
3364 * @return string HTML A Element with `rel="noopener"` in addition to any existing values.
3365 */
3366function wp_targeted_link_rel_callback( $matches ) {
3367 _deprecated_function( __FUNCTION__, '6.7.0' );
3368
3369 $link_html = $matches[1];
3370 $original_link_html = $link_html;
3371
3372 // Consider the HTML escaped if there are no unescaped quotes.
3373 $is_escaped = ! preg_match( '/(^|[^\\\\])[\'"]/', $link_html );
3374 if ( $is_escaped ) {
3375 // Replace only the quotes so that they are parsable by wp_kses_hair(), leave the rest as is.
3376 $link_html = preg_replace( '/\\\\([\'"])/', '$1', $link_html );
3377 }
3378
3379 $atts = wp_kses_hair( $link_html, wp_allowed_protocols() );
3380
3381 /**
3382 * Filters the rel values that are added to links with `target` attribute.
3383 *
3384 * @since 5.1.0
3385 *
3386 * @param string $rel The rel values.
3387 * @param string $link_html The matched content of the link tag including all HTML attributes.
3388 */
3389 $rel = apply_filters( 'wp_targeted_link_rel', 'noopener', $link_html );
3390
3391 // Return early if no rel values to be added or if no actual target attribute.
3392 if ( ! $rel || ! isset( $atts['target'] ) ) {
3393 return "<a $original_link_html>";
3394 }
3395
3396 if ( isset( $atts['rel'] ) ) {
3397 $all_parts = preg_split( '/\s/', "{$atts['rel']['value']} $rel", -1, PREG_SPLIT_NO_EMPTY );
3398 $rel = implode( ' ', array_unique( $all_parts ) );
3399 }
3400
3401 $atts['rel']['whole'] = 'rel="' . esc_attr( $rel ) . '"';
3402 $link_html = implode( ' ', array_column( $atts, 'whole' ) );
3403
3404 if ( $is_escaped ) {
3405 $link_html = preg_replace( '/[\'"]/', '\\\\$0', $link_html );
3406 }
3407
3408 return "<a $link_html>";
3409}
3410
3411/**
3412 * Adds all filters modifying the rel attribute of targeted links.
3413 *
3414 * @since 5.1.0
3415 * @deprecated 6.7.0
3416 */
3417function wp_init_targeted_link_rel_filters() {
3418 _deprecated_function( __FUNCTION__, '6.7.0' );
3419}
3420
3421/**
3422 * Removes all filters modifying the rel attribute of targeted links.
3423 *
3424 * @since 5.1.0
3425 * @deprecated 6.7.0
3426 */
3427function wp_remove_targeted_link_rel_filters() {
3428 _deprecated_function( __FUNCTION__, '6.7.0' );
3429}
3430
3431/**
3432 * Converts one smiley code to the icon graphic file equivalent.
3433 *
3434 * Callback handler for convert_smilies().
3435 *
3436 * Looks up one smiley code in the $wpsmiliestrans global array and returns an
3437 * `<img>` string for that smiley.
3438 *
3439 * @since 2.8.0
3440 *
3441 * @global array $wpsmiliestrans
3442 *
3443 * @param array $matches Single match. Smiley code to convert to image.
3444 * @return string Image string for smiley.
3445 */
3446function translate_smiley( $matches ) {
3447 global $wpsmiliestrans;
3448
3449 if ( 0 === count( $matches ) ) {
3450 return '';
3451 }
3452
3453 $smiley = trim( reset( $matches ) );
3454 $img = $wpsmiliestrans[ $smiley ];
3455
3456 $matches = array();
3457 $ext = preg_match( '/\.([^.]+)$/', $img, $matches ) ? strtolower( $matches[1] ) : false;
3458 $image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'webp', 'avif' );
3459
3460 // Don't convert smilies that aren't images - they're probably emoji.
3461 if ( ! in_array( $ext, $image_exts, true ) ) {
3462 return $img;
3463 }
3464
3465 /**
3466 * Filters the Smiley image URL before it's used in the image element.
3467 *
3468 * @since 2.9.0
3469 *
3470 * @param string $smiley_url URL for the smiley image.
3471 * @param string $img Filename for the smiley image.
3472 * @param string $site_url Site URL, as returned by site_url().
3473 */
3474 $src_url = apply_filters( 'smilies_src', includes_url( "images/smilies/$img" ), $img, site_url() );
3475
3476 return sprintf( '<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', esc_url( $src_url ), esc_attr( $smiley ) );
3477}
3478
3479/**
3480 * Converts text equivalent of smilies to images.
3481 *
3482 * Will only convert smilies if the option 'use_smilies' is true and the global
3483 * used in the function isn't empty.
3484 *
3485 * @since 0.71
3486 *
3487 * @global string|array $wp_smiliessearch
3488 *
3489 * @param string $text Content to convert smilies from text.
3490 * @return string Converted content with text smilies replaced with images.
3491 */
3492function convert_smilies( $text ) {
3493 global $wp_smiliessearch;
3494
3495 if ( ! get_option( 'use_smilies' ) || empty( $wp_smiliessearch ) ) {
3496 // Return default text.
3497 return $text;
3498 }
3499
3500 // HTML loop taken from texturize function, could possible be consolidated.
3501 $textarr = preg_split( '/(<[^>]*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // Capture the tags as well as in between.
3502
3503 if ( false === $textarr ) {
3504 // Return default text.
3505 return $text;
3506 }
3507
3508 // Loop stuff.
3509 $stop = count( $textarr );
3510 $output = '';
3511
3512 // Ignore processing of specific tags.
3513 $tags_to_ignore = 'code|pre|style|script|textarea';
3514 $ignore_block_element = '';
3515
3516 for ( $i = 0; $i < $stop; $i++ ) {
3517 $content = $textarr[ $i ];
3518
3519 // If we're in an ignore block, wait until we find its closing tag.
3520 if ( '' === $ignore_block_element && preg_match( '/^<(' . $tags_to_ignore . ')[^>]*>/', $content, $matches ) ) {
3521 $ignore_block_element = $matches[1];
3522 }
3523
3524 // If it's not a tag and not in ignore block.
3525 if ( '' === $ignore_block_element && strlen( $content ) > 0 && '<' !== $content[0] ) {
3526 $content = preg_replace_callback( $wp_smiliessearch, 'translate_smiley', $content );
3527 }
3528
3529 // Did we exit ignore block?
3530 if ( '' !== $ignore_block_element && '</' . $ignore_block_element . '>' === $content ) {
3531 $ignore_block_element = '';
3532 }
3533
3534 $output .= $content;
3535 }
3536
3537 return $output;
3538}
3539
3540/**
3541 * Verifies that an email is valid.
3542 *
3543 * Does not grok i18n domains. Not RFC compliant.
3544 *
3545 * @since 0.71
3546 *
3547 * @param string $email Email address to verify.
3548 * @param bool $deprecated Deprecated.
3549 * @return string|false Valid email address on success, false on failure.
3550 */
3551function is_email( $email, $deprecated = false ) {
3552 if ( ! empty( $deprecated ) ) {
3553 _deprecated_argument( __FUNCTION__, '3.0.0' );
3554 }
3555
3556 // Test for the minimum length the email can be.
3557 if ( strlen( $email ) < 6 ) {
3558 /**
3559 * Filters whether an email address is valid.
3560 *
3561 * This filter is evaluated under several different contexts, such as 'email_too_short',
3562 * 'email_no_at', 'local_invalid_chars', 'domain_period_sequence', 'domain_period_limits',
3563 * 'domain_no_periods', 'sub_hyphen_limits', 'sub_invalid_chars', or no specific context.
3564 *
3565 * @since 2.8.0
3566 *
3567 * @param string|false $is_email The email address if successfully passed the is_email() checks, false otherwise.
3568 * @param string $email The email address being checked.
3569 * @param string $context Context under which the email was tested.
3570 */
3571 return apply_filters( 'is_email', false, $email, 'email_too_short' );
3572 }
3573
3574 // Test for an @ character after the first position.
3575 if ( false === strpos( $email, '@', 1 ) ) {
3576 /** This filter is documented in wp-includes/formatting.php */
3577 return apply_filters( 'is_email', false, $email, 'email_no_at' );
3578 }
3579
3580 // Split out the local and domain parts.
3581 list( $local, $domain ) = explode( '@', $email, 2 );
3582
3583 /*
3584 * LOCAL PART
3585 * Test for invalid characters.
3586 */
3587 if ( ! preg_match( '/^[a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]+$/', $local ) ) {
3588 /** This filter is documented in wp-includes/formatting.php */
3589 return apply_filters( 'is_email', false, $email, 'local_invalid_chars' );
3590 }
3591
3592 /*
3593 * DOMAIN PART
3594 * Test for sequences of periods.
3595 */
3596 if ( preg_match( '/\.{2,}/', $domain ) ) {
3597 /** This filter is documented in wp-includes/formatting.php */
3598 return apply_filters( 'is_email', false, $email, 'domain_period_sequence' );
3599 }
3600
3601 // Test for leading and trailing periods and whitespace.
3602 if ( trim( $domain, " \t\n\r\0\x0B." ) !== $domain ) {
3603 /** This filter is documented in wp-includes/formatting.php */
3604 return apply_filters( 'is_email', false, $email, 'domain_period_limits' );
3605 }
3606
3607 // Split the domain into subs.
3608 $subs = explode( '.', $domain );
3609
3610 // Assume the domain will have at least two subs.
3611 if ( 2 > count( $subs ) ) {
3612 /** This filter is documented in wp-includes/formatting.php */
3613 return apply_filters( 'is_email', false, $email, 'domain_no_periods' );
3614 }
3615
3616 // Loop through each sub.
3617 foreach ( $subs as $sub ) {
3618 // Test for leading and trailing hyphens and whitespace.
3619 if ( trim( $sub, " \t\n\r\0\x0B-" ) !== $sub ) {
3620 /** This filter is documented in wp-includes/formatting.php */
3621 return apply_filters( 'is_email', false, $email, 'sub_hyphen_limits' );
3622 }
3623
3624 // Test for invalid characters.
3625 if ( ! preg_match( '/^[a-z0-9-]+$/i', $sub ) ) {
3626 /** This filter is documented in wp-includes/formatting.php */
3627 return apply_filters( 'is_email', false, $email, 'sub_invalid_chars' );
3628 }
3629 }
3630
3631 // Congratulations, your email made it!
3632 /** This filter is documented in wp-includes/formatting.php */
3633 return apply_filters( 'is_email', $email, $email, null );
3634}
3635
3636/**
3637 * Converts to ASCII from email subjects.
3638 *
3639 * @since 1.2.0
3640 *
3641 * @param string $subject Subject line.
3642 * @return string Converted string to ASCII.
3643 */
3644function wp_iso_descrambler( $subject ) {
3645 /* this may only work with iso-8859-1, I'm afraid */
3646 if ( ! preg_match( '#\=\?(.+)\?Q\?(.+)\?\=#i', $subject, $matches ) ) {
3647 return $subject;
3648 }
3649
3650 $subject = str_replace( '_', ' ', $matches[2] );
3651 return preg_replace_callback( '#\=([0-9a-f]{2})#i', '_wp_iso_convert', $subject );
3652}
3653
3654/**
3655 * Helper function to convert hex encoded chars to ASCII.
3656 *
3657 * @since 3.1.0
3658 * @access private
3659 *
3660 * @param array $matches The preg_replace_callback matches array.
3661 * @return string Converted chars.
3662 */
3663function _wp_iso_convert( $matches ) {
3664 return chr( hexdec( strtolower( $matches[1] ) ) );
3665}
3666
3667/**
3668 * Given a date in the timezone of the site, returns that date in UTC.
3669 *
3670 * Requires and returns a date in the Y-m-d H:i:s format.
3671 * Return format can be overridden using the $format parameter.
3672 *
3673 * @since 1.2.0
3674 *
3675 * @param string $date_string The date to be converted, in the timezone of the site.
3676 * @param string $format The format string for the returned date. Default 'Y-m-d H:i:s'.
3677 * @return string Formatted version of the date, in UTC.
3678 */
3679function get_gmt_from_date( $date_string, $format = 'Y-m-d H:i:s' ) {
3680 $datetime = date_create( $date_string, wp_timezone() );
3681
3682 if ( false === $datetime ) {
3683 return gmdate( $format, 0 );
3684 }
3685
3686 return $datetime->setTimezone( new DateTimeZone( 'UTC' ) )->format( $format );
3687}
3688
3689/**
3690 * Given a date in UTC or GMT timezone, returns that date in the timezone of the site.
3691 *
3692 * Requires a date in the Y-m-d H:i:s format.
3693 * Default return format of 'Y-m-d H:i:s' can be overridden using the `$format` parameter.
3694 *
3695 * @since 1.2.0
3696 *
3697 * @param string $date_string The date to be converted, in UTC or GMT timezone.
3698 * @param string $format The format string for the returned date. Default 'Y-m-d H:i:s'.
3699 * @return string Formatted version of the date, in the site's timezone.
3700 */
3701function get_date_from_gmt( $date_string, $format = 'Y-m-d H:i:s' ) {
3702 $datetime = date_create( $date_string, new DateTimeZone( 'UTC' ) );
3703
3704 if ( false === $datetime ) {
3705 return gmdate( $format, 0 );
3706 }
3707
3708 return $datetime->setTimezone( wp_timezone() )->format( $format );
3709}
3710
3711/**
3712 * Given an ISO 8601 timezone, returns its UTC offset in seconds.
3713 *
3714 * @since 1.5.0
3715 *
3716 * @param string $timezone Either 'Z' for 0 offset or '±hhmm'.
3717 * @return int|float The offset in seconds.
3718 */
3719function iso8601_timezone_to_offset( $timezone ) {
3720 // $timezone is either 'Z' or '[+|-]hhmm'.
3721 if ( 'Z' === $timezone ) {
3722 $offset = 0;
3723 } else {
3724 $sign = ( str_starts_with( $timezone, '+' ) ) ? 1 : -1;
3725 $hours = (int) substr( $timezone, 1, 2 );
3726 $minutes = (int) substr( $timezone, 3, 4 ) / 60;
3727 $offset = $sign * HOUR_IN_SECONDS * ( $hours + $minutes );
3728 }
3729 return $offset;
3730}
3731
3732/**
3733 * Given an ISO 8601 (Ymd\TH:i:sO) date, returns a MySQL DateTime (Y-m-d H:i:s) format used by post_date[_gmt].
3734 *
3735 * @since 1.5.0
3736 *
3737 * @param string $date_string Date and time in ISO 8601 format {@link https://en.wikipedia.org/wiki/ISO_8601}.
3738 * @param string $timezone Optional. If set to 'gmt' returns the result in UTC. Default 'user'.
3739 * @return string|false The date and time in MySQL DateTime format - Y-m-d H:i:s, or false on failure.
3740 */
3741function iso8601_to_datetime( $date_string, $timezone = 'user' ) {
3742 $timezone = strtolower( $timezone );
3743 $wp_timezone = wp_timezone();
3744 $datetime = date_create( $date_string, $wp_timezone ); // Timezone is ignored if input has one.
3745
3746 if ( false === $datetime ) {
3747 return false;
3748 }
3749
3750 if ( 'gmt' === $timezone ) {
3751 return $datetime->setTimezone( new DateTimeZone( 'UTC' ) )->format( 'Y-m-d H:i:s' );
3752 }
3753
3754 if ( 'user' === $timezone ) {
3755 return $datetime->setTimezone( $wp_timezone )->format( 'Y-m-d H:i:s' );
3756 }
3757
3758 return false;
3759}
3760
3761/**
3762 * Strips out all characters that are not allowable in an email.
3763 *
3764 * @since 1.5.0
3765 *
3766 * @param string $email Email address to filter.
3767 * @return string Filtered email address.
3768 */
3769function sanitize_email( $email ) {
3770 // Test for the minimum length the email can be.
3771 if ( strlen( $email ) < 6 ) {
3772 /**
3773 * Filters a sanitized email address.
3774 *
3775 * This filter is evaluated under several contexts, including 'email_too_short',
3776 * 'email_no_at', 'local_invalid_chars', 'domain_period_sequence', 'domain_period_limits',
3777 * 'domain_no_periods', 'domain_no_valid_subs', or no context.
3778 *
3779 * @since 2.8.0
3780 *
3781 * @param string $sanitized_email The sanitized email address.
3782 * @param string $email The email address, as provided to sanitize_email().
3783 * @param string|null $message A message to pass to the user. null if email is sanitized.
3784 */
3785 return apply_filters( 'sanitize_email', '', $email, 'email_too_short' );
3786 }
3787
3788 // Test for an @ character after the first position.
3789 if ( false === strpos( $email, '@', 1 ) ) {
3790 /** This filter is documented in wp-includes/formatting.php */
3791 return apply_filters( 'sanitize_email', '', $email, 'email_no_at' );
3792 }
3793
3794 // Split out the local and domain parts.
3795 list( $local, $domain ) = explode( '@', $email, 2 );
3796
3797 /*
3798 * LOCAL PART
3799 * Test for invalid characters.
3800 */
3801 $local = preg_replace( '/[^a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]/', '', $local );
3802 if ( '' === $local ) {
3803 /** This filter is documented in wp-includes/formatting.php */
3804 return apply_filters( 'sanitize_email', '', $email, 'local_invalid_chars' );
3805 }
3806
3807 /*
3808 * DOMAIN PART
3809 * Test for sequences of periods.
3810 */
3811 $domain = preg_replace( '/\.{2,}/', '', $domain );
3812 if ( '' === $domain ) {
3813 /** This filter is documented in wp-includes/formatting.php */
3814 return apply_filters( 'sanitize_email', '', $email, 'domain_period_sequence' );
3815 }
3816
3817 // Test for leading and trailing periods and whitespace.
3818 $domain = trim( $domain, " \t\n\r\0\x0B." );
3819 if ( '' === $domain ) {
3820 /** This filter is documented in wp-includes/formatting.php */
3821 return apply_filters( 'sanitize_email', '', $email, 'domain_period_limits' );
3822 }
3823
3824 // Split the domain into subs.
3825 $subs = explode( '.', $domain );
3826
3827 // Assume the domain will have at least two subs.
3828 if ( 2 > count( $subs ) ) {
3829 /** This filter is documented in wp-includes/formatting.php */
3830 return apply_filters( 'sanitize_email', '', $email, 'domain_no_periods' );
3831 }
3832
3833 // Create an array that will contain valid subs.
3834 $new_subs = array();
3835
3836 // Loop through each sub.
3837 foreach ( $subs as $sub ) {
3838 // Test for leading and trailing hyphens.
3839 $sub = trim( $sub, " \t\n\r\0\x0B-" );
3840
3841 // Test for invalid characters.
3842 $sub = preg_replace( '/[^a-z0-9-]+/i', '', $sub );
3843
3844 // If there's anything left, add it to the valid subs.
3845 if ( '' !== $sub ) {
3846 $new_subs[] = $sub;
3847 }
3848 }
3849
3850 // If there aren't 2 or more valid subs.
3851 if ( 2 > count( $new_subs ) ) {
3852 /** This filter is documented in wp-includes/formatting.php */
3853 return apply_filters( 'sanitize_email', '', $email, 'domain_no_valid_subs' );
3854 }
3855
3856 // Join valid subs into the new domain.
3857 $domain = implode( '.', $new_subs );
3858
3859 // Put the email back together.
3860 $sanitized_email = $local . '@' . $domain;
3861
3862 // Congratulations, your email made it!
3863 /** This filter is documented in wp-includes/formatting.php */
3864 return apply_filters( 'sanitize_email', $sanitized_email, $email, null );
3865}
3866
3867/**
3868 * Determines the difference between two timestamps.
3869 *
3870 * The difference is returned in a human-readable format such as "1 hour",
3871 * "5 minutes", "2 days".
3872 *
3873 * @since 1.5.0
3874 * @since 5.3.0 Added support for showing a difference in seconds.
3875 *
3876 * @param int $from Unix timestamp from which the difference begins.
3877 * @param int $to Optional. Unix timestamp to end the time difference. Default becomes time() if not set.
3878 * @return string Human-readable time difference.
3879 */
3880function human_time_diff( $from, $to = 0 ) {
3881 if ( empty( $to ) ) {
3882 $to = time();
3883 }
3884
3885 $diff = (int) abs( $to - $from );
3886
3887 if ( $diff < MINUTE_IN_SECONDS ) {
3888 $secs = $diff;
3889 if ( $secs <= 1 ) {
3890 $secs = 1;
3891 }
3892 /* translators: Time difference between two dates, in seconds. %s: Number of seconds. */
3893 $since = sprintf( _n( '%s second', '%s seconds', $secs ), $secs );
3894 } elseif ( $diff < HOUR_IN_SECONDS && $diff >= MINUTE_IN_SECONDS ) {
3895 $mins = round( $diff / MINUTE_IN_SECONDS );
3896 if ( $mins <= 1 ) {
3897 $mins = 1;
3898 }
3899 /* translators: Time difference between two dates, in minutes. %s: Number of minutes. */
3900 $since = sprintf( _n( '%s minute', '%s minutes', $mins ), $mins );
3901 } elseif ( $diff < DAY_IN_SECONDS && $diff >= HOUR_IN_SECONDS ) {
3902 $hours = round( $diff / HOUR_IN_SECONDS );
3903 if ( $hours <= 1 ) {
3904 $hours = 1;
3905 }
3906 /* translators: Time difference between two dates, in hours. %s: Number of hours. */
3907 $since = sprintf( _n( '%s hour', '%s hours', $hours ), $hours );
3908 } elseif ( $diff < WEEK_IN_SECONDS && $diff >= DAY_IN_SECONDS ) {
3909 $days = round( $diff / DAY_IN_SECONDS );
3910 if ( $days <= 1 ) {
3911 $days = 1;
3912 }
3913 /* translators: Time difference between two dates, in days. %s: Number of days. */
3914 $since = sprintf( _n( '%s day', '%s days', $days ), $days );
3915 } elseif ( $diff < MONTH_IN_SECONDS && $diff >= WEEK_IN_SECONDS ) {
3916 $weeks = round( $diff / WEEK_IN_SECONDS );
3917 if ( $weeks <= 1 ) {
3918 $weeks = 1;
3919 }
3920 /* translators: Time difference between two dates, in weeks. %s: Number of weeks. */
3921 $since = sprintf( _n( '%s week', '%s weeks', $weeks ), $weeks );
3922 } elseif ( $diff < YEAR_IN_SECONDS && $diff >= MONTH_IN_SECONDS ) {
3923 $months = round( $diff / MONTH_IN_SECONDS );
3924 if ( $months <= 1 ) {
3925 $months = 1;
3926 }
3927 /* translators: Time difference between two dates, in months. %s: Number of months. */
3928 $since = sprintf( _n( '%s month', '%s months', $months ), $months );
3929 } elseif ( $diff >= YEAR_IN_SECONDS ) {
3930 $years = round( $diff / YEAR_IN_SECONDS );
3931 if ( $years <= 1 ) {
3932 $years = 1;
3933 }
3934 /* translators: Time difference between two dates, in years. %s: Number of years. */
3935 $since = sprintf( _n( '%s year', '%s years', $years ), $years );
3936 }
3937
3938 /**
3939 * Filters the human-readable difference between two timestamps.
3940 *
3941 * @since 4.0.0
3942 *
3943 * @param string $since The difference in human-readable text.
3944 * @param int $diff The difference in seconds.
3945 * @param int $from Unix timestamp from which the difference begins.
3946 * @param int $to Unix timestamp to end the time difference.
3947 */
3948 return apply_filters( 'human_time_diff', $since, $diff, $from, $to );
3949}
3950
3951/**
3952 * Generates an excerpt from the content, if needed.
3953 *
3954 * Returns a maximum of 55 words with an ellipsis appended if necessary.
3955 *
3956 * The 55-word limit can be modified by plugins/themes using the {@see 'excerpt_length'} filter
3957 * The ' […]' string can be modified by plugins/themes using the {@see 'excerpt_more'} filter
3958 *
3959 * @since 1.5.0
3960 * @since 5.2.0 Added the `$post` parameter.
3961 * @since 6.3.0 Removes footnotes markup from the excerpt content.
3962 *
3963 * @param string $text Optional. The excerpt. If set to empty, an excerpt is generated.
3964 * @param WP_Post|object|int $post Optional. WP_Post instance or Post ID/object. Default null.
3965 * @return string The excerpt.
3966 */
3967function wp_trim_excerpt( $text = '', $post = null ) {
3968 $raw_excerpt = $text;
3969
3970 if ( '' === trim( $text ) ) {
3971 $post = get_post( $post );
3972 $text = get_the_content( '', false, $post );
3973
3974 $text = strip_shortcodes( $text );
3975 $text = excerpt_remove_blocks( $text );
3976 $text = excerpt_remove_footnotes( $text );
3977
3978 /*
3979 * Temporarily unhook wp_filter_content_tags() since any tags
3980 * within the excerpt are stripped out. Modifying the tags here
3981 * is wasteful and can lead to bugs in the image counting logic.
3982 */
3983 $filter_image_removed = remove_filter( 'the_content', 'wp_filter_content_tags', 12 );
3984
3985 /*
3986 * Temporarily unhook do_blocks() since excerpt_remove_blocks( $text )
3987 * handles block rendering needed for excerpt.
3988 */
3989 $filter_block_removed = remove_filter( 'the_content', 'do_blocks', 9 );
3990
3991 /** This filter is documented in wp-includes/post-template.php */
3992 $text = apply_filters( 'the_content', $text );
3993 $text = str_replace( ']]>', ']]>', $text );
3994
3995 // Restore the original filter if removed.
3996 if ( $filter_block_removed ) {
3997 add_filter( 'the_content', 'do_blocks', 9 );
3998 }
3999
4000 /*
4001 * Only restore the filter callback if it was removed above. The logic
4002 * to unhook and restore only applies on the default priority of 10,
4003 * which is generally used for the filter callback in WordPress core.
4004 */
4005 if ( $filter_image_removed ) {
4006 add_filter( 'the_content', 'wp_filter_content_tags', 12 );
4007 }
4008
4009 /* translators: Maximum number of words used in a post excerpt. */
4010 $excerpt_length = (int) _x( '55', 'excerpt_length' );
4011
4012 /**
4013 * Filters the maximum number of words in a post excerpt.
4014 *
4015 * @since 2.7.0
4016 *
4017 * @param int $number The maximum number of words. Default 55.
4018 */
4019 $excerpt_length = (int) apply_filters( 'excerpt_length', $excerpt_length );
4020
4021 /**
4022 * Filters the string in the "more" link displayed after a trimmed excerpt.
4023 *
4024 * @since 2.9.0
4025 *
4026 * @param string $more_string The string shown within the more link.
4027 */
4028 $excerpt_more = apply_filters( 'excerpt_more', ' ' . '[…]' );
4029 $text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
4030
4031 }
4032
4033 /**
4034 * Filters the trimmed excerpt string.
4035 *
4036 * @since 2.8.0
4037 *
4038 * @param string $text The trimmed text.
4039 * @param string $raw_excerpt The text prior to trimming.
4040 */
4041 return apply_filters( 'wp_trim_excerpt', $text, $raw_excerpt );
4042}
4043
4044/**
4045 * Trims text to a certain number of words.
4046 *
4047 * This function is localized. For languages that count 'words' by the individual
4048 * character (such as East Asian languages), the $num_words argument will apply
4049 * to the number of individual characters.
4050 *
4051 * @since 3.3.0
4052 *
4053 * @param string $text Text to trim.
4054 * @param int $num_words Number of words. Default 55.
4055 * @param string $more Optional. What to append if $text needs to be trimmed. Default '…'.
4056 * @return string Trimmed text.
4057 */
4058function wp_trim_words( $text, $num_words = 55, $more = null ) {
4059 if ( null === $more ) {
4060 $more = __( '…' );
4061 }
4062
4063 $original_text = $text;
4064 $text = wp_strip_all_tags( $text );
4065 $num_words = (int) $num_words;
4066
4067 if ( str_starts_with( wp_get_word_count_type(), 'characters' ) && preg_match( '/^utf\-?8$/i', get_option( 'blog_charset' ) ) ) {
4068 $text = trim( preg_replace( "/[\n\r\t ]+/", ' ', $text ), ' ' );
4069 preg_match_all( '/./u', $text, $words_array );
4070 $words_array = array_slice( $words_array[0], 0, $num_words + 1 );
4071 $sep = '';
4072 } else {
4073 $words_array = preg_split( "/[\n\r\t ]+/", $text, $num_words + 1, PREG_SPLIT_NO_EMPTY );
4074 $sep = ' ';
4075 }
4076
4077 if ( count( $words_array ) > $num_words ) {
4078 array_pop( $words_array );
4079 $text = implode( $sep, $words_array );
4080 $text = $text . $more;
4081 } else {
4082 $text = implode( $sep, $words_array );
4083 }
4084
4085 /**
4086 * Filters the text content after words have been trimmed.
4087 *
4088 * @since 3.3.0
4089 *
4090 * @param string $text The trimmed text.
4091 * @param int $num_words The number of words to trim the text to. Default 55.
4092 * @param string $more An optional string to append to the end of the trimmed text, e.g. ….
4093 * @param string $original_text The text before it was trimmed.
4094 */
4095 return apply_filters( 'wp_trim_words', $text, $num_words, $more, $original_text );
4096}
4097
4098/**
4099 * Converts named entities into numbered entities.
4100 *
4101 * @since 1.5.1
4102 *
4103 * @param string $text The text within which entities will be converted.
4104 * @return string Text with converted entities.
4105 */
4106function ent2ncr( $text ) {
4107
4108 /**
4109 * Filters text before named entities are converted into numbered entities.
4110 *
4111 * A non-null string must be returned for the filter to be evaluated.
4112 *
4113 * @since 3.3.0
4114 *
4115 * @param string|null $converted_text The text to be converted. Default null.
4116 * @param string $text The text prior to entity conversion.
4117 */
4118 $filtered = apply_filters( 'pre_ent2ncr', null, $text );
4119 if ( null !== $filtered ) {
4120 return $filtered;
4121 }
4122
4123 $to_ncr = array(
4124 '"' => '"',
4125 '&' => '&',
4126 '<' => '<',
4127 '>' => '>',
4128 '|' => '|',
4129 ' ' => ' ',
4130 '¡' => '¡',
4131 '¢' => '¢',
4132 '£' => '£',
4133 '¤' => '¤',
4134 '¥' => '¥',
4135 '¦' => '¦',
4136 '&brkbar;' => '¦',
4137 '§' => '§',
4138 '¨' => '¨',
4139 '¨' => '¨',
4140 '©' => '©',
4141 'ª' => 'ª',
4142 '«' => '«',
4143 '¬' => '¬',
4144 '­' => '­',
4145 '®' => '®',
4146 '¯' => '¯',
4147 '&hibar;' => '¯',
4148 '°' => '°',
4149 '±' => '±',
4150 '²' => '²',
4151 '³' => '³',
4152 '´' => '´',
4153 'µ' => 'µ',
4154 '¶' => '¶',
4155 '·' => '·',
4156 '¸' => '¸',
4157 '¹' => '¹',
4158 'º' => 'º',
4159 '»' => '»',
4160 '¼' => '¼',
4161 '½' => '½',
4162 '¾' => '¾',
4163 '¿' => '¿',
4164 'À' => 'À',
4165 'Á' => 'Á',
4166 'Â' => 'Â',
4167 'Ã' => 'Ã',
4168 'Ä' => 'Ä',
4169 'Å' => 'Å',
4170 'Æ' => 'Æ',
4171 'Ç' => 'Ç',
4172 'È' => 'È',
4173 'É' => 'É',
4174 'Ê' => 'Ê',
4175 'Ë' => 'Ë',
4176 'Ì' => 'Ì',
4177 'Í' => 'Í',
4178 'Î' => 'Î',
4179 'Ï' => 'Ï',
4180 'Ð' => 'Ð',
4181 'Ñ' => 'Ñ',
4182 'Ò' => 'Ò',
4183 'Ó' => 'Ó',
4184 'Ô' => 'Ô',
4185 'Õ' => 'Õ',
4186 'Ö' => 'Ö',
4187 '×' => '×',
4188 'Ø' => 'Ø',
4189 'Ù' => 'Ù',
4190 'Ú' => 'Ú',
4191 'Û' => 'Û',
4192 'Ü' => 'Ü',
4193 'Ý' => 'Ý',
4194 'Þ' => 'Þ',
4195 'ß' => 'ß',
4196 'à' => 'à',
4197 'á' => 'á',
4198 'â' => 'â',
4199 'ã' => 'ã',
4200 'ä' => 'ä',
4201 'å' => 'å',
4202 'æ' => 'æ',
4203 'ç' => 'ç',
4204 'è' => 'è',
4205 'é' => 'é',
4206 'ê' => 'ê',
4207 'ë' => 'ë',
4208 'ì' => 'ì',
4209 'í' => 'í',
4210 'î' => 'î',
4211 'ï' => 'ï',
4212 'ð' => 'ð',
4213 'ñ' => 'ñ',
4214 'ò' => 'ò',
4215 'ó' => 'ó',
4216 'ô' => 'ô',
4217 'õ' => 'õ',
4218 'ö' => 'ö',
4219 '÷' => '÷',
4220 'ø' => 'ø',
4221 'ù' => 'ù',
4222 'ú' => 'ú',
4223 'û' => 'û',
4224 'ü' => 'ü',
4225 'ý' => 'ý',
4226 'þ' => 'þ',
4227 'ÿ' => 'ÿ',
4228 'Œ' => 'Œ',
4229 'œ' => 'œ',
4230 'Š' => 'Š',
4231 'š' => 'š',
4232 'Ÿ' => 'Ÿ',
4233 'ƒ' => 'ƒ',
4234 'ˆ' => 'ˆ',
4235 '˜' => '˜',
4236 'Α' => 'Α',
4237 'Β' => 'Β',
4238 'Γ' => 'Γ',
4239 'Δ' => 'Δ',
4240 'Ε' => 'Ε',
4241 'Ζ' => 'Ζ',
4242 'Η' => 'Η',
4243 'Θ' => 'Θ',
4244 'Ι' => 'Ι',
4245 'Κ' => 'Κ',
4246 'Λ' => 'Λ',
4247 'Μ' => 'Μ',
4248 'Ν' => 'Ν',
4249 'Ξ' => 'Ξ',
4250 'Ο' => 'Ο',
4251 'Π' => 'Π',
4252 'Ρ' => 'Ρ',
4253 'Σ' => 'Σ',
4254 'Τ' => 'Τ',
4255 'Υ' => 'Υ',
4256 'Φ' => 'Φ',
4257 'Χ' => 'Χ',
4258 'Ψ' => 'Ψ',
4259 'Ω' => 'Ω',
4260 'α' => 'α',
4261 'β' => 'β',
4262 'γ' => 'γ',
4263 'δ' => 'δ',
4264 'ε' => 'ε',
4265 'ζ' => 'ζ',
4266 'η' => 'η',
4267 'θ' => 'θ',
4268 'ι' => 'ι',
4269 'κ' => 'κ',
4270 'λ' => 'λ',
4271 'μ' => 'μ',
4272 'ν' => 'ν',
4273 'ξ' => 'ξ',
4274 'ο' => 'ο',
4275 'π' => 'π',
4276 'ρ' => 'ρ',
4277 'ς' => 'ς',
4278 'σ' => 'σ',
4279 'τ' => 'τ',
4280 'υ' => 'υ',
4281 'φ' => 'φ',
4282 'χ' => 'χ',
4283 'ψ' => 'ψ',
4284 'ω' => 'ω',
4285 'ϑ' => 'ϑ',
4286 'ϒ' => 'ϒ',
4287 'ϖ' => 'ϖ',
4288 ' ' => ' ',
4289 ' ' => ' ',
4290 ' ' => ' ',
4291 '‌' => '‌',
4292 '‍' => '‍',
4293 '‎' => '‎',
4294 '‏' => '‏',
4295 '–' => '–',
4296 '—' => '—',
4297 '‘' => '‘',
4298 '’' => '’',
4299 '‚' => '‚',
4300 '“' => '“',
4301 '”' => '”',
4302 '„' => '„',
4303 '†' => '†',
4304 '‡' => '‡',
4305 '•' => '•',
4306 '…' => '…',
4307 '‰' => '‰',
4308 '′' => '′',
4309 '″' => '″',
4310 '‹' => '‹',
4311 '›' => '›',
4312 '‾' => '‾',
4313 '⁄' => '⁄',
4314 '€' => '€',
4315 'ℑ' => 'ℑ',
4316 '℘' => '℘',
4317 'ℜ' => 'ℜ',
4318 '™' => '™',
4319 'ℵ' => 'ℵ',
4320 '↵' => '↵',
4321 '⇐' => '⇐',
4322 '⇑' => '⇑',
4323 '⇒' => '⇒',
4324 '⇓' => '⇓',
4325 '⇔' => '⇔',
4326 '∀' => '∀',
4327 '∂' => '∂',
4328 '∃' => '∃',
4329 '∅' => '∅',
4330 '∇' => '∇',
4331 '∈' => '∈',
4332 '∉' => '∉',
4333 '∋' => '∋',
4334 '∏' => '∏',
4335 '∑' => '∑',
4336 '−' => '−',
4337 '∗' => '∗',
4338 '√' => '√',
4339 '∝' => '∝',
4340 '∞' => '∞',
4341 '∠' => '∠',
4342 '∧' => '∧',
4343 '∨' => '∨',
4344 '∩' => '∩',
4345 '∪' => '∪',
4346 '∫' => '∫',
4347 '∴' => '∴',
4348 '∼' => '∼',
4349 '≅' => '≅',
4350 '≈' => '≈',
4351 '≠' => '≠',
4352 '≡' => '≡',
4353 '≤' => '≤',
4354 '≥' => '≥',
4355 '⊂' => '⊂',
4356 '⊃' => '⊃',
4357 '⊄' => '⊄',
4358 '⊆' => '⊆',
4359 '⊇' => '⊇',
4360 '⊕' => '⊕',
4361 '⊗' => '⊗',
4362 '⊥' => '⊥',
4363 '⋅' => '⋅',
4364 '⌈' => '⌈',
4365 '⌉' => '⌉',
4366 '⌊' => '⌊',
4367 '⌋' => '⌋',
4368 '⟨' => '〈',
4369 '⟩' => '〉',
4370 '←' => '←',
4371 '↑' => '↑',
4372 '→' => '→',
4373 '↓' => '↓',
4374 '↔' => '↔',
4375 '◊' => '◊',
4376 '♠' => '♠',
4377 '♣' => '♣',
4378 '♥' => '♥',
4379 '♦' => '♦',
4380 );
4381
4382 return str_replace( array_keys( $to_ncr ), array_values( $to_ncr ), $text );
4383}
4384
4385/**
4386 * Formats text for the editor.
4387 *
4388 * Generally the browsers treat everything inside a textarea as text, but
4389 * it is still a good idea to HTML entity encode `<`, `>` and `&` in the content.
4390 *
4391 * The filter {@see 'format_for_editor'} is applied here. If `$text` is empty the
4392 * filter will be applied to an empty string.
4393 *
4394 * @since 4.3.0
4395 *
4396 * @see _WP_Editors::editor()
4397 *
4398 * @param string $text The text to be formatted.
4399 * @param string $default_editor The default editor for the current user.
4400 * It is usually either 'html' or 'tinymce'.
4401 * @return string The formatted text after filter is applied.
4402 */
4403function format_for_editor( $text, $default_editor = null ) {
4404 if ( $text ) {
4405 $text = htmlspecialchars( $text, ENT_NOQUOTES, get_option( 'blog_charset' ) );
4406 }
4407
4408 /**
4409 * Filters the text after it is formatted for the editor.
4410 *
4411 * @since 4.3.0
4412 *
4413 * @param string $text The formatted text.
4414 * @param string $default_editor The default editor for the current user.
4415 * It is usually either 'html' or 'tinymce'.
4416 */
4417 return apply_filters( 'format_for_editor', $text, $default_editor );
4418}
4419
4420/**
4421 * Performs a deep string replace operation to ensure the values in $search are no longer present.
4422 *
4423 * Repeats the replacement operation until it no longer replaces anything to remove "nested" values
4424 * e.g. $subject = '%0%0%0DDD', $search ='%0D', $result ='' rather than the '%0%0DD' that
4425 * str_replace would return
4426 *
4427 * @since 2.8.1
4428 * @access private
4429 *
4430 * @param string|array $search The value being searched for, otherwise known as the needle.
4431 * An array may be used to designate multiple needles.
4432 * @param string $subject The string being searched and replaced on, otherwise known as the haystack.
4433 * @return string The string with the replaced values.
4434 */
4435function _deep_replace( $search, $subject ) {
4436 $subject = (string) $subject;
4437
4438 $count = 1;
4439 while ( $count ) {
4440 $subject = str_replace( $search, '', $subject, $count );
4441 }
4442
4443 return $subject;
4444}
4445
4446/**
4447 * Escapes data for use in a MySQL query.
4448 *
4449 * Usually you should prepare queries using wpdb::prepare().
4450 * Sometimes, spot-escaping is required or useful. One example
4451 * is preparing an array for use in an IN clause.
4452 *
4453 * NOTE: Since 4.8.3, '%' characters will be replaced with a placeholder string,
4454 * this prevents certain SQLi attacks from taking place. This change in behavior
4455 * may cause issues for code that expects the return value of esc_sql() to be usable
4456 * for other purposes.
4457 *
4458 * @since 2.8.0
4459 *
4460 * @global wpdb $wpdb WordPress database abstraction object.
4461 *
4462 * @param string|array $data Unescaped data.
4463 * @return string|array Escaped data, in the same type as supplied.
4464 */
4465function esc_sql( $data ) {
4466 global $wpdb;
4467 return $wpdb->_escape( $data );
4468}
4469
4470/**
4471 * Checks and cleans a URL.
4472 *
4473 * A number of characters are removed from the URL. If the URL is for displaying
4474 * (the default behavior) ampersands are also replaced. The {@see 'clean_url'} filter
4475 * is applied to the returned cleaned URL.
4476 *
4477 * @since 2.8.0
4478 * @since 6.9.0 Prepends `https://` to the URL if it does not already contain a scheme
4479 * and the first item in `$protocols` is 'https'.
4480 *
4481 * @param string $url The URL to be cleaned.
4482 * @param string[] $protocols Optional. An array of acceptable protocols.
4483 * Defaults to return value of wp_allowed_protocols().
4484 * @param string $_context Private. Use sanitize_url() for database usage.
4485 * @return string The cleaned URL after the {@see 'clean_url'} filter is applied.
4486 * An empty string is returned if `$url` specifies a protocol other than
4487 * those in `$protocols`, or if `$url` contains an empty string.
4488 */
4489function esc_url( $url, $protocols = null, $_context = 'display' ) {
4490 $original_url = $url;
4491
4492 if ( '' === $url ) {
4493 return $url;
4494 }
4495
4496 $url = str_replace( ' ', '%20', ltrim( $url ) );
4497 $url = preg_replace( '|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\[\]\\x80-\\xff]|i', '', $url );
4498
4499 if ( '' === $url ) {
4500 return $url;
4501 }
4502
4503 if ( 0 !== stripos( $url, 'mailto:' ) ) {
4504 $strip = array( '%0d', '%0a', '%0D', '%0A' );
4505 $url = _deep_replace( $strip, $url );
4506 }
4507
4508 $url = str_replace( ';//', '://', $url );
4509 /*
4510 * If the URL doesn't appear to contain a scheme, we presume
4511 * it needs http:// prepended (unless it's a relative link
4512 * starting with /, # or ?, or a PHP file). If the first item
4513 * in $protocols is 'https', then https:// is prepended.
4514 */
4515 if ( ! str_contains( $url, ':' ) && ! in_array( $url[0], array( '/', '#', '?' ), true ) &&
4516 ! preg_match( '/^[a-z0-9-]+?\.php/i', $url )
4517 ) {
4518 $scheme = ( is_array( $protocols ) && 'https' === array_first( $protocols ) ) ? 'https://' : 'http://';
4519 $url = $scheme . $url;
4520 }
4521
4522 // Replace ampersands and single quotes only when displaying.
4523 if ( 'display' === $_context ) {
4524 $url = wp_kses_normalize_entities( $url );
4525 $url = str_replace( '&', '&', $url );
4526 $url = str_replace( "'", ''', $url );
4527 }
4528
4529 if ( str_contains( $url, '[' ) || str_contains( $url, ']' ) ) {
4530
4531 $parsed = wp_parse_url( $url );
4532 $front = '';
4533
4534 if ( isset( $parsed['scheme'] ) ) {
4535 $front .= $parsed['scheme'] . '://';
4536 } elseif ( '/' === $url[0] ) {
4537 $front .= '//';
4538 }
4539
4540 if ( isset( $parsed['user'] ) ) {
4541 $front .= $parsed['user'];
4542 }
4543
4544 if ( isset( $parsed['pass'] ) ) {
4545 $front .= ':' . $parsed['pass'];
4546 }
4547
4548 if ( isset( $parsed['user'] ) || isset( $parsed['pass'] ) ) {
4549 $front .= '@';
4550 }
4551
4552 if ( isset( $parsed['host'] ) ) {
4553 $front .= $parsed['host'];
4554 }
4555
4556 if ( isset( $parsed['port'] ) ) {
4557 $front .= ':' . $parsed['port'];
4558 }
4559
4560 $end_dirty = str_replace( $front, '', $url );
4561 $end_clean = str_replace( array( '[', ']' ), array( '%5B', '%5D' ), $end_dirty );
4562 $url = str_replace( $end_dirty, $end_clean, $url );
4563
4564 }
4565
4566 if ( '/' === $url[0] ) {
4567 $good_protocol_url = $url;
4568 } else {
4569 if ( ! is_array( $protocols ) ) {
4570 $protocols = wp_allowed_protocols();
4571 }
4572 $good_protocol_url = wp_kses_bad_protocol( $url, $protocols );
4573 if ( strtolower( $good_protocol_url ) !== strtolower( $url ) ) {
4574 return '';
4575 }
4576 }
4577
4578 /**
4579 * Filters a string cleaned and escaped for output as a URL.
4580 *
4581 * @since 2.3.0
4582 *
4583 * @param string $good_protocol_url The cleaned URL to be returned.
4584 * @param string $original_url The URL prior to cleaning.
4585 * @param string $_context If 'display', replace ampersands and single quotes only.
4586 */
4587 return apply_filters( 'clean_url', $good_protocol_url, $original_url, $_context );
4588}
4589
4590/**
4591 * Sanitizes a URL for database or redirect usage.
4592 *
4593 * This function is an alias for sanitize_url().
4594 *
4595 * @since 2.8.0
4596 * @since 6.1.0 Turned into an alias for sanitize_url().
4597 * @since 6.9.0 Prepends `https://` to the URL if it does not already contain a scheme
4598 * and the first item in `$protocols` is 'https'.
4599 *
4600 * @see sanitize_url()
4601 *
4602 * @param string $url The URL to be cleaned.
4603 * @param string[] $protocols Optional. An array of acceptable protocols.
4604 * Defaults to return value of wp_allowed_protocols().
4605 * @return string The cleaned URL after sanitize_url() is run.
4606 */
4607function esc_url_raw( $url, $protocols = null ) {
4608 return sanitize_url( $url, $protocols );
4609}
4610
4611/**
4612 * Sanitizes a URL for database or redirect usage.
4613 *
4614 * @since 2.3.1
4615 * @since 2.8.0 Deprecated in favor of esc_url_raw().
4616 * @since 5.9.0 Restored (un-deprecated).
4617 * @since 6.9.0 Prepends `https://` to the URL if it does not already contain a scheme
4618 * and the first item in `$protocols` is 'https'.
4619 *
4620 * @see esc_url()
4621 *
4622 * @param string $url The URL to be cleaned.
4623 * @param string[] $protocols Optional. An array of acceptable protocols.
4624 * Defaults to return value of wp_allowed_protocols().
4625 * @return string The cleaned URL after esc_url() is run with the 'db' context.
4626 */
4627function sanitize_url( $url, $protocols = null ) {
4628 return esc_url( $url, $protocols, 'db' );
4629}
4630
4631/**
4632 * Converts entities, while preserving already-encoded entities.
4633 *
4634 * @link https://www.php.net/htmlentities Borrowed from the PHP Manual user notes.
4635 *
4636 * @since 1.2.2
4637 *
4638 * @param string $text The text to be converted.
4639 * @return string Converted text.
4640 */
4641function htmlentities2( $text ) {
4642 $translation_table = get_html_translation_table( HTML_ENTITIES, ENT_QUOTES );
4643
4644 $translation_table[ chr( 38 ) ] = '&';
4645
4646 return preg_replace( '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/', '&', strtr( $text, $translation_table ) );
4647}
4648
4649/**
4650 * Escapes single quotes, `"`, `<`, `>`, `&`, and fixes line endings.
4651 *
4652 * Escapes text strings for echoing in JS. It is intended to be used for inline JS
4653 * (in a tag attribute, for example `onclick="..."`). Note that the strings have to
4654 * be in single quotes. The {@see 'js_escape'} filter is also applied here.
4655 *
4656 * @since 2.8.0
4657 *
4658 * @param string $text The text to be escaped.
4659 * @return string Escaped text.
4660 */
4661function esc_js( $text ) {
4662 $safe_text = wp_check_invalid_utf8( $text );
4663 $safe_text = _wp_specialchars( $safe_text, ENT_COMPAT );
4664 $safe_text = preg_replace( '/&#(x)?0*(?(1)27|39);?/i', "'", stripslashes( $safe_text ) );
4665 $safe_text = str_replace( "\r", '', $safe_text );
4666 $safe_text = str_replace( "\n", '\\n', addslashes( $safe_text ) );
4667 /**
4668 * Filters a string cleaned and escaped for output in JavaScript.
4669 *
4670 * Text passed to esc_js() is stripped of invalid or special characters,
4671 * and properly slashed for output.
4672 *
4673 * @since 2.0.6
4674 *
4675 * @param string $safe_text The text after it has been escaped.
4676 * @param string $text The text prior to being escaped.
4677 */
4678 return apply_filters( 'js_escape', $safe_text, $text );
4679}
4680
4681/**
4682 * Escaping for HTML blocks.
4683 *
4684 * @since 2.8.0
4685 *
4686 * @param string $text
4687 * @return string
4688 */
4689function esc_html( $text ) {
4690 $safe_text = wp_check_invalid_utf8( $text );
4691 $safe_text = _wp_specialchars( $safe_text, ENT_QUOTES );
4692 /**
4693 * Filters a string cleaned and escaped for output in HTML.
4694 *
4695 * Text passed to esc_html() is stripped of invalid or special characters
4696 * before output.
4697 *
4698 * @since 2.8.0
4699 *
4700 * @param string $safe_text The text after it has been escaped.
4701 * @param string $text The text prior to being escaped.
4702 */
4703 return apply_filters( 'esc_html', $safe_text, $text );
4704}
4705
4706/**
4707 * Escaping for HTML attributes.
4708 *
4709 * @since 2.8.0
4710 *
4711 * @param string $text
4712 * @return string
4713 */
4714function esc_attr( $text ) {
4715 $safe_text = wp_check_invalid_utf8( $text );
4716 $safe_text = _wp_specialchars( $safe_text, ENT_QUOTES );
4717 /**
4718 * Filters a string cleaned and escaped for output in an HTML attribute.
4719 *
4720 * Text passed to esc_attr() is stripped of invalid or special characters
4721 * before output.
4722 *
4723 * @since 2.0.6
4724 *
4725 * @param string $safe_text The text after it has been escaped.
4726 * @param string $text The text prior to being escaped.
4727 */
4728 return apply_filters( 'attribute_escape', $safe_text, $text );
4729}
4730
4731/**
4732 * Escaping for textarea values.
4733 *
4734 * @since 3.1.0
4735 *
4736 * @param string $text
4737 * @return string
4738 */
4739function esc_textarea( $text ) {
4740 $safe_text = htmlspecialchars( $text, ENT_QUOTES, get_option( 'blog_charset' ) );
4741 /**
4742 * Filters a string cleaned and escaped for output in a textarea element.
4743 *
4744 * @since 3.1.0
4745 *
4746 * @param string $safe_text The text after it has been escaped.
4747 * @param string $text The text prior to being escaped.
4748 */
4749 return apply_filters( 'esc_textarea', $safe_text, $text );
4750}
4751
4752/**
4753 * Escaping for XML blocks.
4754 *
4755 * @since 5.5.0
4756 *
4757 * @param string $text Text to escape.
4758 * @return string Escaped text.
4759 */
4760function esc_xml( $text ) {
4761 $safe_text = wp_check_invalid_utf8( $text );
4762
4763 $cdata_regex = '\<\!\[CDATA\[.*?\]\]\>';
4764 $regex = <<<EOF
4765/
4766 (?=.*?{$cdata_regex}) # lookahead that will match anything followed by a CDATA Section
4767 (?<non_cdata_followed_by_cdata>(.*?)) # the "anything" matched by the lookahead
4768 (?<cdata>({$cdata_regex})) # the CDATA Section matched by the lookahead
4769
4770| # alternative
4771
4772 (?<non_cdata>(.*)) # non-CDATA Section
4773/sx
4774EOF;
4775
4776 $safe_text = (string) preg_replace_callback(
4777 $regex,
4778 static function ( $matches ) {
4779 if ( ! isset( $matches[0] ) ) {
4780 return '';
4781 }
4782
4783 if ( isset( $matches['non_cdata'] ) ) {
4784 // escape HTML entities in the non-CDATA Section.
4785 return _wp_specialchars( $matches['non_cdata'], ENT_XML1 );
4786 }
4787
4788 // Return the CDATA Section unchanged, escape HTML entities in the rest.
4789 return _wp_specialchars( $matches['non_cdata_followed_by_cdata'], ENT_XML1 ) . $matches['cdata'];
4790 },
4791 $safe_text
4792 );
4793
4794 /**
4795 * Filters a string cleaned and escaped for output in XML.
4796 *
4797 * Text passed to esc_xml() is stripped of invalid or special characters
4798 * before output. HTML named character references are converted to their
4799 * equivalent code points.
4800 *
4801 * @since 5.5.0
4802 *
4803 * @param string $safe_text The text after it has been escaped.
4804 * @param string $text The text prior to being escaped.
4805 */
4806 return apply_filters( 'esc_xml', $safe_text, $text );
4807}
4808
4809/**
4810 * Escapes an HTML tag name.
4811 *
4812 * @since 2.5.0
4813 * @since 6.5.5 Allow hyphens in tag names (i.e. custom elements).
4814 *
4815 * @param string $tag_name
4816 * @return string
4817 */
4818function tag_escape( $tag_name ) {
4819 $safe_tag = strtolower( preg_replace( '/[^a-zA-Z0-9-_:]/', '', $tag_name ) );
4820 /**
4821 * Filters a string cleaned and escaped for output as an HTML tag.
4822 *
4823 * @since 2.8.0
4824 *
4825 * @param string $safe_tag The tag name after it has been escaped.
4826 * @param string $tag_name The text before it was escaped.
4827 */
4828 return apply_filters( 'tag_escape', $safe_tag, $tag_name );
4829}
4830
4831/**
4832 * Converts full URL paths to absolute paths.
4833 *
4834 * Removes the http or https protocols and the domain. Keeps the path '/' at the
4835 * beginning, so it isn't a true relative link, but from the web root base.
4836 *
4837 * @since 2.1.0
4838 * @since 4.1.0 Support was added for relative URLs.
4839 *
4840 * @param string $link Full URL path.
4841 * @return string Absolute path.
4842 */
4843function wp_make_link_relative( $link ) {
4844 return preg_replace( '|^(https?:)?//[^/]+(/?.*)|i', '$2', $link );
4845}
4846
4847/**
4848 * Sanitizes various option values based on the nature of the option.
4849 *
4850 * This is basically a switch statement which will pass $value through a number
4851 * of functions depending on the $option.
4852 *
4853 * @since 2.0.5
4854 *
4855 * @global wpdb $wpdb WordPress database abstraction object.
4856 *
4857 * @param string $option The name of the option.
4858 * @param mixed $value The unsanitized value.
4859 * @return mixed Sanitized value.
4860 */
4861function sanitize_option( $option, $value ) {
4862 global $wpdb;
4863
4864 $original_value = $value;
4865 $error = null;
4866
4867 switch ( $option ) {
4868 case 'admin_email':
4869 case 'new_admin_email':
4870 $value = $wpdb->strip_invalid_text_for_column( $wpdb->options, 'option_value', $value );
4871 if ( is_wp_error( $value ) ) {
4872 $error = $value->get_error_message();
4873 } else {
4874 $value = sanitize_email( $value );
4875 if ( ! is_email( $value ) ) {
4876 $error = __( 'The email address entered did not appear to be a valid email address. Please enter a valid email address.' );
4877 }
4878 }
4879 break;
4880
4881 case 'thumbnail_size_w':
4882 case 'thumbnail_size_h':
4883 case 'medium_size_w':
4884 case 'medium_size_h':
4885 case 'medium_large_size_w':
4886 case 'medium_large_size_h':
4887 case 'large_size_w':
4888 case 'large_size_h':
4889 case 'mailserver_port':
4890 case 'comment_max_links':
4891 case 'page_on_front':
4892 case 'page_for_posts':
4893 case 'rss_excerpt_length':
4894 case 'default_category':
4895 case 'default_email_category':
4896 case 'default_link_category':
4897 case 'close_comments_days_old':
4898 case 'comments_per_page':
4899 case 'thread_comments_depth':
4900 case 'users_can_register':
4901 case 'start_of_week':
4902 case 'site_icon':
4903 case 'fileupload_maxk':
4904 $value = absint( $value );
4905 break;
4906
4907 case 'posts_per_page':
4908 case 'posts_per_rss':
4909 $value = (int) $value;
4910 if ( empty( $value ) ) {
4911 $value = 1;
4912 }
4913 if ( $value < -1 ) {
4914 $value = abs( $value );
4915 }
4916 break;
4917
4918 case 'default_ping_status':
4919 case 'default_comment_status':
4920 // Options that if not there have 0 value but need to be something like "closed".
4921 if ( '0' === (string) $value || '' === $value ) {
4922 $value = 'closed';
4923 }
4924 break;
4925
4926 case 'blogdescription':
4927 case 'blogname':
4928 $value = $wpdb->strip_invalid_text_for_column( $wpdb->options, 'option_value', $value );
4929 if ( $value !== $original_value ) {
4930 $value = $wpdb->strip_invalid_text_for_column( $wpdb->options, 'option_value', wp_encode_emoji( $original_value ) );
4931 }
4932
4933 if ( is_wp_error( $value ) ) {
4934 $error = $value->get_error_message();
4935 } else {
4936 $value = esc_html( $value );
4937 }
4938 break;
4939
4940 case 'blog_charset':
4941 if ( is_string( $value ) ) {
4942 $value = preg_replace( '/[^a-zA-Z0-9_-]/', '', $value ); // Strips slashes.
4943 } else {
4944 $value = '';
4945 }
4946 break;
4947
4948 case 'blog_public':
4949 // This is the value if the settings checkbox is not checked on POST. Don't rely on this.
4950 if ( null === $value ) {
4951 $value = 1;
4952 } else {
4953 $value = (int) $value;
4954 }
4955 break;
4956
4957 case 'date_format':
4958 case 'time_format':
4959 case 'mailserver_url':
4960 case 'mailserver_login':
4961 case 'mailserver_pass':
4962 case 'upload_path':
4963 $value = $wpdb->strip_invalid_text_for_column( $wpdb->options, 'option_value', $value );
4964 if ( is_wp_error( $value ) ) {
4965 $error = $value->get_error_message();
4966 } else {
4967 $value = strip_tags( $value );
4968 $value = wp_kses_data( $value );
4969 }
4970 break;
4971
4972 case 'ping_sites':
4973 $value = explode( "\n", $value );
4974 $value = array_filter( array_map( 'trim', $value ) );
4975 $value = array_filter( array_map( 'sanitize_url', $value ) );
4976 $value = implode( "\n", $value );
4977 break;
4978
4979 case 'gmt_offset':
4980 if ( is_numeric( $value ) ) {
4981 $value = preg_replace( '/[^0-9:.-]/', '', $value ); // Strips slashes.
4982 } else {
4983 $value = '';
4984 }
4985 break;
4986
4987 case 'siteurl':
4988 $value = $wpdb->strip_invalid_text_for_column( $wpdb->options, 'option_value', $value );
4989 if ( is_wp_error( $value ) ) {
4990 $error = $value->get_error_message();
4991 } else {
4992 if ( preg_match( '#http(s?)://(.+)#i', $value ) ) {
4993 $value = sanitize_url( $value );
4994 } else {
4995 $error = __( 'The WordPress address you entered did not appear to be a valid URL. Please enter a valid URL.' );
4996 }
4997 }
4998 break;
4999
5000 case 'home':
5001 $value = $wpdb->strip_invalid_text_for_column( $wpdb->options, 'option_value', $value );
5002 if ( is_wp_error( $value ) ) {
5003 $error = $value->get_error_message();
5004 } else {
5005 if ( preg_match( '#http(s?)://(.+)#i', $value ) ) {
5006 $value = sanitize_url( $value );
5007 } else {
5008 $error = __( 'The Site address you entered did not appear to be a valid URL. Please enter a valid URL.' );
5009 }
5010 }
5011 break;
5012
5013 case 'WPLANG':
5014 $allowed = get_available_languages();
5015 if ( ! is_multisite() && defined( 'WPLANG' ) && '' !== WPLANG && 'en_US' !== WPLANG ) {
5016 $allowed[] = WPLANG;
5017 }
5018 if ( ! in_array( $value, $allowed, true ) && ! empty( $value ) ) {
5019 $value = get_option( $option );
5020 }
5021 break;
5022
5023 case 'illegal_names':
5024 $value = $wpdb->strip_invalid_text_for_column( $wpdb->options, 'option_value', $value );
5025 if ( is_wp_error( $value ) ) {
5026 $error = $value->get_error_message();
5027 } else {
5028 if ( ! is_array( $value ) ) {
5029 $value = explode( ' ', $value );
5030 }
5031
5032 $value = array_values( array_filter( array_map( 'trim', $value ) ) );
5033
5034 if ( ! $value ) {
5035 $value = '';
5036 }
5037 }
5038 break;
5039
5040 case 'limited_email_domains':
5041 case 'banned_email_domains':
5042 $value = $wpdb->strip_invalid_text_for_column( $wpdb->options, 'option_value', $value );
5043 if ( is_wp_error( $value ) ) {
5044 $error = $value->get_error_message();
5045 } else {
5046 if ( ! is_array( $value ) ) {
5047 $value = explode( "\n", $value );
5048 }
5049
5050 $domains = array_values( array_filter( array_map( 'trim', $value ) ) );
5051 $value = array();
5052
5053 foreach ( $domains as $domain ) {
5054 if ( ! preg_match( '/(--|\.\.)/', $domain ) && preg_match( '|^([a-zA-Z0-9-\.])+$|', $domain ) ) {
5055 $value[] = $domain;
5056 }
5057 }
5058 if ( ! $value ) {
5059 $value = '';
5060 }
5061 }
5062 break;
5063
5064 case 'timezone_string':
5065 $allowed_zones = timezone_identifiers_list( DateTimeZone::ALL_WITH_BC );
5066 if ( ! in_array( $value, $allowed_zones, true ) && ! empty( $value ) ) {
5067 $error = __( 'The timezone you have entered is not valid. Please select a valid timezone.' );
5068 }
5069 break;
5070
5071 case 'permalink_structure':
5072 case 'category_base':
5073 case 'tag_base':
5074 $value = $wpdb->strip_invalid_text_for_column( $wpdb->options, 'option_value', $value );
5075 if ( is_wp_error( $value ) ) {
5076 $error = $value->get_error_message();
5077 } else {
5078 $value = sanitize_url( $value );
5079 $value = str_replace( 'http://', '', $value );
5080 }
5081
5082 if ( 'permalink_structure' === $option && null === $error
5083 && '' !== $value && ! preg_match( '/%[^\/%]+%/', $value )
5084 ) {
5085 $error = sprintf(
5086 /* translators: %s: Documentation URL. */
5087 __( 'A structure tag is required when using custom permalinks. <a href="%s">Learn more</a>' ),
5088 __( 'https://wordpress.org/documentation/article/customize-permalinks/#choosing-your-permalink-structure' )
5089 );
5090 }
5091 break;
5092
5093 case 'default_role':
5094 if ( ! get_role( $value ) && get_role( 'subscriber' ) ) {
5095 $value = 'subscriber';
5096 }
5097 break;
5098
5099 case 'moderation_keys':
5100 case 'disallowed_keys':
5101 $value = $wpdb->strip_invalid_text_for_column( $wpdb->options, 'option_value', $value );
5102 if ( is_wp_error( $value ) ) {
5103 $error = $value->get_error_message();
5104 } else {
5105 $value = explode( "\n", $value );
5106 $value = array_filter( array_map( 'trim', $value ) );
5107 $value = array_unique( $value );
5108 $value = implode( "\n", $value );
5109 }
5110 break;
5111 }
5112
5113 if ( null !== $error ) {
5114 if ( '' === $error && is_wp_error( $value ) ) {
5115 /* translators: 1: Option name, 2: Error code. */
5116 $error = sprintf( __( 'Could not sanitize the %1$s option. Error code: %2$s' ), $option, $value->get_error_code() );
5117 }
5118
5119 $value = get_option( $option );
5120 if ( function_exists( 'add_settings_error' ) ) {
5121 add_settings_error( $option, "invalid_{$option}", $error );
5122 }
5123 }
5124
5125 /**
5126 * Filters an option value following sanitization.
5127 *
5128 * @since 2.3.0
5129 * @since 4.3.0 Added the `$original_value` parameter.
5130 *
5131 * @param mixed $value The sanitized option value.
5132 * @param string $option The option name.
5133 * @param mixed $original_value The original value passed to the function.
5134 */
5135 return apply_filters( "sanitize_option_{$option}", $value, $option, $original_value );
5136}
5137
5138/**
5139 * Maps a function to all non-iterable elements of an array or an object.
5140 *
5141 * This is similar to `array_walk_recursive()` but acts upon objects too.
5142 *
5143 * @since 4.4.0
5144 *
5145 * @param mixed $value The array, object, or scalar.
5146 * @param callable $callback The function to map onto $value.
5147 * @return mixed The value with the callback applied to all non-arrays and non-objects inside it.
5148 */
5149function map_deep( $value, $callback ) {
5150 if ( is_array( $value ) ) {
5151 foreach ( $value as $index => $item ) {
5152 $value[ $index ] = map_deep( $item, $callback );
5153 }
5154 } elseif ( is_object( $value ) ) {
5155 $object_vars = get_object_vars( $value );
5156 foreach ( $object_vars as $property_name => $property_value ) {
5157 $value->$property_name = map_deep( $property_value, $callback );
5158 }
5159 } else {
5160 $value = call_user_func( $callback, $value );
5161 }
5162
5163 return $value;
5164}
5165
5166/**
5167 * Parses a string into variables to be stored in an array.
5168 *
5169 * @since 2.2.1
5170 *
5171 * @param string $input_string The string to be parsed.
5172 * @param array $result Variables will be stored in this array.
5173 */
5174function wp_parse_str( $input_string, &$result ) {
5175 parse_str( (string) $input_string, $result );
5176
5177 /**
5178 * Filters the array of variables derived from a parsed string.
5179 *
5180 * @since 2.2.1
5181 *
5182 * @param array $result The array populated with variables.
5183 */
5184 $result = apply_filters( 'wp_parse_str', $result );
5185}
5186
5187/**
5188 * Converts lone less than signs.
5189 *
5190 * KSES already converts lone greater than signs.
5191 *
5192 * @since 2.3.0
5193 *
5194 * @param string $content Text to be converted.
5195 * @return string Converted text.
5196 */
5197function wp_pre_kses_less_than( $content ) {
5198 return preg_replace_callback( '%<[^>]*?((?=<)|>|$)%', 'wp_pre_kses_less_than_callback', $content );
5199}
5200
5201/**
5202 * Callback function used by preg_replace.
5203 *
5204 * @since 2.3.0
5205 *
5206 * @param string[] $matches Populated by matches to preg_replace.
5207 * @return string The text returned after esc_html if needed.
5208 */
5209function wp_pre_kses_less_than_callback( $matches ) {
5210 if ( ! str_contains( $matches[0], '>' ) ) {
5211 return esc_html( $matches[0] );
5212 }
5213 return $matches[0];
5214}
5215
5216/**
5217 * Removes non-allowable HTML from parsed block attribute values when filtering
5218 * in the post context.
5219 *
5220 * @since 5.3.1
5221 *
5222 * @param string $content Content to be run through KSES.
5223 * @param array[]|string $allowed_html An array of allowed HTML elements
5224 * and attributes, or a context name
5225 * such as 'post'.
5226 * @param string[] $allowed_protocols Array of allowed URL protocols.
5227 * @return string Filtered text to run through KSES.
5228 */
5229function wp_pre_kses_block_attributes( $content, $allowed_html, $allowed_protocols ) {
5230 /*
5231 * `filter_block_content` is expected to call `wp_kses`. Temporarily remove
5232 * the filter to avoid recursion.
5233 */
5234 remove_filter( 'pre_kses', 'wp_pre_kses_block_attributes', 10 );
5235 $content = filter_block_content( $content, $allowed_html, $allowed_protocols );
5236 add_filter( 'pre_kses', 'wp_pre_kses_block_attributes', 10, 3 );
5237
5238 return $content;
5239}
5240
5241/**
5242 * WordPress' implementation of PHP sprintf() with filters.
5243 *
5244 * @since 2.5.0
5245 * @since 5.3.0 Formalized the existing and already documented `...$args` parameter
5246 * by adding it to the function signature.
5247 *
5248 * @link https://www.php.net/sprintf
5249 *
5250 * @param string $pattern The string which formatted args are inserted.
5251 * @param mixed ...$args Arguments to be formatted into the $pattern string.
5252 * @return string The formatted string.
5253 */
5254function wp_sprintf( $pattern, ...$args ) {
5255 $len = strlen( $pattern );
5256 $start = 0;
5257 $result = '';
5258 $arg_index = 0;
5259
5260 while ( $len > $start ) {
5261 // Last character: append and break.
5262 if ( strlen( $pattern ) - 1 === $start ) {
5263 $result .= substr( $pattern, -1 );
5264 break;
5265 }
5266
5267 // Literal %: append and continue.
5268 if ( '%%' === substr( $pattern, $start, 2 ) ) {
5269 $start += 2;
5270 $result .= '%';
5271 continue;
5272 }
5273
5274 // Get fragment before next %.
5275 $end = strpos( $pattern, '%', $start + 1 );
5276 if ( false === $end ) {
5277 $end = $len;
5278 }
5279 $fragment = substr( $pattern, $start, $end - $start );
5280
5281 // Fragment has a specifier.
5282 if ( '%' === $pattern[ $start ] ) {
5283 // Find numbered arguments or take the next one in order.
5284 if ( preg_match( '/^%(\d+)\$/', $fragment, $matches ) ) {
5285 $index = $matches[1] - 1; // 0-based array vs 1-based sprintf() arguments.
5286 $arg = isset( $args[ $index ] ) ? $args[ $index ] : '';
5287 $fragment = str_replace( "%{$matches[1]}$", '%', $fragment );
5288 } else {
5289 $arg = isset( $args[ $arg_index ] ) ? $args[ $arg_index ] : '';
5290 ++$arg_index;
5291 }
5292
5293 /**
5294 * Filters a fragment from the pattern passed to wp_sprintf().
5295 *
5296 * If the fragment is unchanged, then sprintf() will be run on the fragment.
5297 *
5298 * @since 2.5.0
5299 *
5300 * @param string $fragment A fragment from the pattern.
5301 * @param string $arg The argument.
5302 */
5303 $_fragment = apply_filters( 'wp_sprintf', $fragment, $arg );
5304
5305 if ( $_fragment !== $fragment ) {
5306 $fragment = $_fragment;
5307 } else {
5308 $fragment = sprintf( $fragment, (string) $arg );
5309 }
5310 }
5311
5312 // Append to result and move to next fragment.
5313 $result .= $fragment;
5314 $start = $end;
5315 }
5316
5317 return $result;
5318}
5319
5320/**
5321 * Localizes list items before the rest of the content.
5322 *
5323 * The '%l' must be at the first characters can then contain the rest of the
5324 * content. The list items will have ', ', ', and', and ' and ' added depending
5325 * on the amount of list items in the $args parameter.
5326 *
5327 * @since 2.5.0
5328 *
5329 * @param string $pattern Content containing '%l' at the beginning.
5330 * @param array $args List items to prepend to the content and replace '%l'.
5331 * @return string Localized list items and rest of the content.
5332 */
5333function wp_sprintf_l( $pattern, $args ) {
5334 // Not a match.
5335 if ( ! str_starts_with( $pattern, '%l' ) ) {
5336 return $pattern;
5337 }
5338
5339 // Nothing to work with.
5340 if ( empty( $args ) ) {
5341 return '';
5342 }
5343
5344 /**
5345 * Filters the translated delimiters used by wp_sprintf_l().
5346 * Placeholders (%s) are included to assist translators and then
5347 * removed before the array of strings reaches the filter.
5348 *
5349 * Please note: Ampersands and entities should be avoided here.
5350 *
5351 * @since 2.5.0
5352 *
5353 * @param array $delimiters An array of translated delimiters.
5354 */
5355 $l = apply_filters(
5356 'wp_sprintf_l',
5357 array(
5358 /* translators: Used to join items in a list with more than 2 items. */
5359 'between' => sprintf( __( '%1$s, %2$s' ), '', '' ),
5360 /* translators: Used to join last two items in a list with more than 2 times. */
5361 'between_last_two' => sprintf( __( '%1$s, and %2$s' ), '', '' ),
5362 /* translators: Used to join items in a list with only 2 items. */
5363 'between_only_two' => sprintf( __( '%1$s and %2$s' ), '', '' ),
5364 )
5365 );
5366
5367 $args = (array) $args;
5368 $result = array_shift( $args );
5369 if ( 1 === count( $args ) ) {
5370 $result .= $l['between_only_two'] . array_shift( $args );
5371 }
5372
5373 // Loop when more than two args.
5374 $i = count( $args );
5375 while ( $i ) {
5376 $arg = array_shift( $args );
5377 --$i;
5378 if ( 0 === $i ) {
5379 $result .= $l['between_last_two'] . $arg;
5380 } else {
5381 $result .= $l['between'] . $arg;
5382 }
5383 }
5384
5385 return $result . substr( $pattern, 2 );
5386}
5387
5388/**
5389 * Safely extracts not more than the first $count characters from HTML string.
5390 *
5391 * UTF-8, tags and entities safe prefix extraction. Entities inside will *NOT*
5392 * be counted as one character. For example & will be counted as 4, < as
5393 * 3, etc.
5394 *
5395 * @since 2.5.0
5396 *
5397 * @param string $str String to get the excerpt from.
5398 * @param int $count Maximum number of characters to take.
5399 * @param string $more Optional. What to append if $str needs to be trimmed. Defaults to empty string.
5400 * @return string The excerpt.
5401 */
5402function wp_html_excerpt( $str, $count, $more = null ) {
5403 if ( null === $more ) {
5404 $more = '';
5405 }
5406
5407 $str = wp_strip_all_tags( $str, true );
5408 $excerpt = mb_substr( $str, 0, $count );
5409
5410 // Remove part of an entity at the end.
5411 $excerpt = preg_replace( '/&[^;\s]{0,6}$/', '', $excerpt );
5412
5413 if ( $str !== $excerpt ) {
5414 $excerpt = trim( $excerpt ) . $more;
5415 }
5416
5417 return $excerpt;
5418}
5419
5420/**
5421 * Adds a base URL to relative links in passed content.
5422 *
5423 * By default, this function supports the 'src' and 'href' attributes.
5424 * However, this can be modified via the `$attrs` parameter.
5425 *
5426 * @since 2.7.0
5427 *
5428 * @global string $_links_add_base
5429 *
5430 * @param string $content String to search for links in.
5431 * @param string $base The base URL to prefix to links.
5432 * @param string[] $attrs The attributes which should be processed.
5433 * @return string The processed content.
5434 */
5435function links_add_base_url( $content, $base, $attrs = array( 'src', 'href' ) ) {
5436 global $_links_add_base;
5437 $_links_add_base = $base;
5438 $attrs = implode( '|', (array) $attrs );
5439 return preg_replace_callback( "!($attrs)=(['\"])(.+?)\\2!i", '_links_add_base', $content );
5440}
5441
5442/**
5443 * Callback to add a base URL to relative links in passed content.
5444 *
5445 * @since 2.7.0
5446 * @access private
5447 *
5448 * @global string $_links_add_base
5449 *
5450 * @param string $m The matched link.
5451 * @return string The processed link.
5452 */
5453function _links_add_base( $m ) {
5454 global $_links_add_base;
5455 // 1 = attribute name 2 = quotation mark 3 = URL.
5456 return $m[1] . '=' . $m[2] .
5457 ( preg_match( '#^(\w{1,20}):#', $m[3], $protocol ) && in_array( $protocol[1], wp_allowed_protocols(), true ) ?
5458 $m[3] :
5459 WP_Http::make_absolute_url( $m[3], $_links_add_base )
5460 )
5461 . $m[2];
5462}
5463
5464/**
5465 * Adds a target attribute to all links in passed content.
5466 *
5467 * By default, this function only applies to `<a>` tags.
5468 * However, this can be modified via the `$tags` parameter.
5469 *
5470 * *NOTE:* Any current target attribute will be stripped and replaced.
5471 *
5472 * @since 2.7.0
5473 *
5474 * @global string $_links_add_target
5475 *
5476 * @param string $content String to search for links in.
5477 * @param string $target The target to add to the links.
5478 * @param string[] $tags An array of tags to apply to.
5479 * @return string The processed content.
5480 */
5481function links_add_target( $content, $target = '_blank', $tags = array( 'a' ) ) {
5482 global $_links_add_target;
5483 $_links_add_target = $target;
5484 $tags = implode( '|', (array) $tags );
5485 return preg_replace_callback( "!<($tags)((\s[^>]*)?)>!i", '_links_add_target', $content );
5486}
5487
5488/**
5489 * Callback to add a target attribute to all links in passed content.
5490 *
5491 * @since 2.7.0
5492 * @access private
5493 *
5494 * @global string $_links_add_target
5495 *
5496 * @param string $m The matched link.
5497 * @return string The processed link.
5498 */
5499function _links_add_target( $m ) {
5500 global $_links_add_target;
5501 $tag = $m[1];
5502 $link = preg_replace( '|( target=([\'"])(.*?)\2)|i', '', $m[2] );
5503 return '<' . $tag . $link . ' target="' . esc_attr( $_links_add_target ) . '">';
5504}
5505
5506/**
5507 * Normalizes EOL characters and strips duplicate whitespace.
5508 *
5509 * @since 2.7.0
5510 *
5511 * @param string $str The string to normalize.
5512 * @return string The normalized string.
5513 */
5514function normalize_whitespace( $str ) {
5515 $str = trim( $str );
5516 $str = str_replace( "\r", "\n", $str );
5517 $str = preg_replace( array( '/\n+/', '/[ \t]+/' ), array( "\n", ' ' ), $str );
5518 return $str;
5519}
5520
5521/**
5522 * Properly strips all HTML tags including 'script' and 'style'.
5523 *
5524 * This differs from strip_tags() because it removes the contents of
5525 * the `<script>` and `<style>` tags. E.g. `strip_tags( '<script>something</script>' )`
5526 * will return 'something'. wp_strip_all_tags() will return an empty string.
5527 *
5528 * @since 2.9.0
5529 *
5530 * @param string $text String containing HTML tags
5531 * @param bool $remove_breaks Optional. Whether to remove left over line breaks and white space chars
5532 * @return string The processed string.
5533 */
5534function wp_strip_all_tags( $text, $remove_breaks = false ) {
5535 if ( is_null( $text ) ) {
5536 return '';
5537 }
5538
5539 if ( ! is_scalar( $text ) ) {
5540 /*
5541 * To maintain consistency with pre-PHP 8 error levels,
5542 * wp_trigger_error() is used to trigger an E_USER_WARNING,
5543 * rather than _doing_it_wrong(), which triggers an E_USER_NOTICE.
5544 */
5545 wp_trigger_error(
5546 '',
5547 sprintf(
5548 /* translators: 1: The function name, 2: The argument number, 3: The argument name, 4: The expected type, 5: The provided type. */
5549 __( 'Warning: %1$s expects parameter %2$s (%3$s) to be a %4$s, %5$s given.' ),
5550 __FUNCTION__,
5551 '#1',
5552 '$text',
5553 'string',
5554 gettype( $text )
5555 ),
5556 E_USER_WARNING
5557 );
5558
5559 return '';
5560 }
5561
5562 $text = preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $text );
5563 $text = strip_tags( $text );
5564
5565 if ( $remove_breaks ) {
5566 $text = preg_replace( '/[\r\n\t ]+/', ' ', $text );
5567 }
5568
5569 return trim( $text );
5570}
5571
5572/**
5573 * Sanitizes a string from user input or from the database.
5574 *
5575 * - Checks for invalid UTF-8,
5576 * - Converts single `<` characters to entities
5577 * - Strips all tags
5578 * - Removes line breaks, tabs, and extra whitespace
5579 * - Strips percent-encoded characters
5580 *
5581 * @since 2.9.0
5582 *
5583 * @see sanitize_textarea_field()
5584 * @see wp_check_invalid_utf8()
5585 * @see wp_strip_all_tags()
5586 *
5587 * @param string $str String to sanitize.
5588 * @return string Sanitized string.
5589 */
5590function sanitize_text_field( $str ) {
5591 $filtered = _sanitize_text_fields( $str, false );
5592
5593 /**
5594 * Filters a sanitized text field string.
5595 *
5596 * @since 2.9.0
5597 *
5598 * @param string $filtered The sanitized string.
5599 * @param string $str The string prior to being sanitized.
5600 */
5601 return apply_filters( 'sanitize_text_field', $filtered, $str );
5602}
5603
5604/**
5605 * Sanitizes a multiline string from user input or from the database.
5606 *
5607 * The function is like sanitize_text_field(), but preserves
5608 * new lines (\n) and other whitespace, which are legitimate
5609 * input in textarea elements.
5610 *
5611 * @see sanitize_text_field()
5612 *
5613 * @since 4.7.0
5614 *
5615 * @param string $str String to sanitize.
5616 * @return string Sanitized string.
5617 */
5618function sanitize_textarea_field( $str ) {
5619 $filtered = _sanitize_text_fields( $str, true );
5620
5621 /**
5622 * Filters a sanitized textarea field string.
5623 *
5624 * @since 4.7.0
5625 *
5626 * @param string $filtered The sanitized string.
5627 * @param string $str The string prior to being sanitized.
5628 */
5629 return apply_filters( 'sanitize_textarea_field', $filtered, $str );
5630}
5631
5632/**
5633 * Internal helper function to sanitize a string from user input or from the database.
5634 *
5635 * @since 4.7.0
5636 * @access private
5637 *
5638 * @param string $str String to sanitize.
5639 * @param bool $keep_newlines Optional. Whether to keep newlines. Default: false.
5640 * @return string Sanitized string.
5641 */
5642function _sanitize_text_fields( $str, $keep_newlines = false ) {
5643 if ( is_object( $str ) || is_array( $str ) ) {
5644 return '';
5645 }
5646
5647 $str = (string) $str;
5648
5649 $filtered = wp_check_invalid_utf8( $str );
5650
5651 if ( str_contains( $filtered, '<' ) ) {
5652 $filtered = wp_pre_kses_less_than( $filtered );
5653 // This will strip extra whitespace for us.
5654 $filtered = wp_strip_all_tags( $filtered, false );
5655
5656 /*
5657 * Use HTML entities in a special case to make sure that
5658 * later newline stripping stages cannot lead to a functional tag.
5659 */
5660 $filtered = str_replace( "<\n", "<\n", $filtered );
5661 }
5662
5663 if ( ! $keep_newlines ) {
5664 $filtered = preg_replace( '/[\r\n\t ]+/', ' ', $filtered );
5665 }
5666 $filtered = trim( $filtered );
5667
5668 // Remove percent-encoded characters.
5669 $found = false;
5670 while ( preg_match( '/%[a-f0-9]{2}/i', $filtered, $match ) ) {
5671 $filtered = str_replace( $match[0], '', $filtered );
5672 $found = true;
5673 }
5674
5675 if ( $found ) {
5676 // Strip out the whitespace that may now exist after removing percent-encoded characters.
5677 $filtered = trim( preg_replace( '/ +/', ' ', $filtered ) );
5678 }
5679
5680 return $filtered;
5681}
5682
5683/**
5684 * i18n-friendly version of basename().
5685 *
5686 * @since 3.1.0
5687 *
5688 * @param string $path A path.
5689 * @param string $suffix If the filename ends in suffix this will also be cut off.
5690 * @return string
5691 */
5692function wp_basename( $path, $suffix = '' ) {
5693 return urldecode( basename( str_replace( array( '%2F', '%5C' ), '/', urlencode( $path ) ), $suffix ) );
5694}
5695
5696// phpcs:disable WordPress.WP.CapitalPDangit.MisspelledInComment,WordPress.WP.CapitalPDangit.MisspelledInText,WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid -- 8-)
5697/**
5698 * Forever eliminate "Wordpress" from the planet (or at least the little bit we can influence).
5699 *
5700 * Violating our coding standards for a good function name.
5701 *
5702 * @since 3.0.0
5703 *
5704 * @param string $text The text to be modified.
5705 * @return string The modified text.
5706 */
5707function capital_P_dangit( $text ) {
5708 // Simple replacement for titles.
5709 $current_filter = current_filter();
5710 if ( 'the_title' === $current_filter || 'wp_title' === $current_filter ) {
5711 return str_replace( 'Wordpress', 'WordPress', $text );
5712 }
5713 // Still here? Use the more judicious replacement.
5714 static $dblq = false;
5715 if ( false === $dblq ) {
5716 $dblq = _x( '“', 'opening curly double quote' );
5717 }
5718 return str_replace(
5719 array( ' Wordpress', '‘Wordpress', $dblq . 'Wordpress', '>Wordpress', '(Wordpress' ),
5720 array( ' WordPress', '‘WordPress', $dblq . 'WordPress', '>WordPress', '(WordPress' ),
5721 $text
5722 );
5723}
5724// phpcs:enable
5725
5726/**
5727 * Sanitizes a mime type
5728 *
5729 * @since 3.1.3
5730 *
5731 * @param string $mime_type Mime type.
5732 * @return string Sanitized mime type.
5733 */
5734function sanitize_mime_type( $mime_type ) {
5735 $sani_mime_type = preg_replace( '/[^-+*.a-zA-Z0-9\/]/', '', $mime_type );
5736 /**
5737 * Filters a mime type following sanitization.
5738 *
5739 * @since 3.1.3
5740 *
5741 * @param string $sani_mime_type The sanitized mime type.
5742 * @param string $mime_type The mime type prior to sanitization.
5743 */
5744 return apply_filters( 'sanitize_mime_type', $sani_mime_type, $mime_type );
5745}
5746
5747/**
5748 * Sanitizes space or carriage return separated URLs that are used to send trackbacks.
5749 *
5750 * @since 3.4.0
5751 *
5752 * @param string $to_ping Space or carriage return separated URLs
5753 * @return string URLs starting with the http or https protocol, separated by a carriage return.
5754 */
5755function sanitize_trackback_urls( $to_ping ) {
5756 $urls_to_ping = preg_split( '/[\r\n\t ]/', trim( $to_ping ), -1, PREG_SPLIT_NO_EMPTY );
5757 foreach ( $urls_to_ping as $k => $url ) {
5758 if ( ! preg_match( '#^https?://.#i', $url ) ) {
5759 unset( $urls_to_ping[ $k ] );
5760 }
5761 }
5762 $urls_to_ping = array_map( 'sanitize_url', $urls_to_ping );
5763 $urls_to_ping = implode( "\n", $urls_to_ping );
5764 /**
5765 * Filters a list of trackback URLs following sanitization.
5766 *
5767 * The string returned here consists of a space or carriage return-delimited list
5768 * of trackback URLs.
5769 *
5770 * @since 3.4.0
5771 *
5772 * @param string $urls_to_ping Sanitized space or carriage return separated URLs.
5773 * @param string $to_ping Space or carriage return separated URLs before sanitization.
5774 */
5775 return apply_filters( 'sanitize_trackback_urls', $urls_to_ping, $to_ping );
5776}
5777
5778/**
5779 * Adds slashes to a string or recursively adds slashes to strings within an array.
5780 *
5781 * This should be used when preparing data for core API that expects slashed data.
5782 * This should not be used to escape data going directly into an SQL query.
5783 *
5784 * @since 3.6.0
5785 * @since 5.5.0 Non-string values are left untouched.
5786 *
5787 * @param string|array $value String or array of data to slash.
5788 * @return string|array Slashed `$value`, in the same type as supplied.
5789 */
5790function wp_slash( $value ) {
5791 if ( is_array( $value ) ) {
5792 return array_map( 'wp_slash', $value );
5793 }
5794
5795 if ( is_string( $value ) ) {
5796 return addslashes( $value );
5797 }
5798
5799 return $value;
5800}
5801
5802/**
5803 * Removes slashes from a string or recursively removes slashes from strings within an array.
5804 *
5805 * This should be used to remove slashes from data passed to core API that
5806 * expects data to be unslashed.
5807 *
5808 * @since 3.6.0
5809 *
5810 * @param string|array $value String or array of data to unslash.
5811 * @return string|array Unslashed `$value`, in the same type as supplied.
5812 */
5813function wp_unslash( $value ) {
5814 return stripslashes_deep( $value );
5815}
5816
5817/**
5818 * Extracts and returns the first URL from passed content.
5819 *
5820 * @since 3.6.0
5821 *
5822 * @param string $content A string which might contain an `A` element with a non-empty `href` attribute.
5823 * @return string|false Database-escaped URL via {@see esc_url()} if found, otherwise `false`.
5824 */
5825function get_url_in_content( $content ) {
5826 if ( empty( $content ) ) {
5827 return false;
5828 }
5829
5830 $processor = new WP_HTML_Tag_Processor( $content );
5831 while ( $processor->next_tag( 'A' ) ) {
5832 $href = $processor->get_attribute( 'href' );
5833 if ( is_string( $href ) && '' !== $href ) {
5834 return sanitize_url( $href );
5835 }
5836 }
5837
5838 return false;
5839}
5840
5841/**
5842 * Returns the regexp for common whitespace characters.
5843 *
5844 * By default, spaces include new lines, tabs, nbsp entities, and the UTF-8 nbsp.
5845 * This is designed to replace the PCRE \s sequence. In ticket #22692, that
5846 * sequence was found to be unreliable due to random inclusion of the A0 byte.
5847 *
5848 * @since 4.0.0
5849 *
5850 * @return string The spaces regexp.
5851 */
5852function wp_spaces_regexp() {
5853 static $spaces = '';
5854
5855 if ( empty( $spaces ) ) {
5856 /**
5857 * Filters the regexp for common whitespace characters.
5858 *
5859 * This string is substituted for the \s sequence as needed in regular
5860 * expressions. For websites not written in English, different characters
5861 * may represent whitespace. For websites not encoded in UTF-8, the 0xC2 0xA0
5862 * sequence may not be in use.
5863 *
5864 * @since 4.0.0
5865 *
5866 * @param string $spaces Regexp pattern for matching common whitespace characters.
5867 */
5868 $spaces = apply_filters( 'wp_spaces_regexp', '[\r\n\t ]|\xC2\xA0| ' );
5869 }
5870
5871 return $spaces;
5872}
5873
5874/**
5875 * Enqueues the important emoji-related styles.
5876 *
5877 * @since 6.4.0
5878 */
5879function wp_enqueue_emoji_styles() {
5880 // Back-compat for plugins that disable functionality by unhooking this action.
5881 $action = is_admin() ? 'admin_print_styles' : 'wp_print_styles';
5882 if ( ! has_action( $action, 'print_emoji_styles' ) ) {
5883 return;
5884 }
5885 remove_action( $action, 'print_emoji_styles' );
5886
5887 $emoji_styles = '
5888 img.wp-smiley, img.emoji {
5889 display: inline !important;
5890 border: none !important;
5891 box-shadow: none !important;
5892 height: 1em !important;
5893 width: 1em !important;
5894 margin: 0 0.07em !important;
5895 vertical-align: -0.1em !important;
5896 background: none !important;
5897 padding: 0 !important;
5898 }';
5899 $handle = 'wp-emoji-styles';
5900 wp_register_style( $handle, false );
5901 wp_add_inline_style( $handle, $emoji_styles );
5902 wp_enqueue_style( $handle );
5903}
5904
5905/**
5906 * Prints the inline Emoji detection script if it is not already printed.
5907 *
5908 * @since 4.2.0
5909 */
5910function print_emoji_detection_script() {
5911 static $printed = false;
5912
5913 if ( $printed ) {
5914 return;
5915 }
5916
5917 $printed = true;
5918
5919 if ( did_action( 'wp_print_footer_scripts' ) ) {
5920 _print_emoji_detection_script();
5921 } else {
5922 add_action( 'wp_print_footer_scripts', '_print_emoji_detection_script' );
5923 }
5924}
5925
5926/**
5927 * Prints inline Emoji detection script.
5928 *
5929 * @ignore
5930 * @since 4.6.0
5931 * @access private
5932 */
5933function _print_emoji_detection_script() {
5934 $settings = array(
5935 /**
5936 * Filters the URL where emoji png images are hosted.
5937 *
5938 * @since 4.2.0
5939 *
5940 * @param string $url The emoji base URL for png images.
5941 */
5942 'baseUrl' => apply_filters( 'emoji_url', 'https://s.w.org/images/core/emoji/17.0.2/72x72/' ),
5943
5944 /**
5945 * Filters the extension of the emoji png files.
5946 *
5947 * @since 4.2.0
5948 *
5949 * @param string $extension The emoji extension for png files. Default .png.
5950 */
5951 'ext' => apply_filters( 'emoji_ext', '.png' ),
5952
5953 /**
5954 * Filters the URL where emoji SVG images are hosted.
5955 *
5956 * @since 4.6.0
5957 *
5958 * @param string $url The emoji base URL for svg images.
5959 */
5960 'svgUrl' => apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/17.0.2/svg/' ),
5961
5962 /**
5963 * Filters the extension of the emoji SVG files.
5964 *
5965 * @since 4.6.0
5966 *
5967 * @param string $extension The emoji extension for svg files. Default .svg.
5968 */
5969 'svgExt' => apply_filters( 'emoji_svg_ext', '.svg' ),
5970 );
5971
5972 $version = 'ver=' . get_bloginfo( 'version' );
5973
5974 if ( SCRIPT_DEBUG ) {
5975 $settings['source'] = array(
5976 /** This filter is documented in wp-includes/class-wp-scripts.php */
5977 'wpemoji' => apply_filters( 'script_loader_src', includes_url( "js/wp-emoji.js?$version" ), 'wpemoji' ),
5978 /** This filter is documented in wp-includes/class-wp-scripts.php */
5979 'twemoji' => apply_filters( 'script_loader_src', includes_url( "js/twemoji.js?$version" ), 'twemoji' ),
5980 );
5981 } else {
5982 $settings['source'] = array(
5983 /** This filter is documented in wp-includes/class-wp-scripts.php */
5984 'concatemoji' => apply_filters( 'script_loader_src', includes_url( "js/wp-emoji-release.min.js?$version" ), 'concatemoji' ),
5985 );
5986 }
5987
5988 wp_print_inline_script_tag(
5989 wp_json_encode( $settings, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
5990 array(
5991 'id' => 'wp-emoji-settings',
5992 'type' => 'application/json',
5993 )
5994 );
5995
5996 $emoji_loader_script_path = '/js/wp-emoji-loader' . wp_scripts_get_suffix() . '.js';
5997 wp_print_inline_script_tag(
5998 rtrim( file_get_contents( ABSPATH . WPINC . $emoji_loader_script_path ) ) . "\n" .
5999 '//# sourceURL=' . esc_url_raw( includes_url( $emoji_loader_script_path ) ),
6000 array(
6001 'type' => 'module',
6002 )
6003 );
6004}
6005
6006/**
6007 * Converts emoji characters to their equivalent HTML entity.
6008 *
6009 * This allows us to store emoji in a DB using the utf8 character set.
6010 *
6011 * @since 4.2.0
6012 *
6013 * @param string $content The content to encode.
6014 * @return string The encoded content.
6015 */
6016function wp_encode_emoji( $content ) {
6017 $emoji = _wp_emoji_list( 'partials' );
6018
6019 foreach ( $emoji as $emojum ) {
6020 $emoji_char = html_entity_decode( $emojum );
6021 if ( str_contains( $content, $emoji_char ) ) {
6022 $content = preg_replace( "/$emoji_char/", $emojum, $content );
6023 }
6024 }
6025
6026 return $content;
6027}
6028
6029/**
6030 * Converts emoji to a static img element.
6031 *
6032 * @since 4.2.0
6033 *
6034 * @param string $text The content to encode.
6035 * @return string The encoded content.
6036 */
6037function wp_staticize_emoji( $text ) {
6038 if ( ! str_contains( $text, '&#x' ) ) {
6039 if ( ( function_exists( 'mb_check_encoding' ) && mb_check_encoding( $text, 'ASCII' ) ) || ! preg_match( '/[^\x00-\x7F]/', $text ) ) {
6040 // The text doesn't contain anything that might be emoji, so we can return early.
6041 return $text;
6042 } else {
6043 $encoded_text = wp_encode_emoji( $text );
6044 if ( $encoded_text === $text ) {
6045 return $encoded_text;
6046 }
6047
6048 $text = $encoded_text;
6049 }
6050 }
6051
6052 $emoji = _wp_emoji_list( 'entities' );
6053
6054 // Quickly narrow down the list of emoji that might be in the text and need replacing.
6055 $possible_emoji = array();
6056 foreach ( $emoji as $emojum ) {
6057 if ( str_contains( $text, $emojum ) ) {
6058 $possible_emoji[ $emojum ] = html_entity_decode( $emojum );
6059 }
6060 }
6061
6062 if ( ! $possible_emoji ) {
6063 return $text;
6064 }
6065
6066 /** This filter is documented in wp-includes/formatting.php */
6067 $cdn_url = apply_filters( 'emoji_url', 'https://s.w.org/images/core/emoji/17.0.2/72x72/' );
6068
6069 /** This filter is documented in wp-includes/formatting.php */
6070 $ext = apply_filters( 'emoji_ext', '.png' );
6071
6072 $output = '';
6073 /*
6074 * HTML loop taken from smiley function, which was taken from texturize function.
6075 * It'll never be consolidated.
6076 *
6077 * First, capture the tags as well as in between.
6078 */
6079 $textarr = preg_split( '/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE );
6080 $stop = count( $textarr );
6081
6082 // Ignore processing of specific tags.
6083 $tags_to_ignore = 'code|pre|style|script|textarea';
6084 $ignore_block_element = '';
6085
6086 for ( $i = 0; $i < $stop; $i++ ) {
6087 $content = $textarr[ $i ];
6088
6089 // If we're in an ignore block, wait until we find its closing tag.
6090 if ( '' === $ignore_block_element && preg_match( '/^<(' . $tags_to_ignore . ')>/', $content, $matches ) ) {
6091 $ignore_block_element = $matches[1];
6092 }
6093
6094 // If it's not a tag and not in ignore block.
6095 if ( '' === $ignore_block_element && strlen( $content ) > 0 && '<' !== $content[0] && str_contains( $content, '&#x' ) ) {
6096 foreach ( $possible_emoji as $emojum => $emoji_char ) {
6097 if ( ! str_contains( $content, $emojum ) ) {
6098 continue;
6099 }
6100
6101 $file = str_replace( ';&#x', '-', $emojum );
6102 $file = str_replace( array( '&#x', ';' ), '', $file );
6103
6104 $entity = sprintf( '<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', $cdn_url . $file . $ext, $emoji_char );
6105
6106 $content = str_replace( $emojum, $entity, $content );
6107 }
6108 }
6109
6110 // Did we exit ignore block?
6111 if ( '' !== $ignore_block_element && '</' . $ignore_block_element . '>' === $content ) {
6112 $ignore_block_element = '';
6113 }
6114
6115 $output .= $content;
6116 }
6117
6118 // Finally, remove any stray U+FE0F characters.
6119 $output = str_replace( '️', '', $output );
6120
6121 return $output;
6122}
6123
6124/**
6125 * Converts emoji in emails into static images.
6126 *
6127 * @since 4.2.0
6128 *
6129 * @param array $mail The email data array.
6130 * @return array The email data array, with emoji in the message staticized.
6131 */
6132function wp_staticize_emoji_for_email( $mail ) {
6133 if ( ! isset( $mail['message'] ) ) {
6134 return $mail;
6135 }
6136
6137 /*
6138 * We can only transform the emoji into images if it's a `text/html` email.
6139 * To do that, here's a cut down version of the same process that happens
6140 * in wp_mail() - get the `Content-Type` from the headers, if there is one,
6141 * then pass it through the {@see 'wp_mail_content_type'} filter, in case
6142 * a plugin is handling changing the `Content-Type`.
6143 */
6144 $headers = array();
6145 if ( isset( $mail['headers'] ) ) {
6146 if ( is_array( $mail['headers'] ) ) {
6147 $headers = $mail['headers'];
6148 } else {
6149 $headers = explode( "\n", str_replace( "\r\n", "\n", $mail['headers'] ) );
6150 }
6151 }
6152
6153 foreach ( $headers as $header ) {
6154 if ( ! str_contains( $header, ':' ) ) {
6155 continue;
6156 }
6157
6158 // Explode them out.
6159 list( $name, $content ) = explode( ':', trim( $header ), 2 );
6160
6161 // Cleanup crew.
6162 $name = trim( $name );
6163 $content = trim( $content );
6164
6165 if ( 'content-type' === strtolower( $name ) ) {
6166 if ( str_contains( $content, ';' ) ) {
6167 list( $type, $charset ) = explode( ';', $content );
6168 $content_type = trim( $type );
6169 } else {
6170 $content_type = trim( $content );
6171 }
6172 break;
6173 }
6174 }
6175
6176 // Set Content-Type if we don't have a content-type from the input headers.
6177 if ( ! isset( $content_type ) ) {
6178 $content_type = 'text/plain';
6179 }
6180
6181 /** This filter is documented in wp-includes/pluggable.php */
6182 $content_type = apply_filters( 'wp_mail_content_type', $content_type );
6183
6184 if ( 'text/html' === $content_type ) {
6185 $mail['message'] = wp_staticize_emoji( $mail['message'] );
6186 }
6187
6188 return $mail;
6189}
6190
6191/**
6192 * Returns arrays of emoji data.
6193 *
6194 * These arrays are automatically built from the regex in twemoji.js - if they need to be updated,
6195 * you should update the regex there, then run the `npm run grunt precommit:emoji` job.
6196 *
6197 * @since 4.9.0
6198 * @access private
6199 *
6200 * @param string $type Optional. Which array type to return. Accepts 'partials' or 'entities', default 'entities'.
6201 * @return array An array to match all emoji that WordPress recognises.
6202 */
6203function _wp_emoji_list( $type = 'entities' ) {
6204 // Do not remove the START/END comments - they're used to find where to insert the arrays.
6205
6206 // START: emoji arrays
6207 $entities = array( '👨🏻‍❤️‍💋‍👨🏻', '👨🏻‍❤️‍💋‍👨🏼', '👨🏻‍❤️‍💋‍👨🏽', '👨🏻‍❤️‍💋‍👨🏾', '👨🏻‍❤️‍💋‍👨🏿', '👨🏼‍❤️‍💋‍👨🏻', '👨🏼‍❤️‍💋‍👨🏼', '👨🏼‍❤️‍💋‍👨🏽', '👨🏼‍❤️‍💋‍👨🏾', '👨🏼‍❤️‍💋‍👨🏿', '👨🏽‍❤️‍💋‍👨🏻', '👨🏽‍❤️‍💋‍👨🏼', '👨🏽‍❤️‍💋‍👨🏽', '👨🏽‍❤️‍💋‍👨🏾', '👨🏽‍❤️‍💋‍👨🏿', '👨🏾‍❤️‍💋‍👨🏻', '👨🏾‍❤️‍💋‍👨🏼', '👨🏾‍❤️‍💋‍👨🏽', '👨🏾‍❤️‍💋‍👨🏾', '👨🏾‍❤️‍💋‍👨🏿', '👨🏿‍❤️‍💋‍👨🏻', '👨🏿‍❤️‍💋‍👨🏼', '👨🏿‍❤️‍💋‍👨🏽', '👨🏿‍❤️‍💋‍👨🏾', '👨🏿‍❤️‍💋‍👨🏿', '👩🏻‍❤️‍💋‍👨🏻', '👩🏻‍❤️‍💋‍👨🏼', '👩🏻‍❤️‍💋‍👨🏽', '👩🏻‍❤️‍💋‍👨🏾', '👩🏻‍❤️‍💋‍👨🏿', '👩🏻‍❤️‍💋‍👩🏻', '👩🏻‍❤️‍💋‍👩🏼', '👩🏻‍❤️‍💋‍👩🏽', '👩🏻‍❤️‍💋‍👩🏾', '👩🏻‍❤️‍💋‍👩🏿', '👩🏼‍❤️‍💋‍👨🏻', '👩🏼‍❤️‍💋‍👨🏼', '👩🏼‍❤️‍💋‍👨🏽', '👩🏼‍❤️‍💋‍👨🏾', '👩🏼‍❤️‍💋‍👨🏿', '👩🏼‍❤️‍💋‍👩🏻', '👩🏼‍❤️‍💋‍👩🏼', '👩🏼‍❤️‍💋‍👩🏽', '👩🏼‍❤️‍💋‍👩🏾', '👩🏼‍❤️‍💋‍👩🏿', '👩🏽‍❤️‍💋‍👨🏻', '👩🏽‍❤️‍💋‍👨🏼', '👩🏽‍❤️‍💋‍👨🏽', '👩🏽‍❤️‍💋‍👨🏾', '👩🏽‍❤️‍💋‍👨🏿', '👩🏽‍❤️‍💋‍👩🏻', '👩🏽‍❤️‍💋‍👩🏼', '👩🏽‍❤️‍💋‍👩🏽', '👩🏽‍❤️‍💋‍👩🏾', '👩🏽‍❤️‍💋‍👩🏿', '👩🏾‍❤️‍💋‍👨🏻', '👩🏾‍❤️‍💋‍👨🏼', '👩🏾‍❤️‍💋‍👨🏽', '👩🏾‍❤️‍💋‍👨🏾', '👩🏾‍❤️‍💋‍👨🏿', '👩🏾‍❤️‍💋‍👩🏻', '👩🏾‍❤️‍💋‍👩🏼', '👩🏾‍❤️‍💋‍👩🏽', '👩🏾‍❤️‍💋‍👩🏾', '👩🏾‍❤️‍💋‍👩🏿', '👩🏿‍❤️‍💋‍👨🏻', '👩🏿‍❤️‍💋‍👨🏼', '👩🏿‍❤️‍💋‍👨🏽', '👩🏿‍❤️‍💋‍👨🏾', '👩🏿‍❤️‍💋‍👨🏿', '👩🏿‍❤️‍💋‍👩🏻', '👩🏿‍❤️‍💋‍👩🏼', '👩🏿‍❤️‍💋‍👩🏽', '👩🏿‍❤️‍💋‍👩🏾', '👩🏿‍❤️‍💋‍👩🏿', '🧑🏻‍❤️‍💋‍🧑🏼', '🧑🏻‍❤️‍💋‍🧑🏽', '🧑🏻‍❤️‍💋‍🧑🏾', '🧑🏻‍❤️‍💋‍🧑🏿', '🧑🏼‍❤️‍💋‍🧑🏻', '🧑🏼‍❤️‍💋‍🧑🏽', '🧑🏼‍❤️‍💋‍🧑🏾', '🧑🏼‍❤️‍💋‍🧑🏿', '🧑🏽‍❤️‍💋‍🧑🏻', '🧑🏽‍❤️‍💋‍🧑🏼', '🧑🏽‍❤️‍💋‍🧑🏾', '🧑🏽‍❤️‍💋‍🧑🏿', '🧑🏾‍❤️‍💋‍🧑🏻', '🧑🏾‍❤️‍💋‍🧑🏼', '🧑🏾‍❤️‍💋‍🧑🏽', '🧑🏾‍❤️‍💋‍🧑🏿', '🧑🏿‍❤️‍💋‍🧑🏻', '🧑🏿‍❤️‍💋‍🧑🏼', '🧑🏿‍❤️‍💋‍🧑🏽', '🧑🏿‍❤️‍💋‍🧑🏾', '👨🏻‍❤️‍👨🏻', '👨🏻‍❤️‍👨🏼', '👨🏻‍❤️‍👨🏽', '👨🏻‍❤️‍👨🏾', '👨🏻‍❤️‍👨🏿', '👨🏼‍❤️‍👨🏻', '👨🏼‍❤️‍👨🏼', '👨🏼‍❤️‍👨🏽', '👨🏼‍❤️‍👨🏾', '👨🏼‍❤️‍👨🏿', '👨🏽‍❤️‍👨🏻', '👨🏽‍❤️‍👨🏼', '👨🏽‍❤️‍👨🏽', '👨🏽‍❤️‍👨🏾', '👨🏽‍❤️‍👨🏿', '👨🏾‍❤️‍👨🏻', '👨🏾‍❤️‍👨🏼', '👨🏾‍❤️‍👨🏽', '👨🏾‍❤️‍👨🏾', '👨🏾‍❤️‍👨🏿', '👨🏿‍❤️‍👨🏻', '👨🏿‍❤️‍👨🏼', '👨🏿‍❤️‍👨🏽', '👨🏿‍❤️‍👨🏾', '👨🏿‍❤️‍👨🏿', '👩🏻‍❤️‍👨🏻', '👩🏻‍❤️‍👨🏼', '👩🏻‍❤️‍👨🏽', '👩🏻‍❤️‍👨🏾', '👩🏻‍❤️‍👨🏿', '👩🏻‍❤️‍👩🏻', '👩🏻‍❤️‍👩🏼', '👩🏻‍❤️‍👩🏽', '👩🏻‍❤️‍👩🏾', '👩🏻‍❤️‍👩🏿', '👩🏼‍❤️‍👨🏻', '👩🏼‍❤️‍👨🏼', '👩🏼‍❤️‍👨🏽', '👩🏼‍❤️‍👨🏾', '👩🏼‍❤️‍👨🏿', '👩🏼‍❤️‍👩🏻', '👩🏼‍❤️‍👩🏼', '👩🏼‍❤️‍👩🏽', '👩🏼‍❤️‍👩🏾', '👩🏼‍❤️‍👩🏿', '👩🏽‍❤️‍👨🏻', '👩🏽‍❤️‍👨🏼', '👩🏽‍❤️‍👨🏽', '👩🏽‍❤️‍👨🏾', '👩🏽‍❤️‍👨🏿', '👩🏽‍❤️‍👩🏻', '👩🏽‍❤️‍👩🏼', '👩🏽‍❤️‍👩🏽', '👩🏽‍❤️‍👩🏾', '👩🏽‍❤️‍👩🏿', '👩🏾‍❤️‍👨🏻', '👩🏾‍❤️‍👨🏼', '👩🏾‍❤️‍👨🏽', '👩🏾‍❤️‍👨🏾', '👩🏾‍❤️‍👨🏿', '👩🏾‍❤️‍👩🏻', '👩🏾‍❤️‍👩🏼', '👩🏾‍❤️‍👩🏽', '👩🏾‍❤️‍👩🏾', '👩🏾‍❤️‍👩🏿', '👩🏿‍❤️‍👨🏻', '👩🏿‍❤️‍👨🏼', '👩🏿‍❤️‍👨🏽', '👩🏿‍❤️‍👨🏾', '👩🏿‍❤️‍👨🏿', '👩🏿‍❤️‍👩🏻', '👩🏿‍❤️‍👩🏼', '👩🏿‍❤️‍👩🏽', '👩🏿‍❤️‍👩🏾', '👩🏿‍❤️‍👩🏿', '🧑🏻‍❤️‍🧑🏼', '🧑🏻‍❤️‍🧑🏽', '🧑🏻‍❤️‍🧑🏾', '🧑🏻‍❤️‍🧑🏿', '🧑🏼‍❤️‍🧑🏻', '🧑🏼‍❤️‍🧑🏽', '🧑🏼‍❤️‍🧑🏾', '🧑🏼‍❤️‍🧑🏿', '🧑🏽‍❤️‍🧑🏻', '🧑🏽‍❤️‍🧑🏼', '🧑🏽‍❤️‍🧑🏾', '🧑🏽‍❤️‍🧑🏿', '🧑🏾‍❤️‍🧑🏻', '🧑🏾‍❤️‍🧑🏼', '🧑🏾‍❤️‍🧑🏽', '🧑🏾‍❤️‍🧑🏿', '🧑🏿‍❤️‍🧑🏻', '🧑🏿‍❤️‍🧑🏼', '🧑🏿‍❤️‍🧑🏽', '🧑🏿‍❤️‍🧑🏾', '👨‍❤️‍💋‍👨', '👩‍❤️‍💋‍👨', '👩‍❤️‍💋‍👩', '🏃🏻‍♀️‍➡️', '🏃🏻‍♂️‍➡️', '🏃🏼‍♀️‍➡️', '🏃🏼‍♂️‍➡️', '🏃🏽‍♀️‍➡️', '🏃🏽‍♂️‍➡️', '🏃🏾‍♀️‍➡️', '🏃🏾‍♂️‍➡️', '🏃🏿‍♀️‍➡️', '🏃🏿‍♂️‍➡️', '🚶🏻‍♀️‍➡️', '🚶🏻‍♂️‍➡️', '🚶🏼‍♀️‍➡️', '🚶🏼‍♂️‍➡️', '🚶🏽‍♀️‍➡️', '🚶🏽‍♂️‍➡️', '🚶🏾‍♀️‍➡️', '🚶🏾‍♂️‍➡️', '🚶🏿‍♀️‍➡️', '🚶🏿‍♂️‍➡️', '🧎🏻‍♀️‍➡️', '🧎🏻‍♂️‍➡️', '🧎🏼‍♀️‍➡️', '🧎🏼‍♂️‍➡️', '🧎🏽‍♀️‍➡️', '🧎🏽‍♂️‍➡️', '🧎🏾‍♀️‍➡️', '🧎🏾‍♂️‍➡️', '🧎🏿‍♀️‍➡️', '🧎🏿‍♂️‍➡️', '🏴󠁧󠁢󠁥󠁮󠁧󠁿', '🏴󠁧󠁢󠁳󠁣󠁴󠁿', '🏴󠁧󠁢󠁷󠁬󠁳󠁿', '👨🏻‍🐰‍👨🏼', '👨🏻‍🐰‍👨🏽', '👨🏻‍🐰‍👨🏾', '👨🏻‍🐰‍👨🏿', '👨🏻‍🤝‍👨🏼', '👨🏻‍🤝‍👨🏽', '👨🏻‍🤝‍👨🏾', '👨🏻‍🤝‍👨🏿', '👨🏻‍🫯‍👨🏼', '👨🏻‍🫯‍👨🏽', '👨🏻‍🫯‍👨🏾', '👨🏻‍🫯‍👨🏿', '👨🏼‍🐰‍👨🏻', '👨🏼‍🐰‍👨🏼', '👨🏼‍🐰‍👨🏽', '👨🏼‍🐰‍👨🏾', '👨🏼‍🐰‍👨🏿', '👨🏼‍🤝‍👨🏻', '👨🏼‍🤝‍👨🏽', '👨🏼‍🤝‍👨🏾', '👨🏼‍🤝‍👨🏿', '👨🏼‍🫯‍👨🏻', '👨🏼‍🫯‍👨🏽', '👨🏼‍🫯‍👨🏾', '👨🏼‍🫯‍👨🏿', '👨🏽‍🐰‍👨🏻', '👨🏽‍🐰‍👨🏼', '👨🏽‍🐰‍👨🏾', '👨🏽‍🐰‍👨🏿', '👨🏽‍🤝‍👨🏻', '👨🏽‍🤝‍👨🏼', '👨🏽‍🤝‍👨🏾', '👨🏽‍🤝‍👨🏿', '👨🏽‍🫯‍👨🏻', '👨🏽‍🫯‍👨🏼', '👨🏽‍🫯‍👨🏾', '👨🏽‍🫯‍👨🏿', '👨🏾‍🐰‍👨🏻', '👨🏾‍🐰‍👨🏼', '👨🏾‍🐰‍👨🏽', '👨🏾‍🐰‍👨🏿', '👨🏾‍🤝‍👨🏻', '👨🏾‍🤝‍👨🏼', '👨🏾‍🤝‍👨🏽', '👨🏾‍🤝‍👨🏿', '👨🏾‍🫯‍👨🏻', '👨🏾‍🫯‍👨🏼', '👨🏾‍🫯‍👨🏽', '👨🏾‍🫯‍👨🏿', '👨🏿‍🐰‍👨🏻', '👨🏿‍🐰‍👨🏼', '👨🏿‍🐰‍👨🏽', '👨🏿‍🐰‍👨🏾', '👨🏿‍🤝‍👨🏻', '👨🏿‍🤝‍👨🏼', '👨🏿‍🤝‍👨🏽', '👨🏿‍🤝‍👨🏾', '👨🏿‍🫯‍👨🏻', '👨🏿‍🫯‍👨🏼', '👨🏿‍🫯‍👨🏽', '👨🏿‍🫯‍👨🏾', '👩🏻‍🐰‍👩🏼', '👩🏻‍🐰‍👩🏽', '👩🏻‍🐰‍👩🏾', '👩🏻‍🐰‍👩🏿', '👩🏻‍🤝‍👨🏼', '👩🏻‍🤝‍👨🏽', '👩🏻‍🤝‍👨🏾', '👩🏻‍🤝‍👨🏿', '👩🏻‍🤝‍👩🏼', '👩🏻‍🤝‍👩🏽', '👩🏻‍🤝‍👩🏾', '👩🏻‍🤝‍👩🏿', '👩🏻‍🫯‍👩🏼', '👩🏻‍🫯‍👩🏽', '👩🏻‍🫯‍👩🏾', '👩🏻‍🫯‍👩🏿', '👩🏼‍🐰‍👩🏻', '👩🏼‍🐰‍👩🏽', '👩🏼‍🐰‍👩🏾', '👩🏼‍🐰‍👩🏿', '👩🏼‍🤝‍👨🏻', '👩🏼‍🤝‍👨🏽', '👩🏼‍🤝‍👨🏾', '👩🏼‍🤝‍👨🏿', '👩🏼‍🤝‍👩🏻', '👩🏼‍🤝‍👩🏽', '👩🏼‍🤝‍👩🏾', '👩🏼‍🤝‍👩🏿', '👩🏼‍🫯‍👩🏻', '👩🏼‍🫯‍👩🏽', '👩🏼‍🫯‍👩🏾', '👩🏼‍🫯‍👩🏿', '👩🏽‍🐰‍👩🏻', '👩🏽‍🐰‍👩🏼', '👩🏽‍🐰‍👩🏾', '👩🏽‍🐰‍👩🏿', '👩🏽‍🤝‍👨🏻', '👩🏽‍🤝‍👨🏼', '👩🏽‍🤝‍👨🏾', '👩🏽‍🤝‍👨🏿', '👩🏽‍🤝‍👩🏻', '👩🏽‍🤝‍👩🏼', '👩🏽‍🤝‍👩🏾', '👩🏽‍🤝‍👩🏿', '👩🏽‍🫯‍👩🏻', '👩🏽‍🫯‍👩🏼', '👩🏽‍🫯‍👩🏾', '👩🏽‍🫯‍👩🏿', '👩🏾‍🐰‍👩🏻', '👩🏾‍🐰‍👩🏼', '👩🏾‍🐰‍👩🏽', '👩🏾‍🐰‍👩🏿', '👩🏾‍🤝‍👨🏻', '👩🏾‍🤝‍👨🏼', '👩🏾‍🤝‍👨🏽', '👩🏾‍🤝‍👨🏿', '👩🏾‍🤝‍👩🏻', '👩🏾‍🤝‍👩🏼', '👩🏾‍🤝‍👩🏽', '👩🏾‍🤝‍👩🏿', '👩🏾‍🫯‍👩🏻', '👩🏾‍🫯‍👩🏼', '👩🏾‍🫯‍👩🏽', '👩🏾‍🫯‍👩🏿', '👩🏿‍🐰‍👩🏻', '👩🏿‍🐰‍👩🏼', '👩🏿‍🐰‍👩🏽', '👩🏿‍🐰‍👩🏾', '👩🏿‍🤝‍👨🏻', '👩🏿‍🤝‍👨🏼', '👩🏿‍🤝‍👨🏽', '👩🏿‍🤝‍👨🏾', '👩🏿‍🤝‍👩🏻', '👩🏿‍🤝‍👩🏼', '👩🏿‍🤝‍👩🏽', '👩🏿‍🤝‍👩🏾', '👩🏿‍🫯‍👩🏻', '👩🏿‍🫯‍👩🏼', '👩🏿‍🫯‍👩🏽', '👩🏿‍🫯‍👩🏾', '🧑🏻‍🐰‍🧑🏼', '🧑🏻‍🐰‍🧑🏽', '🧑🏻‍🐰‍🧑🏾', '🧑🏻‍🐰‍🧑🏿', '🧑🏻‍🤝‍🧑🏻', '🧑🏻‍🤝‍🧑🏼', '🧑🏻‍🤝‍🧑🏽', '🧑🏻‍🤝‍🧑🏾', '🧑🏻‍🤝‍🧑🏿', '🧑🏻‍🫯‍🧑🏼', '🧑🏻‍🫯‍🧑🏽', '🧑🏻‍🫯‍🧑🏾', '🧑🏻‍🫯‍🧑🏿', '🧑🏼‍🐰‍🧑🏻', '🧑🏼‍🐰‍🧑🏽', '🧑🏼‍🐰‍🧑🏾', '🧑🏼‍🐰‍🧑🏿', '🧑🏼‍🤝‍🧑🏻', '🧑🏼‍🤝‍🧑🏼', '🧑🏼‍🤝‍🧑🏽', '🧑🏼‍🤝‍🧑🏾', '🧑🏼‍🤝‍🧑🏿', '🧑🏼‍🫯‍🧑🏻', '🧑🏼‍🫯‍🧑🏽', '🧑🏼‍🫯‍🧑🏾', '🧑🏼‍🫯‍🧑🏿', '🧑🏽‍🐰‍🧑🏻', '🧑🏽‍🐰‍🧑🏼', '🧑🏽‍🐰‍🧑🏾', '🧑🏽‍🐰‍🧑🏿', '🧑🏽‍🤝‍🧑🏻', '🧑🏽‍🤝‍🧑🏼', '🧑🏽‍🤝‍🧑🏽', '🧑🏽‍🤝‍🧑🏾', '🧑🏽‍🤝‍🧑🏿', '🧑🏽‍🫯‍🧑🏻', '🧑🏽‍🫯‍🧑🏼', '🧑🏽‍🫯‍🧑🏾', '🧑🏽‍🫯‍🧑🏿', '🧑🏾‍🐰‍🧑🏻', '🧑🏾‍🐰‍🧑🏼', '🧑🏾‍🐰‍🧑🏽', '🧑🏾‍🐰‍🧑🏿', '🧑🏾‍🤝‍🧑🏻', '🧑🏾‍🤝‍🧑🏼', '🧑🏾‍🤝‍🧑🏽', '🧑🏾‍🤝‍🧑🏾', '🧑🏾‍🤝‍🧑🏿', '🧑🏾‍🫯‍🧑🏻', '🧑🏾‍🫯‍🧑🏼', '🧑🏾‍🫯‍🧑🏽', '🧑🏾‍🫯‍🧑🏿', '🧑🏿‍🐰‍🧑🏻', '🧑🏿‍🐰‍🧑🏼', '🧑🏿‍🐰‍🧑🏽', '🧑🏿‍🐰‍🧑🏾', '🧑🏿‍🤝‍🧑🏻', '🧑🏿‍🤝‍🧑🏼', '🧑🏿‍🤝‍🧑🏽', '🧑🏿‍🤝‍🧑🏾', '🧑🏿‍🤝‍🧑🏿', '🧑🏿‍🫯‍🧑🏻', '🧑🏿‍🫯‍🧑🏼', '🧑🏿‍🫯‍🧑🏽', '🧑🏿‍🫯‍🧑🏾', '👨‍👨‍👦‍👦', '👨‍👨‍👧‍👦', '👨‍👨‍👧‍👧', '👨‍👩‍👦‍👦', '👨‍👩‍👧‍👦', '👨‍👩‍👧‍👧', '👩‍👩‍👦‍👦', '👩‍👩‍👧‍👦', '👩‍👩‍👧‍👧', '🧑‍🧑‍🧒‍🧒', '👨🏻‍🦯‍➡️', '👨🏻‍🦼‍➡️', '👨🏻‍🦽‍➡️', '👨🏼‍🦯‍➡️', '👨🏼‍🦼‍➡️', '👨🏼‍🦽‍➡️', '👨🏽‍🦯‍➡️', '👨🏽‍🦼‍➡️', '👨🏽‍🦽‍➡️', '👨🏾‍🦯‍➡️', '👨🏾‍🦼‍➡️', '👨🏾‍🦽‍➡️', '👨🏿‍🦯‍➡️', '👨🏿‍🦼‍➡️', '👨🏿‍🦽‍➡️', '👩🏻‍🦯‍➡️', '👩🏻‍🦼‍➡️', '👩🏻‍🦽‍➡️', '👩🏼‍🦯‍➡️', '👩🏼‍🦼‍➡️', '👩🏼‍🦽‍➡️', '👩🏽‍🦯‍➡️', '👩🏽‍🦼‍➡️', '👩🏽‍🦽‍➡️', '👩🏾‍🦯‍➡️', '👩🏾‍🦼‍➡️', '👩🏾‍🦽‍➡️', '👩🏿‍🦯‍➡️', '👩🏿‍🦼‍➡️', '👩🏿‍🦽‍➡️', '🧑🏻‍🦯‍➡️', '🧑🏻‍🦼‍➡️', '🧑🏻‍🦽‍➡️', '🧑🏼‍🦯‍➡️', '🧑🏼‍🦼‍➡️', '🧑🏼‍🦽‍➡️', '🧑🏽‍🦯‍➡️', '🧑🏽‍🦼‍➡️', '🧑🏽‍🦽‍➡️', '🧑🏾‍🦯‍➡️', '🧑🏾‍🦼‍➡️', '🧑🏾‍🦽‍➡️', '🧑🏿‍🦯‍➡️', '🧑🏿‍🦼‍➡️', '🧑🏿‍🦽‍➡️', '🏃‍♀️‍➡️', '🏃‍♂️‍➡️', '🚶‍♀️‍➡️', '🚶‍♂️‍➡️', '🧎‍♀️‍➡️', '🧎‍♂️‍➡️', '👨‍🦯‍➡️', '👨‍🦼‍➡️', '👨‍🦽‍➡️', '👨‍❤️‍👨', '👩‍🦯‍➡️', '👩‍🦼‍➡️', '👩‍🦽‍➡️', '👩‍❤️‍👨', '👩‍❤️‍👩', '🧑‍🦯‍➡️', '🧑‍🦼‍➡️', '🧑‍🦽‍➡️', '🫱🏻‍🫲🏼', '🫱🏻‍🫲🏽', '🫱🏻‍🫲🏾', '🫱🏻‍🫲🏿', '🫱🏼‍🫲🏻', '🫱🏼‍🫲🏽', '🫱🏼‍🫲🏾', '🫱🏼‍🫲🏿', '🫱🏽‍🫲🏻', '🫱🏽‍🫲🏼', '🫱🏽‍🫲🏾', '🫱🏽‍🫲🏿', '🫱🏾‍🫲🏻', '🫱🏾‍🫲🏼', '🫱🏾‍🫲🏽', '🫱🏾‍🫲🏿', '🫱🏿‍🫲🏻', '🫱🏿‍🫲🏼', '🫱🏿‍🫲🏽', '🫱🏿‍🫲🏾', '👨‍👦‍👦', '👨‍👧‍👦', '👨‍👧‍👧', '👨‍👨‍👦', '👨‍👨‍👧', '👨‍👩‍👦', '👨‍👩‍👧', '👩‍👦‍👦', '👩‍👧‍👦', '👩‍👧‍👧', '👩‍👩‍👦', '👩‍👩‍👧', '🧑‍🤝‍🧑', '🧑‍🧑‍🧒', '🧑‍🧒‍🧒', '🏃🏻‍♀️', '🏃🏻‍♂️', '🏃🏻‍➡️', '🏃🏼‍♀️', '🏃🏼‍♂️', '🏃🏼‍➡️', '🏃🏽‍♀️', '🏃🏽‍♂️', '🏃🏽‍➡️', '🏃🏾‍♀️', '🏃🏾‍♂️', '🏃🏾‍➡️', '🏃🏿‍♀️', '🏃🏿‍♂️', '🏃🏿‍➡️', '🏄🏻‍♀️', '🏄🏻‍♂️', '🏄🏼‍♀️', '🏄🏼‍♂️', '🏄🏽‍♀️', '🏄🏽‍♂️', '🏄🏾‍♀️', '🏄🏾‍♂️', '🏄🏿‍♀️', '🏄🏿‍♂️', '🏊🏻‍♀️', '🏊🏻‍♂️', '🏊🏼‍♀️', '🏊🏼‍♂️', '🏊🏽‍♀️', '🏊🏽‍♂️', '🏊🏾‍♀️', '🏊🏾‍♂️', '🏊🏿‍♀️', '🏊🏿‍♂️', '🏋🏻‍♀️', '🏋🏻‍♂️', '🏋🏼‍♀️', '🏋🏼‍♂️', '🏋🏽‍♀️', '🏋🏽‍♂️', '🏋🏾‍♀️', '🏋🏾‍♂️', '🏋🏿‍♀️', '🏋🏿‍♂️', '🏌🏻‍♀️', '🏌🏻‍♂️', '🏌🏼‍♀️', '🏌🏼‍♂️', '🏌🏽‍♀️', '🏌🏽‍♂️', '🏌🏾‍♀️', '🏌🏾‍♂️', '🏌🏿‍♀️', '🏌🏿‍♂️', '👨🏻‍⚕️', '👨🏻‍⚖️', '👨🏻‍✈️', '👨🏼‍⚕️', '👨🏼‍⚖️', '👨🏼‍✈️', '👨🏽‍⚕️', '👨🏽‍⚖️', '👨🏽‍✈️', '👨🏾‍⚕️', '👨🏾‍⚖️', '👨🏾‍✈️', '👨🏿‍⚕️', '👨🏿‍⚖️', '👨🏿‍✈️', '👩🏻‍⚕️', '👩🏻‍⚖️', '👩🏻‍✈️', '👩🏼‍⚕️', '👩🏼‍⚖️', '👩🏼‍✈️', '👩🏽‍⚕️', '👩🏽‍⚖️', '👩🏽‍✈️', '👩🏾‍⚕️', '👩🏾‍⚖️', '👩🏾‍✈️', '👩🏿‍⚕️', '👩🏿‍⚖️', '👩🏿‍✈️', '👮🏻‍♀️', '👮🏻‍♂️', '👮🏼‍♀️', '👮🏼‍♂️', '👮🏽‍♀️', '👮🏽‍♂️', '👮🏾‍♀️', '👮🏾‍♂️', '👮🏿‍♀️', '👮🏿‍♂️', '👯🏻‍♀️', '👯🏻‍♂️', '👯🏼‍♀️', '👯🏼‍♂️', '👯🏽‍♀️', '👯🏽‍♂️', '👯🏾‍♀️', '👯🏾‍♂️', '👯🏿‍♀️', '👯🏿‍♂️', '👰🏻‍♀️', '👰🏻‍♂️', '👰🏼‍♀️', '👰🏼‍♂️', '👰🏽‍♀️', '👰🏽‍♂️', '👰🏾‍♀️', '👰🏾‍♂️', '👰🏿‍♀️', '👰🏿‍♂️', '👱🏻‍♀️', '👱🏻‍♂️', '👱🏼‍♀️', '👱🏼‍♂️', '👱🏽‍♀️', '👱🏽‍♂️', '👱🏾‍♀️', '👱🏾‍♂️', '👱🏿‍♀️', '👱🏿‍♂️', '👳🏻‍♀️', '👳🏻‍♂️', '👳🏼‍♀️', '👳🏼‍♂️', '👳🏽‍♀️', '👳🏽‍♂️', '👳🏾‍♀️', '👳🏾‍♂️', '👳🏿‍♀️', '👳🏿‍♂️', '👷🏻‍♀️', '👷🏻‍♂️', '👷🏼‍♀️', '👷🏼‍♂️', '👷🏽‍♀️', '👷🏽‍♂️', '👷🏾‍♀️', '👷🏾‍♂️', '👷🏿‍♀️', '👷🏿‍♂️', '💁🏻‍♀️', '💁🏻‍♂️', '💁🏼‍♀️', '💁🏼‍♂️', '💁🏽‍♀️', '💁🏽‍♂️', '💁🏾‍♀️', '💁🏾‍♂️', '💁🏿‍♀️', '💁🏿‍♂️', '💂🏻‍♀️', '💂🏻‍♂️', '💂🏼‍♀️', '💂🏼‍♂️', '💂🏽‍♀️', '💂🏽‍♂️', '💂🏾‍♀️', '💂🏾‍♂️', '💂🏿‍♀️', '💂🏿‍♂️', '💆🏻‍♀️', '💆🏻‍♂️', '💆🏼‍♀️', '💆🏼‍♂️', '💆🏽‍♀️', '💆🏽‍♂️', '💆🏾‍♀️', '💆🏾‍♂️', '💆🏿‍♀️', '💆🏿‍♂️', '💇🏻‍♀️', '💇🏻‍♂️', '💇🏼‍♀️', '💇🏼‍♂️', '💇🏽‍♀️', '💇🏽‍♂️', '💇🏾‍♀️', '💇🏾‍♂️', '💇🏿‍♀️', '💇🏿‍♂️', '🕴🏻‍♀️', '🕴🏻‍♂️', '🕴🏼‍♀️', '🕴🏼‍♂️', '🕴🏽‍♀️', '🕴🏽‍♂️', '🕴🏾‍♀️', '🕴🏾‍♂️', '🕴🏿‍♀️', '🕴🏿‍♂️', '🕵🏻‍♀️', '🕵🏻‍♂️', '🕵🏼‍♀️', '🕵🏼‍♂️', '🕵🏽‍♀️', '🕵🏽‍♂️', '🕵🏾‍♀️', '🕵🏾‍♂️', '🕵🏿‍♀️', '🕵🏿‍♂️', '🙅🏻‍♀️', '🙅🏻‍♂️', '🙅🏼‍♀️', '🙅🏼‍♂️', '🙅🏽‍♀️', '🙅🏽‍♂️', '🙅🏾‍♀️', '🙅🏾‍♂️', '🙅🏿‍♀️', '🙅🏿‍♂️', '🙆🏻‍♀️', '🙆🏻‍♂️', '🙆🏼‍♀️', '🙆🏼‍♂️', '🙆🏽‍♀️', '🙆🏽‍♂️', '🙆🏾‍♀️', '🙆🏾‍♂️', '🙆🏿‍♀️', '🙆🏿‍♂️', '🙇🏻‍♀️', '🙇🏻‍♂️', '🙇🏼‍♀️', '🙇🏼‍♂️', '🙇🏽‍♀️', '🙇🏽‍♂️', '🙇🏾‍♀️', '🙇🏾‍♂️', '🙇🏿‍♀️', '🙇🏿‍♂️', '🙋🏻‍♀️', '🙋🏻‍♂️', '🙋🏼‍♀️', '🙋🏼‍♂️', '🙋🏽‍♀️', '🙋🏽‍♂️', '🙋🏾‍♀️', '🙋🏾‍♂️', '🙋🏿‍♀️', '🙋🏿‍♂️', '🙍🏻‍♀️', '🙍🏻‍♂️', '🙍🏼‍♀️', '🙍🏼‍♂️', '🙍🏽‍♀️', '🙍🏽‍♂️', '🙍🏾‍♀️', '🙍🏾‍♂️', '🙍🏿‍♀️', '🙍🏿‍♂️', '🙎🏻‍♀️', '🙎🏻‍♂️', '🙎🏼‍♀️', '🙎🏼‍♂️', '🙎🏽‍♀️', '🙎🏽‍♂️', '🙎🏾‍♀️', '🙎🏾‍♂️', '🙎🏿‍♀️', '🙎🏿‍♂️', '🚣🏻‍♀️', '🚣🏻‍♂️', '🚣🏼‍♀️', '🚣🏼‍♂️', '🚣🏽‍♀️', '🚣🏽‍♂️', '🚣🏾‍♀️', '🚣🏾‍♂️', '🚣🏿‍♀️', '🚣🏿‍♂️', '🚴🏻‍♀️', '🚴🏻‍♂️', '🚴🏼‍♀️', '🚴🏼‍♂️', '🚴🏽‍♀️', '🚴🏽‍♂️', '🚴🏾‍♀️', '🚴🏾‍♂️', '🚴🏿‍♀️', '🚴🏿‍♂️', '🚵🏻‍♀️', '🚵🏻‍♂️', '🚵🏼‍♀️', '🚵🏼‍♂️', '🚵🏽‍♀️', '🚵🏽‍♂️', '🚵🏾‍♀️', '🚵🏾‍♂️', '🚵🏿‍♀️', '🚵🏿‍♂️', '🚶🏻‍♀️', '🚶🏻‍♂️', '🚶🏻‍➡️', '🚶🏼‍♀️', '🚶🏼‍♂️', '🚶🏼‍➡️', '🚶🏽‍♀️', '🚶🏽‍♂️', '🚶🏽‍➡️', '🚶🏾‍♀️', '🚶🏾‍♂️', '🚶🏾‍➡️', '🚶🏿‍♀️', '🚶🏿‍♂️', '🚶🏿‍➡️', '🤦🏻‍♀️', '🤦🏻‍♂️', '🤦🏼‍♀️', '🤦🏼‍♂️', '🤦🏽‍♀️', '🤦🏽‍♂️', '🤦🏾‍♀️', '🤦🏾‍♂️', '🤦🏿‍♀️', '🤦🏿‍♂️', '🤵🏻‍♀️', '🤵🏻‍♂️', '🤵🏼‍♀️', '🤵🏼‍♂️', '🤵🏽‍♀️', '🤵🏽‍♂️', '🤵🏾‍♀️', '🤵🏾‍♂️', '🤵🏿‍♀️', '🤵🏿‍♂️', '🤷🏻‍♀️', '🤷🏻‍♂️', '🤷🏼‍♀️', '🤷🏼‍♂️', '🤷🏽‍♀️', '🤷🏽‍♂️', '🤷🏾‍♀️', '🤷🏾‍♂️', '🤷🏿‍♀️', '🤷🏿‍♂️', '🤸🏻‍♀️', '🤸🏻‍♂️', '🤸🏼‍♀️', '🤸🏼‍♂️', '🤸🏽‍♀️', '🤸🏽‍♂️', '🤸🏾‍♀️', '🤸🏾‍♂️', '🤸🏿‍♀️', '🤸🏿‍♂️', '🤹🏻‍♀️', '🤹🏻‍♂️', '🤹🏼‍♀️', '🤹🏼‍♂️', '🤹🏽‍♀️', '🤹🏽‍♂️', '🤹🏾‍♀️', '🤹🏾‍♂️', '🤹🏿‍♀️', '🤹🏿‍♂️', '🤼🏻‍♀️', '🤼🏻‍♂️', '🤼🏼‍♀️', '🤼🏼‍♂️', '🤼🏽‍♀️', '🤼🏽‍♂️', '🤼🏾‍♀️', '🤼🏾‍♂️', '🤼🏿‍♀️', '🤼🏿‍♂️', '🤽🏻‍♀️', '🤽🏻‍♂️', '🤽🏼‍♀️', '🤽🏼‍♂️', '🤽🏽‍♀️', '🤽🏽‍♂️', '🤽🏾‍♀️', '🤽🏾‍♂️', '🤽🏿‍♀️', '🤽🏿‍♂️', '🤾🏻‍♀️', '🤾🏻‍♂️', '🤾🏼‍♀️', '🤾🏼‍♂️', '🤾🏽‍♀️', '🤾🏽‍♂️', '🤾🏾‍♀️', '🤾🏾‍♂️', '🤾🏿‍♀️', '🤾🏿‍♂️', '🦸🏻‍♀️', '🦸🏻‍♂️', '🦸🏼‍♀️', '🦸🏼‍♂️', '🦸🏽‍♀️', '🦸🏽‍♂️', '🦸🏾‍♀️', '🦸🏾‍♂️', '🦸🏿‍♀️', '🦸🏿‍♂️', '🦹🏻‍♀️', '🦹🏻‍♂️', '🦹🏼‍♀️', '🦹🏼‍♂️', '🦹🏽‍♀️', '🦹🏽‍♂️', '🦹🏾‍♀️', '🦹🏾‍♂️', '🦹🏿‍♀️', '🦹🏿‍♂️', '🧍🏻‍♀️', '🧍🏻‍♂️', '🧍🏼‍♀️', '🧍🏼‍♂️', '🧍🏽‍♀️', '🧍🏽‍♂️', '🧍🏾‍♀️', '🧍🏾‍♂️', '🧍🏿‍♀️', '🧍🏿‍♂️', '🧎🏻‍♀️', '🧎🏻‍♂️', '🧎🏻‍➡️', '🧎🏼‍♀️', '🧎🏼‍♂️', '🧎🏼‍➡️', '🧎🏽‍♀️', '🧎🏽‍♂️', '🧎🏽‍➡️', '🧎🏾‍♀️', '🧎🏾‍♂️', '🧎🏾‍➡️', '🧎🏿‍♀️', '🧎🏿‍♂️', '🧎🏿‍➡️', '🧏🏻‍♀️', '🧏🏻‍♂️', '🧏🏼‍♀️', '🧏🏼‍♂️', '🧏🏽‍♀️', '🧏🏽‍♂️', '🧏🏾‍♀️', '🧏🏾‍♂️', '🧏🏿‍♀️', '🧏🏿‍♂️', '🧑🏻‍⚕️', '🧑🏻‍⚖️', '🧑🏻‍✈️', '🧑🏼‍⚕️', '🧑🏼‍⚖️', '🧑🏼‍✈️', '🧑🏽‍⚕️', '🧑🏽‍⚖️', '🧑🏽‍✈️', '🧑🏾‍⚕️', '🧑🏾‍⚖️', '🧑🏾‍✈️', '🧑🏿‍⚕️', '🧑🏿‍⚖️', '🧑🏿‍✈️', '🧔🏻‍♀️', '🧔🏻‍♂️', '🧔🏼‍♀️', '🧔🏼‍♂️', '🧔🏽‍♀️', '🧔🏽‍♂️', '🧔🏾‍♀️', '🧔🏾‍♂️', '🧔🏿‍♀️', '🧔🏿‍♂️', '🧖🏻‍♀️', '🧖🏻‍♂️', '🧖🏼‍♀️', '🧖🏼‍♂️', '🧖🏽‍♀️', '🧖🏽‍♂️', '🧖🏾‍♀️', '🧖🏾‍♂️', '🧖🏿‍♀️', '🧖🏿‍♂️', '🧗🏻‍♀️', '🧗🏻‍♂️', '🧗🏼‍♀️', '🧗🏼‍♂️', '🧗🏽‍♀️', '🧗🏽‍♂️', '🧗🏾‍♀️', '🧗🏾‍♂️', '🧗🏿‍♀️', '🧗🏿‍♂️', '🧘🏻‍♀️', '🧘🏻‍♂️', '🧘🏼‍♀️', '🧘🏼‍♂️', '🧘🏽‍♀️', '🧘🏽‍♂️', '🧘🏾‍♀️', '🧘🏾‍♂️', '🧘🏿‍♀️', '🧘🏿‍♂️', '🧙🏻‍♀️', '🧙🏻‍♂️', '🧙🏼‍♀️', '🧙🏼‍♂️', '🧙🏽‍♀️', '🧙🏽‍♂️', '🧙🏾‍♀️', '🧙🏾‍♂️', '🧙🏿‍♀️', '🧙🏿‍♂️', '🧚🏻‍♀️', '🧚🏻‍♂️', '🧚🏼‍♀️', '🧚🏼‍♂️', '🧚🏽‍♀️', '🧚🏽‍♂️', '🧚🏾‍♀️', '🧚🏾‍♂️', '🧚🏿‍♀️', '🧚🏿‍♂️', '🧛🏻‍♀️', '🧛🏻‍♂️', '🧛🏼‍♀️', '🧛🏼‍♂️', '🧛🏽‍♀️', '🧛🏽‍♂️', '🧛🏾‍♀️', '🧛🏾‍♂️', '🧛🏿‍♀️', '🧛🏿‍♂️', '🧜🏻‍♀️', '🧜🏻‍♂️', '🧜🏼‍♀️', '🧜🏼‍♂️', '🧜🏽‍♀️', '🧜🏽‍♂️', '🧜🏾‍♀️', '🧜🏾‍♂️', '🧜🏿‍♀️', '🧜🏿‍♂️', '🧝🏻‍♀️', '🧝🏻‍♂️', '🧝🏼‍♀️', '🧝🏼‍♂️', '🧝🏽‍♀️', '🧝🏽‍♂️', '🧝🏾‍♀️', '🧝🏾‍♂️', '🧝🏿‍♀️', '🧝🏿‍♂️', '🏋️‍♀️', '🏋️‍♂️', '🏌️‍♀️', '🏌️‍♂️', '🏳️‍⚧️', '🕴️‍♀️', '🕴️‍♂️', '🕵️‍♀️', '🕵️‍♂️', '⛹🏻‍♀️', '⛹🏻‍♂️', '⛹🏼‍♀️', '⛹🏼‍♂️', '⛹🏽‍♀️', '⛹🏽‍♂️', '⛹🏾‍♀️', '⛹🏾‍♂️', '⛹🏿‍♀️', '⛹🏿‍♂️', '⛹️‍♀️', '⛹️‍♂️', '👨🏻‍🌾', '👨🏻‍🍳', '👨🏻‍🍼', '👨🏻‍🎄', '👨🏻‍🎓', '👨🏻‍🎤', '👨🏻‍🎨', '👨🏻‍🏫', '👨🏻‍🏭', '👨🏻‍💻', '👨🏻‍💼', '👨🏻‍🔧', '👨🏻‍🔬', '👨🏻‍🚀', '👨🏻‍🚒', '👨🏻‍🦯', '👨🏻‍🦰', '👨🏻‍🦱', '👨🏻‍🦲', '👨🏻‍🦳', '👨🏻‍🦼', '👨🏻‍🦽', '👨🏼‍🌾', '👨🏼‍🍳', '👨🏼‍🍼', '👨🏼‍🎄', '👨🏼‍🎓', '👨🏼‍🎤', '👨🏼‍🎨', '👨🏼‍🏫', '👨🏼‍🏭', '👨🏼‍💻', '👨🏼‍💼', '👨🏼‍🔧', '👨🏼‍🔬', '👨🏼‍🚀', '👨🏼‍🚒', '👨🏼‍🦯', '👨🏼‍🦰', '👨🏼‍🦱', '👨🏼‍🦲', '👨🏼‍🦳', '👨🏼‍🦼', '👨🏼‍🦽', '👨🏽‍🌾', '👨🏽‍🍳', '👨🏽‍🍼', '👨🏽‍🎄', '👨🏽‍🎓', '👨🏽‍🎤', '👨🏽‍🎨', '👨🏽‍🏫', '👨🏽‍🏭', '👨🏽‍💻', '👨🏽‍💼', '👨🏽‍🔧', '👨🏽‍🔬', '👨🏽‍🚀', '👨🏽‍🚒', '👨🏽‍🦯', '👨🏽‍🦰', '👨🏽‍🦱', '👨🏽‍🦲', '👨🏽‍🦳', '👨🏽‍🦼', '👨🏽‍🦽', '👨🏾‍🌾', '👨🏾‍🍳', '👨🏾‍🍼', '👨🏾‍🎄', '👨🏾‍🎓', '👨🏾‍🎤', '👨🏾‍🎨', '👨🏾‍🏫', '👨🏾‍🏭', '👨🏾‍💻', '👨🏾‍💼', '👨🏾‍🔧', '👨🏾‍🔬', '👨🏾‍🚀', '👨🏾‍🚒', '👨🏾‍🦯', '👨🏾‍🦰', '👨🏾‍🦱', '👨🏾‍🦲', '👨🏾‍🦳', '👨🏾‍🦼', '👨🏾‍🦽', '👨🏿‍🌾', '👨🏿‍🍳', '👨🏿‍🍼', '👨🏿‍🎄', '👨🏿‍🎓', '👨🏿‍🎤', '👨🏿‍🎨', '👨🏿‍🏫', '👨🏿‍🏭', '👨🏿‍💻', '👨🏿‍💼', '👨🏿‍🔧', '👨🏿‍🔬', '👨🏿‍🚀', '👨🏿‍🚒', '👨🏿‍🦯', '👨🏿‍🦰', '👨🏿‍🦱', '👨🏿‍🦲', '👨🏿‍🦳', '👨🏿‍🦼', '👨🏿‍🦽', '👩🏻‍🌾', '👩🏻‍🍳', '👩🏻‍🍼', '👩🏻‍🎄', '👩🏻‍🎓', '👩🏻‍🎤', '👩🏻‍🎨', '👩🏻‍🏫', '👩🏻‍🏭', '👩🏻‍💻', '👩🏻‍💼', '👩🏻‍🔧', '👩🏻‍🔬', '👩🏻‍🚀', '👩🏻‍🚒', '👩🏻‍🦯', '👩🏻‍🦰', '👩🏻‍🦱', '👩🏻‍🦲', '👩🏻‍🦳', '👩🏻‍🦼', '👩🏻‍🦽', '👩🏼‍🌾', '👩🏼‍🍳', '👩🏼‍🍼', '👩🏼‍🎄', '👩🏼‍🎓', '👩🏼‍🎤', '👩🏼‍🎨', '👩🏼‍🏫', '👩🏼‍🏭', '👩🏼‍💻', '👩🏼‍💼', '👩🏼‍🔧', '👩🏼‍🔬', '👩🏼‍🚀', '👩🏼‍🚒', '👩🏼‍🦯', '👩🏼‍🦰', '👩🏼‍🦱', '👩🏼‍🦲', '👩🏼‍🦳', '👩🏼‍🦼', '👩🏼‍🦽', '👩🏽‍🌾', '👩🏽‍🍳', '👩🏽‍🍼', '👩🏽‍🎄', '👩🏽‍🎓', '👩🏽‍🎤', '👩🏽‍🎨', '👩🏽‍🏫', '👩🏽‍🏭', '👩🏽‍💻', '👩🏽‍💼', '👩🏽‍🔧', '👩🏽‍🔬', '👩🏽‍🚀', '👩🏽‍🚒', '👩🏽‍🦯', '👩🏽‍🦰', '👩🏽‍🦱', '👩🏽‍🦲', '👩🏽‍🦳', '👩🏽‍🦼', '👩🏽‍🦽', '👩🏾‍🌾', '👩🏾‍🍳', '👩🏾‍🍼', '👩🏾‍🎄', '👩🏾‍🎓', '👩🏾‍🎤', '👩🏾‍🎨', '👩🏾‍🏫', '👩🏾‍🏭', '👩🏾‍💻', '👩🏾‍💼', '👩🏾‍🔧', '👩🏾‍🔬', '👩🏾‍🚀', '👩🏾‍🚒', '👩🏾‍🦯', '👩🏾‍🦰', '👩🏾‍🦱', '👩🏾‍🦲', '👩🏾‍🦳', '👩🏾‍🦼', '👩🏾‍🦽', '👩🏿‍🌾', '👩🏿‍🍳', '👩🏿‍🍼', '👩🏿‍🎄', '👩🏿‍🎓', '👩🏿‍🎤', '👩🏿‍🎨', '👩🏿‍🏫', '👩🏿‍🏭', '👩🏿‍💻', '👩🏿‍💼', '👩🏿‍🔧', '👩🏿‍🔬', '👩🏿‍🚀', '👩🏿‍🚒', '👩🏿‍🦯', '👩🏿‍🦰', '👩🏿‍🦱', '👩🏿‍🦲', '👩🏿‍🦳', '👩🏿‍🦼', '👩🏿‍🦽', '🧑🏻‍🌾', '🧑🏻‍🍳', '🧑🏻‍🍼', '🧑🏻‍🎄', '🧑🏻‍🎓', '🧑🏻‍🎤', '🧑🏻‍🎨', '🧑🏻‍🏫', '🧑🏻‍🏭', '🧑🏻‍💻', '🧑🏻‍💼', '🧑🏻‍🔧', '🧑🏻‍🔬', '🧑🏻‍🚀', '🧑🏻‍🚒', '🧑🏻‍🦯', '🧑🏻‍🦰', '🧑🏻‍🦱', '🧑🏻‍🦲', '🧑🏻‍🦳', '🧑🏻‍🦼', '🧑🏻‍🦽', '🧑🏻‍🩰', '🧑🏼‍🌾', '🧑🏼‍🍳', '🧑🏼‍🍼', '🧑🏼‍🎄', '🧑🏼‍🎓', '🧑🏼‍🎤', '🧑🏼‍🎨', '🧑🏼‍🏫', '🧑🏼‍🏭', '🧑🏼‍💻', '🧑🏼‍💼', '🧑🏼‍🔧', '🧑🏼‍🔬', '🧑🏼‍🚀', '🧑🏼‍🚒', '🧑🏼‍🦯', '🧑🏼‍🦰', '🧑🏼‍🦱', '🧑🏼‍🦲', '🧑🏼‍🦳', '🧑🏼‍🦼', '🧑🏼‍🦽', '🧑🏼‍🩰', '🧑🏽‍🌾', '🧑🏽‍🍳', '🧑🏽‍🍼', '🧑🏽‍🎄', '🧑🏽‍🎓', '🧑🏽‍🎤', '🧑🏽‍🎨', '🧑🏽‍🏫', '🧑🏽‍🏭', '🧑🏽‍💻', '🧑🏽‍💼', '🧑🏽‍🔧', '🧑🏽‍🔬', '🧑🏽‍🚀', '🧑🏽‍🚒', '🧑🏽‍🦯', '🧑🏽‍🦰', '🧑🏽‍🦱', '🧑🏽‍🦲', '🧑🏽‍🦳', '🧑🏽‍🦼', '🧑🏽‍🦽', '🧑🏽‍🩰', '🧑🏾‍🌾', '🧑🏾‍🍳', '🧑🏾‍🍼', '🧑🏾‍🎄', '🧑🏾‍🎓', '🧑🏾‍🎤', '🧑🏾‍🎨', '🧑🏾‍🏫', '🧑🏾‍🏭', '🧑🏾‍💻', '🧑🏾‍💼', '🧑🏾‍🔧', '🧑🏾‍🔬', '🧑🏾‍🚀', '🧑🏾‍🚒', '🧑🏾‍🦯', '🧑🏾‍🦰', '🧑🏾‍🦱', '🧑🏾‍🦲', '🧑🏾‍🦳', '🧑🏾‍🦼', '🧑🏾‍🦽', '🧑🏾‍🩰', '🧑🏿‍🌾', '🧑🏿‍🍳', '🧑🏿‍🍼', '🧑🏿‍🎄', '🧑🏿‍🎓', '🧑🏿‍🎤', '🧑🏿‍🎨', '🧑🏿‍🏫', '🧑🏿‍🏭', '🧑🏿‍💻', '🧑🏿‍💼', '🧑🏿‍🔧', '🧑🏿‍🔬', '🧑🏿‍🚀', '🧑🏿‍🚒', '🧑🏿‍🦯', '🧑🏿‍🦰', '🧑🏿‍🦱', '🧑🏿‍🦲', '🧑🏿‍🦳', '🧑🏿‍🦼', '🧑🏿‍🦽', '🧑🏿‍🩰', '🏳️‍🌈', '😶‍🌫️', '🏃‍♀️', '🏃‍♂️', '🏃‍➡️', '🏄‍♀️', '🏄‍♂️', '🏊‍♀️', '🏊‍♂️', '🏴‍☠️', '🐻‍❄️', '👨‍⚕️', '👨‍⚖️', '👨‍✈️', '👩‍⚕️', '👩‍⚖️', '👩‍✈️', '👮‍♀️', '👮‍♂️', '👯‍♀️', '👯‍♂️', '👰‍♀️', '👰‍♂️', '👱‍♀️', '👱‍♂️', '👳‍♀️', '👳‍♂️', '👷‍♀️', '👷‍♂️', '💁‍♀️', '💁‍♂️', '💂‍♀️', '💂‍♂️', '💆‍♀️', '💆‍♂️', '💇‍♀️', '💇‍♂️', '🙂‍↔️', '🙂‍↕️', '🙅‍♀️', '🙅‍♂️', '🙆‍♀️', '🙆‍♂️', '🙇‍♀️', '🙇‍♂️', '🙋‍♀️', '🙋‍♂️', '🙍‍♀️', '🙍‍♂️', '🙎‍♀️', '🙎‍♂️', '🚣‍♀️', '🚣‍♂️', '🚴‍♀️', '🚴‍♂️', '🚵‍♀️', '🚵‍♂️', '🚶‍♀️', '🚶‍♂️', '🚶‍➡️', '🤦‍♀️', '🤦‍♂️', '🤵‍♀️', '🤵‍♂️', '🤷‍♀️', '🤷‍♂️', '🤸‍♀️', '🤸‍♂️', '🤹‍♀️', '🤹‍♂️', '🤼‍♀️', '🤼‍♂️', '🤽‍♀️', '🤽‍♂️', '🤾‍♀️', '🤾‍♂️', '🦸‍♀️', '🦸‍♂️', '🦹‍♀️', '🦹‍♂️', '🧍‍♀️', '🧍‍♂️', '🧎‍♀️', '🧎‍♂️', '🧎‍➡️', '🧏‍♀️', '🧏‍♂️', '🧑‍⚕️', '🧑‍⚖️', '🧑‍✈️', '🧔‍♀️', '🧔‍♂️', '🧖‍♀️', '🧖‍♂️', '🧗‍♀️', '🧗‍♂️', '🧘‍♀️', '🧘‍♂️', '🧙‍♀️', '🧙‍♂️', '🧚‍♀️', '🧚‍♂️', '🧛‍♀️', '🧛‍♂️', '🧜‍♀️', '🧜‍♂️', '🧝‍♀️', '🧝‍♂️', '🧞‍♀️', '🧞‍♂️', '🧟‍♀️', '🧟‍♂️', '⛓️‍💥', '❤️‍🔥', '❤️‍🩹', '🍄‍🟫', '🍋‍🟩', '🐕‍🦺', '🐦‍🔥', '👁‍🗨', '👨‍🌾', '👨‍🍳', '👨‍🍼', '👨‍🎄', '👨‍🎓', '👨‍🎤', '👨‍🎨', '👨‍🏫', '👨‍🏭', '👨‍👦', '👨‍👧', '👨‍💻', '👨‍💼', '👨‍🔧', '👨‍🔬', '👨‍🚀', '👨‍🚒', '👨‍🦯', '👨‍🦰', '👨‍🦱', '👨‍🦲', '👨‍🦳', '👨‍🦼', '👨‍🦽', '👩‍🌾', '👩‍🍳', '👩‍🍼', '👩‍🎄', '👩‍🎓', '👩‍🎤', '👩‍🎨', '👩‍🏫', '👩‍🏭', '👩‍👦', '👩‍👧', '👩‍💻', '👩‍💼', '👩‍🔧', '👩‍🔬', '👩‍🚀', '👩‍🚒', '👩‍🦯', '👩‍🦰', '👩‍🦱', '👩‍🦲', '👩‍🦳', '👩‍🦼', '👩‍🦽', '😮‍💨', '😵‍💫', '🧑‍🌾', '🧑‍🍳', '🧑‍🍼', '🧑‍🎄', '🧑‍🎓', '🧑‍🎤', '🧑‍🎨', '🧑‍🏫', '🧑‍🏭', '🧑‍💻', '🧑‍💼', '🧑‍🔧', '🧑‍🔬', '🧑‍🚀', '🧑‍🚒', '🧑‍🦯', '🧑‍🦰', '🧑‍🦱', '🧑‍🦲', '🧑‍🦳', '🧑‍🦼', '🧑‍🦽', '🧑‍🧒', '🧑‍🩰', '🐈‍⬛', '🐦‍⬛', '🇦🇨', '🇦🇩', '🇦🇪', '🇦🇫', '🇦🇬', '🇦🇮', '🇦🇱', '🇦🇲', '🇦🇴', '🇦🇶', '🇦🇷', '🇦🇸', '🇦🇹', '🇦🇺', '🇦🇼', '🇦🇽', '🇦🇿', '🇧🇦', '🇧🇧', '🇧🇩', '🇧🇪', '🇧🇫', '🇧🇬', '🇧🇭', '🇧🇮', '🇧🇯', '🇧🇱', '🇧🇲', '🇧🇳', '🇧🇴', '🇧🇶', '🇧🇷', '🇧🇸', '🇧🇹', '🇧🇻', '🇧🇼', '🇧🇾', '🇧🇿', '🇨🇦', '🇨🇨', '🇨🇩', '🇨🇫', '🇨🇬', '🇨🇭', '🇨🇮', '🇨🇰', '🇨🇱', '🇨🇲', '🇨🇳', '🇨🇴', '🇨🇵', '🇨🇶', '🇨🇷', '🇨🇺', '🇨🇻', '🇨🇼', '🇨🇽', '🇨🇾', '🇨🇿', '🇩🇪', '🇩🇬', '🇩🇯', '🇩🇰', '🇩🇲', '🇩🇴', '🇩🇿', '🇪🇦', '🇪🇨', '🇪🇪', '🇪🇬', '🇪🇭', '🇪🇷', '🇪🇸', '🇪🇹', '🇪🇺', '🇫🇮', '🇫🇯', '🇫🇰', '🇫🇲', '🇫🇴', '🇫🇷', '🇬🇦', '🇬🇧', '🇬🇩', '🇬🇪', '🇬🇫', '🇬🇬', '🇬🇭', '🇬🇮', '🇬🇱', '🇬🇲', '🇬🇳', '🇬🇵', '🇬🇶', '🇬🇷', '🇬🇸', '🇬🇹', '🇬🇺', '🇬🇼', '🇬🇾', '🇭🇰', '🇭🇲', '🇭🇳', '🇭🇷', '🇭🇹', '🇭🇺', '🇮🇨', '🇮🇩', '🇮🇪', '🇮🇱', '🇮🇲', '🇮🇳', '🇮🇴', '🇮🇶', '🇮🇷', '🇮🇸', '🇮🇹', '🇯🇪', '🇯🇲', '🇯🇴', '🇯🇵', '🇰🇪', '🇰🇬', '🇰🇭', '🇰🇮', '🇰🇲', '🇰🇳', '🇰🇵', '🇰🇷', '🇰🇼', '🇰🇾', '🇰🇿', '🇱🇦', '🇱🇧', '🇱🇨', '🇱🇮', '🇱🇰', '🇱🇷', '🇱🇸', '🇱🇹', '🇱🇺', '🇱🇻', '🇱🇾', '🇲🇦', '🇲🇨', '🇲🇩', '🇲🇪', '🇲🇫', '🇲🇬', '🇲🇭', '🇲🇰', '🇲🇱', '🇲🇲', '🇲🇳', '🇲🇴', '🇲🇵', '🇲🇶', '🇲🇷', '🇲🇸', '🇲🇹', '🇲🇺', '🇲🇻', '🇲🇼', '🇲🇽', '🇲🇾', '🇲🇿', '🇳🇦', '🇳🇨', '🇳🇪', '🇳🇫', '🇳🇬', '🇳🇮', '🇳🇱', '🇳🇴', '🇳🇵', '🇳🇷', '🇳🇺', '🇳🇿', '🇴🇲', '🇵🇦', '🇵🇪', '🇵🇫', '🇵🇬', '🇵🇭', '🇵🇰', '🇵🇱', '🇵🇲', '🇵🇳', '🇵🇷', '🇵🇸', '🇵🇹', '🇵🇼', '🇵🇾', '🇶🇦', '🇷🇪', '🇷🇴', '🇷🇸', '🇷🇺', '🇷🇼', '🇸🇦', '🇸🇧', '🇸🇨', '🇸🇩', '🇸🇪', '🇸🇬', '🇸🇭', '🇸🇮', '🇸🇯', '🇸🇰', '🇸🇱', '🇸🇲', '🇸🇳', '🇸🇴', '🇸🇷', '🇸🇸', '🇸🇹', '🇸🇻', '🇸🇽', '🇸🇾', '🇸🇿', '🇹🇦', '🇹🇨', '🇹🇩', '🇹🇫', '🇹🇬', '🇹🇭', '🇹🇯', '🇹🇰', '🇹🇱', '🇹🇲', '🇹🇳', '🇹🇴', '🇹🇷', '🇹🇹', '🇹🇻', '🇹🇼', '🇹🇿', '🇺🇦', '🇺🇬', '🇺🇲', '🇺🇳', '🇺🇸', '🇺🇾', '🇺🇿', '🇻🇦', '🇻🇨', '🇻🇪', '🇻🇬', '🇻🇮', '🇻🇳', '🇻🇺', '🇼🇫', '🇼🇸', '🇽🇰', '🇾🇪', '🇾🇹', '🇿🇦', '🇿🇲', '🇿🇼', '🎅🏻', '🎅🏼', '🎅🏽', '🎅🏾', '🎅🏿', '🏂🏻', '🏂🏼', '🏂🏽', '🏂🏾', '🏂🏿', '🏃🏻', '🏃🏼', '🏃🏽', '🏃🏾', '🏃🏿', '🏄🏻', '🏄🏼', '🏄🏽', '🏄🏾', '🏄🏿', '🏇🏻', '🏇🏼', '🏇🏽', '🏇🏾', '🏇🏿', '🏊🏻', '🏊🏼', '🏊🏽', '🏊🏾', '🏊🏿', '🏋🏻', '🏋🏼', '🏋🏽', '🏋🏾', '🏋🏿', '🏌🏻', '🏌🏼', '🏌🏽', '🏌🏾', '🏌🏿', '👂🏻', '👂🏼', '👂🏽', '👂🏾', '👂🏿', '👃🏻', '👃🏼', '👃🏽', '👃🏾', '👃🏿', '👆🏻', '👆🏼', '👆🏽', '👆🏾', '👆🏿', '👇🏻', '👇🏼', '👇🏽', '👇🏾', '👇🏿', '👈🏻', '👈🏼', '👈🏽', '👈🏾', '👈🏿', '👉🏻', '👉🏼', '👉🏽', '👉🏾', '👉🏿', '👊🏻', '👊🏼', '👊🏽', '👊🏾', '👊🏿', '👋🏻', '👋🏼', '👋🏽', '👋🏾', '👋🏿', '👌🏻', '👌🏼', '👌🏽', '👌🏾', '👌🏿', '👍🏻', '👍🏼', '👍🏽', '👍🏾', '👍🏿', '👎🏻', '👎🏼', '👎🏽', '👎🏾', '👎🏿', '👏🏻', '👏🏼', '👏🏽', '👏🏾', '👏🏿', '👐🏻', '👐🏼', '👐🏽', '👐🏾', '👐🏿', '👦🏻', '👦🏼', '👦🏽', '👦🏾', '👦🏿', '👧🏻', '👧🏼', '👧🏽', '👧🏾', '👧🏿', '👨🏻', '👨🏼', '👨🏽', '👨🏾', '👨🏿', '👩🏻', '👩🏼', '👩🏽', '👩🏾', '👩🏿', '👫🏻', '👫🏼', '👫🏽', '👫🏾', '👫🏿', '👬🏻', '👬🏼', '👬🏽', '👬🏾', '👬🏿', '👭🏻', '👭🏼', '👭🏽', '👭🏾', '👭🏿', '👮🏻', '👮🏼', '👮🏽', '👮🏾', '👮🏿', '👯🏻', '👯🏼', '👯🏽', '👯🏾', '👯🏿', '👰🏻', '👰🏼', '👰🏽', '👰🏾', '👰🏿', '👱🏻', '👱🏼', '👱🏽', '👱🏾', '👱🏿', '👲🏻', '👲🏼', '👲🏽', '👲🏾', '👲🏿', '👳🏻', '👳🏼', '👳🏽', '👳🏾', '👳🏿', '👴🏻', '👴🏼', '👴🏽', '👴🏾', '👴🏿', '👵🏻', '👵🏼', '👵🏽', '👵🏾', '👵🏿', '👶🏻', '👶🏼', '👶🏽', '👶🏾', '👶🏿', '👷🏻', '👷🏼', '👷🏽', '👷🏾', '👷🏿', '👸🏻', '👸🏼', '👸🏽', '👸🏾', '👸🏿', '👼🏻', '👼🏼', '👼🏽', '👼🏾', '👼🏿', '💁🏻', '💁🏼', '💁🏽', '💁🏾', '💁🏿', '💂🏻', '💂🏼', '💂🏽', '💂🏾', '💂🏿', '💃🏻', '💃🏼', '💃🏽', '💃🏾', '💃🏿', '💅🏻', '💅🏼', '💅🏽', '💅🏾', '💅🏿', '💆🏻', '💆🏼', '💆🏽', '💆🏾', '💆🏿', '💇🏻', '💇🏼', '💇🏽', '💇🏾', '💇🏿', '💏🏻', '💏🏼', '💏🏽', '💏🏾', '💏🏿', '💑🏻', '💑🏼', '💑🏽', '💑🏾', '💑🏿', '💪🏻', '💪🏼', '💪🏽', '💪🏾', '💪🏿', '🕴🏻', '🕴🏼', '🕴🏽', '🕴🏾', '🕴🏿', '🕵🏻', '🕵🏼', '🕵🏽', '🕵🏾', '🕵🏿', '🕺🏻', '🕺🏼', '🕺🏽', '🕺🏾', '🕺🏿', '🖐🏻', '🖐🏼', '🖐🏽', '🖐🏾', '🖐🏿', '🖕🏻', '🖕🏼', '🖕🏽', '🖕🏾', '🖕🏿', '🖖🏻', '🖖🏼', '🖖🏽', '🖖🏾', '🖖🏿', '🙅🏻', '🙅🏼', '🙅🏽', '🙅🏾', '🙅🏿', '🙆🏻', '🙆🏼', '🙆🏽', '🙆🏾', '🙆🏿', '🙇🏻', '🙇🏼', '🙇🏽', '🙇🏾', '🙇🏿', '🙋🏻', '🙋🏼', '🙋🏽', '🙋🏾', '🙋🏿', '🙌🏻', '🙌🏼', '🙌🏽', '🙌🏾', '🙌🏿', '🙍🏻', '🙍🏼', '🙍🏽', '🙍🏾', '🙍🏿', '🙎🏻', '🙎🏼', '🙎🏽', '🙎🏾', '🙎🏿', '🙏🏻', '🙏🏼', '🙏🏽', '🙏🏾', '🙏🏿', '🚣🏻', '🚣🏼', '🚣🏽', '🚣🏾', '🚣🏿', '🚴🏻', '🚴🏼', '🚴🏽', '🚴🏾', '🚴🏿', '🚵🏻', '🚵🏼', '🚵🏽', '🚵🏾', '🚵🏿', '🚶🏻', '🚶🏼', '🚶🏽', '🚶🏾', '🚶🏿', '🛀🏻', '🛀🏼', '🛀🏽', '🛀🏾', '🛀🏿', '🛌🏻', '🛌🏼', '🛌🏽', '🛌🏾', '🛌🏿', '🤌🏻', '🤌🏼', '🤌🏽', '🤌🏾', '🤌🏿', '🤏🏻', '🤏🏼', '🤏🏽', '🤏🏾', '🤏🏿', '🤘🏻', '🤘🏼', '🤘🏽', '🤘🏾', '🤘🏿', '🤙🏻', '🤙🏼', '🤙🏽', '🤙🏾', '🤙🏿', '🤚🏻', '🤚🏼', '🤚🏽', '🤚🏾', '🤚🏿', '🤛🏻', '🤛🏼', '🤛🏽', '🤛🏾', '🤛🏿', '🤜🏻', '🤜🏼', '🤜🏽', '🤜🏾', '🤜🏿', '🤝🏻', '🤝🏼', '🤝🏽', '🤝🏾', '🤝🏿', '🤞🏻', '🤞🏼', '🤞🏽', '🤞🏾', '🤞🏿', '🤟🏻', '🤟🏼', '🤟🏽', '🤟🏾', '🤟🏿', '🤦🏻', '🤦🏼', '🤦🏽', '🤦🏾', '🤦🏿', '🤰🏻', '🤰🏼', '🤰🏽', '🤰🏾', '🤰🏿', '🤱🏻', '🤱🏼', '🤱🏽', '🤱🏾', '🤱🏿', '🤲🏻', '🤲🏼', '🤲🏽', '🤲🏾', '🤲🏿', '🤳🏻', '🤳🏼', '🤳🏽', '🤳🏾', '🤳🏿', '🤴🏻', '🤴🏼', '🤴🏽', '🤴🏾', '🤴🏿', '🤵🏻', '🤵🏼', '🤵🏽', '🤵🏾', '🤵🏿', '🤶🏻', '🤶🏼', '🤶🏽', '🤶🏾', '🤶🏿', '🤷🏻', '🤷🏼', '🤷🏽', '🤷🏾', '🤷🏿', '🤸🏻', '🤸🏼', '🤸🏽', '🤸🏾', '🤸🏿', '🤹🏻', '🤹🏼', '🤹🏽', '🤹🏾', '🤹🏿', '🤼🏻', '🤼🏼', '🤼🏽', '🤼🏾', '🤼🏿', '🤽🏻', '🤽🏼', '🤽🏽', '🤽🏾', '🤽🏿', '🤾🏻', '🤾🏼', '🤾🏽', '🤾🏾', '🤾🏿', '🥷🏻', '🥷🏼', '🥷🏽', '🥷🏾', '🥷🏿', '🦵🏻', '🦵🏼', '🦵🏽', '🦵🏾', '🦵🏿', '🦶🏻', '🦶🏼', '🦶🏽', '🦶🏾', '🦶🏿', '🦸🏻', '🦸🏼', '🦸🏽', '🦸🏾', '🦸🏿', '🦹🏻', '🦹🏼', '🦹🏽', '🦹🏾', '🦹🏿', '🦻🏻', '🦻🏼', '🦻🏽', '🦻🏾', '🦻🏿', '🧍🏻', '🧍🏼', '🧍🏽', '🧍🏾', '🧍🏿', '🧎🏻', '🧎🏼', '🧎🏽', '🧎🏾', '🧎🏿', '🧏🏻', '🧏🏼', '🧏🏽', '🧏🏾', '🧏🏿', '🧑🏻', '🧑🏼', '🧑🏽', '🧑🏾', '🧑🏿', '🧒🏻', '🧒🏼', '🧒🏽', '🧒🏾', '🧒🏿', '🧓🏻', '🧓🏼', '🧓🏽', '🧓🏾', '🧓🏿', '🧔🏻', '🧔🏼', '🧔🏽', '🧔🏾', '🧔🏿', '🧕🏻', '🧕🏼', '🧕🏽', '🧕🏾', '🧕🏿', '🧖🏻', '🧖🏼', '🧖🏽', '🧖🏾', '🧖🏿', '🧗🏻', '🧗🏼', '🧗🏽', '🧗🏾', '🧗🏿', '🧘🏻', '🧘🏼', '🧘🏽', '🧘🏾', '🧘🏿', '🧙🏻', '🧙🏼', '🧙🏽', '🧙🏾', '🧙🏿', '🧚🏻', '🧚🏼', '🧚🏽', '🧚🏾', '🧚🏿', '🧛🏻', '🧛🏼', '🧛🏽', '🧛🏾', '🧛🏿', '🧜🏻', '🧜🏼', '🧜🏽', '🧜🏾', '🧜🏿', '🧝🏻', '🧝🏼', '🧝🏽', '🧝🏾', '🧝🏿', '🫃🏻', '🫃🏼', '🫃🏽', '🫃🏾', '🫃🏿', '🫄🏻', '🫄🏼', '🫄🏽', '🫄🏾', '🫄🏿', '🫅🏻', '🫅🏼', '🫅🏽', '🫅🏾', '🫅🏿', '🫰🏻', '🫰🏼', '🫰🏽', '🫰🏾', '🫰🏿', '🫱🏻', '🫱🏼', '🫱🏽', '🫱🏾', '🫱🏿', '🫲🏻', '🫲🏼', '🫲🏽', '🫲🏾', '🫲🏿', '🫳🏻', '🫳🏼', '🫳🏽', '🫳🏾', '🫳🏿', '🫴🏻', '🫴🏼', '🫴🏽', '🫴🏾', '🫴🏿', '🫵🏻', '🫵🏼', '🫵🏽', '🫵🏾', '🫵🏿', '🫶🏻', '🫶🏼', '🫶🏽', '🫶🏾', '🫶🏿', '🫷🏻', '🫷🏼', '🫷🏽', '🫷🏾', '🫷🏿', '🫸🏻', '🫸🏼', '🫸🏽', '🫸🏾', '🫸🏿', '☝🏻', '☝🏼', '☝🏽', '☝🏾', '☝🏿', '⛷🏻', '⛷🏼', '⛷🏽', '⛷🏾', '⛷🏿', '⛹🏻', '⛹🏼', '⛹🏽', '⛹🏾', '⛹🏿', '✊🏻', '✊🏼', '✊🏽', '✊🏾', '✊🏿', '✋🏻', '✋🏼', '✋🏽', '✋🏾', '✋🏿', '✌🏻', '✌🏼', '✌🏽', '✌🏾', '✌🏿', '✍🏻', '✍🏼', '✍🏽', '✍🏾', '✍🏿', '#⃣', '*⃣', '0⃣', '1⃣', '2⃣', '3⃣', '4⃣', '5⃣', '6⃣', '7⃣', '8⃣', '9⃣', '🀄', '🃏', '🅰', '🅱', '🅾', '🅿', '🆎', '🆑', '🆒', '🆓', '🆔', '🆕', '🆖', '🆗', '🆘', '🆙', '🆚', '🇦', '🇧', '🇨', '🇩', '🇪', '🇫', '🇬', '🇭', '🇮', '🇯', '🇰', '🇱', '🇲', '🇳', '🇴', '🇵', '🇶', '🇷', '🇸', '🇹', '🇺', '🇻', '🇼', '🇽', '🇾', '🇿', '🈁', '🈂', '🈚', '🈯', '🈲', '🈳', '🈴', '🈵', '🈶', '🈷', '🈸', '🈹', '🈺', '🉐', '🉑', '🌀', '🌁', '🌂', '🌃', '🌄', '🌅', '🌆', '🌇', '🌈', '🌉', '🌊', '🌋', '🌌', '🌍', '🌎', '🌏', '🌐', '🌑', '🌒', '🌓', '🌔', '🌕', '🌖', '🌗', '🌘', '🌙', '🌚', '🌛', '🌜', '🌝', '🌞', '🌟', '🌠', '🌡', '🌤', '🌥', '🌦', '🌧', '🌨', '🌩', '🌪', '🌫', '🌬', '🌭', '🌮', '🌯', '🌰', '🌱', '🌲', '🌳', '🌴', '🌵', '🌶', '🌷', '🌸', '🌹', '🌺', '🌻', '🌼', '🌽', '🌾', '🌿', '🍀', '🍁', '🍂', '🍃', '🍄', '🍅', '🍆', '🍇', '🍈', '🍉', '🍊', '🍋', '🍌', '🍍', '🍎', '🍏', '🍐', '🍑', '🍒', '🍓', '🍔', '🍕', '🍖', '🍗', '🍘', '🍙', '🍚', '🍛', '🍜', '🍝', '🍞', '🍟', '🍠', '🍡', '🍢', '🍣', '🍤', '🍥', '🍦', '🍧', '🍨', '🍩', '🍪', '🍫', '🍬', '🍭', '🍮', '🍯', '🍰', '🍱', '🍲', '🍳', '🍴', '🍵', '🍶', '🍷', '🍸', '🍹', '🍺', '🍻', '🍼', '🍽', '🍾', '🍿', '🎀', '🎁', '🎂', '🎃', '🎄', '🎅', '🎆', '🎇', '🎈', '🎉', '🎊', '🎋', '🎌', '🎍', '🎎', '🎏', '🎐', '🎑', '🎒', '🎓', '🎖', '🎗', '🎙', '🎚', '🎛', '🎞', '🎟', '🎠', '🎡', '🎢', '🎣', '🎤', '🎥', '🎦', '🎧', '🎨', '🎩', '🎪', '🎫', '🎬', '🎭', '🎮', '🎯', '🎰', '🎱', '🎲', '🎳', '🎴', '🎵', '🎶', '🎷', '🎸', '🎹', '🎺', '🎻', '🎼', '🎽', '🎾', '🎿', '🏀', '🏁', '🏂', '🏃', '🏄', '🏅', '🏆', '🏇', '🏈', '🏉', '🏊', '🏋', '🏌', '🏍', '🏎', '🏏', '🏐', '🏑', '🏒', '🏓', '🏔', '🏕', '🏖', '🏗', '🏘', '🏙', '🏚', '🏛', '🏜', '🏝', '🏞', '🏟', '🏠', '🏡', '🏢', '🏣', '🏤', '🏥', '🏦', '🏧', '🏨', '🏩', '🏪', '🏫', '🏬', '🏭', '🏮', '🏯', '🏰', '🏳', '🏴', '🏵', '🏷', '🏸', '🏹', '🏺', '🏻', '🏼', '🏽', '🏾', '🏿', '🐀', '🐁', '🐂', '🐃', '🐄', '🐅', '🐆', '🐇', '🐈', '🐉', '🐊', '🐋', '🐌', '🐍', '🐎', '🐏', '🐐', '🐑', '🐒', '🐓', '🐔', '🐕', '🐖', '🐗', '🐘', '🐙', '🐚', '🐛', '🐜', '🐝', '🐞', '🐟', '🐠', '🐡', '🐢', '🐣', '🐤', '🐥', '🐦', '🐧', '🐨', '🐩', '🐪', '🐫', '🐬', '🐭', '🐮', '🐯', '🐰', '🐱', '🐲', '🐳', '🐴', '🐵', '🐶', '🐷', '🐸', '🐹', '🐺', '🐻', '🐼', '🐽', '🐾', '🐿', '👀', '👁', '👂', '👃', '👄', '👅', '👆', '👇', '👈', '👉', '👊', '👋', '👌', '👍', '👎', '👏', '👐', '👑', '👒', '👓', '👔', '👕', '👖', '👗', '👘', '👙', '👚', '👛', '👜', '👝', '👞', '👟', '👠', '👡', '👢', '👣', '👤', '👥', '👦', '👧', '👨', '👩', '👪', '👫', '👬', '👭', '👮', '👯', '👰', '👱', '👲', '👳', '👴', '👵', '👶', '👷', '👸', '👹', '👺', '👻', '👼', '👽', '👾', '👿', '💀', '💁', '💂', '💃', '💄', '💅', '💆', '💇', '💈', '💉', '💊', '💋', '💌', '💍', '💎', '💏', '💐', '💑', '💒', '💓', '💔', '💕', '💖', '💗', '💘', '💙', '💚', '💛', '💜', '💝', '💞', '💟', '💠', '💡', '💢', '💣', '💤', '💥', '💦', '💧', '💨', '💩', '💪', '💫', '💬', '💭', '💮', '💯', '💰', '💱', '💲', '💳', '💴', '💵', '💶', '💷', '💸', '💹', '💺', '💻', '💼', '💽', '💾', '💿', '📀', '📁', '📂', '📃', '📄', '📅', '📆', '📇', '📈', '📉', '📊', '📋', '📌', '📍', '📎', '📏', '📐', '📑', '📒', '📓', '📔', '📕', '📖', '📗', '📘', '📙', '📚', '📛', '📜', '📝', '📞', '📟', '📠', '📡', '📢', '📣', '📤', '📥', '📦', '📧', '📨', '📩', '📪', '📫', '📬', '📭', '📮', '📯', '📰', '📱', '📲', '📳', '📴', '📵', '📶', '📷', '📸', '📹', '📺', '📻', '📼', '📽', '📿', '🔀', '🔁', '🔂', '🔃', '🔄', '🔅', '🔆', '🔇', '🔈', '🔉', '🔊', '🔋', '🔌', '🔍', '🔎', '🔏', '🔐', '🔑', '🔒', '🔓', '🔔', '🔕', '🔖', '🔗', '🔘', '🔙', '🔚', '🔛', '🔜', '🔝', '🔞', '🔟', '🔠', '🔡', '🔢', '🔣', '🔤', '🔥', '🔦', '🔧', '🔨', '🔩', '🔪', '🔫', '🔬', '🔭', '🔮', '🔯', '🔰', '🔱', '🔲', '🔳', '🔴', '🔵', '🔶', '🔷', '🔸', '🔹', '🔺', '🔻', '🔼', '🔽', '🕉', '🕊', '🕋', '🕌', '🕍', '🕎', '🕐', '🕑', '🕒', '🕓', '🕔', '🕕', '🕖', '🕗', '🕘', '🕙', '🕚', '🕛', '🕜', '🕝', '🕞', '🕟', '🕠', '🕡', '🕢', '🕣', '🕤', '🕥', '🕦', '🕧', '🕯', '🕰', '🕳', '🕴', '🕵', '🕶', '🕷', '🕸', '🕹', '🕺', '🖇', '🖊', '🖋', '🖌', '🖍', '🖐', '🖕', '🖖', '🖤', '🖥', '🖨', '🖱', '🖲', '🖼', '🗂', '🗃', '🗄', '🗑', '🗒', '🗓', '🗜', '🗝', '🗞', '🗡', '🗣', '🗨', '🗯', '🗳', '🗺', '🗻', '🗼', '🗽', '🗾', '🗿', '😀', '😁', '😂', '😃', '😄', '😅', '😆', '😇', '😈', '😉', '😊', '😋', '😌', '😍', '😎', '😏', '😐', '😑', '😒', '😓', '😔', '😕', '😖', '😗', '😘', '😙', '😚', '😛', '😜', '😝', '😞', '😟', '😠', '😡', '😢', '😣', '😤', '😥', '😦', '😧', '😨', '😩', '😪', '😫', '😬', '😭', '😮', '😯', '😰', '😱', '😲', '😳', '😴', '😵', '😶', '😷', '😸', '😹', '😺', '😻', '😼', '😽', '😾', '😿', '🙀', '🙁', '🙂', '🙃', '🙄', '🙅', '🙆', '🙇', '🙈', '🙉', '🙊', '🙋', '🙌', '🙍', '🙎', '🙏', '🚀', '🚁', '🚂', '🚃', '🚄', '🚅', '🚆', '🚇', '🚈', '🚉', '🚊', '🚋', '🚌', '🚍', '🚎', '🚏', '🚐', '🚑', '🚒', '🚓', '🚔', '🚕', '🚖', '🚗', '🚘', '🚙', '🚚', '🚛', '🚜', '🚝', '🚞', '🚟', '🚠', '🚡', '🚢', '🚣', '🚤', '🚥', '🚦', '🚧', '🚨', '🚩', '🚪', '🚫', '🚬', '🚭', '🚮', '🚯', '🚰', '🚱', '🚲', '🚳', '🚴', '🚵', '🚶', '🚷', '🚸', '🚹', '🚺', '🚻', '🚼', '🚽', '🚾', '🚿', '🛀', '🛁', '🛂', '🛃', '🛄', '🛅', '🛋', '🛌', '🛍', '🛎', '🛏', '🛐', '🛑', '🛒', '🛕', '🛖', '🛗', '🛘', '🛜', '🛝', '🛞', '🛟', '🛠', '🛡', '🛢', '🛣', '🛤', '🛥', '🛩', '🛫', '🛬', '🛰', '🛳', '🛴', '🛵', '🛶', '🛷', '🛸', '🛹', '🛺', '🛻', '🛼', '🟠', '🟡', '🟢', '🟣', '🟤', '🟥', '🟦', '🟧', '🟨', '🟩', '🟪', '🟫', '🟰', '🤌', '🤍', '🤎', '🤏', '🤐', '🤑', '🤒', '🤓', '🤔', '🤕', '🤖', '🤗', '🤘', '🤙', '🤚', '🤛', '🤜', '🤝', '🤞', '🤟', '🤠', '🤡', '🤢', '🤣', '🤤', '🤥', '🤦', '🤧', '🤨', '🤩', '🤪', '🤫', '🤬', '🤭', '🤮', '🤯', '🤰', '🤱', '🤲', '🤳', '🤴', '🤵', '🤶', '🤷', '🤸', '🤹', '🤺', '🤼', '🤽', '🤾', '🤿', '🥀', '🥁', '🥂', '🥃', '🥄', '🥅', '🥇', '🥈', '🥉', '🥊', '🥋', '🥌', '🥍', '🥎', '🥏', '🥐', '🥑', '🥒', '🥓', '🥔', '🥕', '🥖', '🥗', '🥘', '🥙', '🥚', '🥛', '🥜', '🥝', '🥞', '🥟', '🥠', '🥡', '🥢', '🥣', '🥤', '🥥', '🥦', '🥧', '🥨', '🥩', '🥪', '🥫', '🥬', '🥭', '🥮', '🥯', '🥰', '🥱', '🥲', '🥳', '🥴', '🥵', '🥶', '🥷', '🥸', '🥹', '🥺', '🥻', '🥼', '🥽', '🥾', '🥿', '🦀', '🦁', '🦂', '🦃', '🦄', '🦅', '🦆', '🦇', '🦈', '🦉', '🦊', '🦋', '🦌', '🦍', '🦎', '🦏', '🦐', '🦑', '🦒', '🦓', '🦔', '🦕', '🦖', '🦗', '🦘', '🦙', '🦚', '🦛', '🦜', '🦝', '🦞', '🦟', '🦠', '🦡', '🦢', '🦣', '🦤', '🦥', '🦦', '🦧', '🦨', '🦩', '🦪', '🦫', '🦬', '🦭', '🦮', '🦯', '🦰', '🦱', '🦲', '🦳', '🦴', '🦵', '🦶', '🦷', '🦸', '🦹', '🦺', '🦻', '🦼', '🦽', '🦾', '🦿', '🧀', '🧁', '🧂', '🧃', '🧄', '🧅', '🧆', '🧇', '🧈', '🧉', '🧊', '🧋', '🧌', '🧍', '🧎', '🧏', '🧐', '🧑', '🧒', '🧓', '🧔', '🧕', '🧖', '🧗', '🧘', '🧙', '🧚', '🧛', '🧜', '🧝', '🧞', '🧟', '🧠', '🧡', '🧢', '🧣', '🧤', '🧥', '🧦', '🧧', '🧨', '🧩', '🧪', '🧫', '🧬', '🧭', '🧮', '🧯', '🧰', '🧱', '🧲', '🧳', '🧴', '🧵', '🧶', '🧷', '🧸', '🧹', '🧺', '🧻', '🧼', '🧽', '🧾', '🧿', '🩰', '🩱', '🩲', '🩳', '🩴', '🩵', '🩶', '🩷', '🩸', '🩹', '🩺', '🩻', '🩼', '🪀', '🪁', '🪂', '🪃', '🪄', '🪅', '🪆', '🪇', '🪈', '🪉', '🪊', '🪎', '🪏', '🪐', '🪑', '🪒', '🪓', '🪔', '🪕', '🪖', '🪗', '🪘', '🪙', '🪚', '🪛', '🪜', '🪝', '🪞', '🪟', '🪠', '🪡', '🪢', '🪣', '🪤', '🪥', '🪦', '🪧', '🪨', '🪩', '🪪', '🪫', '🪬', '🪭', '🪮', '🪯', '🪰', '🪱', '🪲', '🪳', '🪴', '🪵', '🪶', '🪷', '🪸', '🪹', '🪺', '🪻', '🪼', '🪽', '🪾', '🪿', '🫀', '🫁', '🫂', '🫃', '🫄', '🫅', '🫆', '🫈', '🫍', '🫎', '🫏', '🫐', '🫑', '🫒', '🫓', '🫔', '🫕', '🫖', '🫗', '🫘', '🫙', '🫚', '🫛', '🫜', '🫟', '🫠', '🫡', '🫢', '🫣', '🫤', '🫥', '🫦', '🫧', '🫨', '🫩', '🫪', '🫯', '🫰', '🫱', '🫲', '🫳', '🫴', '🫵', '🫶', '🫷', '🫸', '‼', '⁉', '™', 'ℹ', '↔', '↕', '↖', '↗', '↘', '↙', '↩', '↪', '⌚', '⌛', '⌨', '⏏', '⏩', '⏪', '⏫', '⏬', '⏭', '⏮', '⏯', '⏰', '⏱', '⏲', '⏳', '⏸', '⏹', '⏺', 'Ⓜ', '▪', '▫', '▶', '◀', '◻', '◼', '◽', '◾', '☀', '☁', '☂', '☃', '☄', '☎', '☑', '☔', '☕', '☘', '☝', '☠', '☢', '☣', '☦', '☪', '☮', '☯', '☸', '☹', '☺', '♀', '♂', '♈', '♉', '♊', '♋', '♌', '♍', '♎', '♏', '♐', '♑', '♒', '♓', '♟', '♠', '♣', '♥', '♦', '♨', '♻', '♾', '♿', '⚒', '⚓', '⚔', '⚕', '⚖', '⚗', '⚙', '⚛', '⚜', '⚠', '⚡', '⚧', '⚪', '⚫', '⚰', '⚱', '⚽', '⚾', '⛄', '⛅', '⛈', '⛎', '⛏', '⛑', '⛓', '⛔', '⛩', '⛪', '⛰', '⛱', '⛲', '⛳', '⛴', '⛵', '⛷', '⛸', '⛹', '⛺', '⛽', '✂', '✅', '✈', '✉', '✊', '✋', '✌', '✍', '✏', '✒', '✔', '✖', '✝', '✡', '✨', '✳', '✴', '❄', '❇', '❌', '❎', '❓', '❔', '❕', '❗', '❣', '❤', '➕', '➖', '➗', '➡', '➰', '➿', '⤴', '⤵', '⬅', '⬆', '⬇', '⬛', '⬜', '⭐', '⭕', '〰', '〽', '㊗', '㊙', '' );
6208 $partials = array( '🀄', '🃏', '🅰', '🅱', '🅾', '🅿', '🆎', '🆑', '🆒', '🆓', '🆔', '🆕', '🆖', '🆗', '🆘', '🆙', '🆚', '🇦', '🇨', '🇩', '🇪', '🇫', '🇬', '🇮', '🇱', '🇲', '🇴', '🇶', '🇷', '🇸', '🇹', '🇺', '🇼', '🇽', '🇿', '🇧', '🇭', '🇯', '🇳', '🇻', '🇾', '🇰', '🇵', '🈁', '🈂', '🈚', '🈯', '🈲', '🈳', '🈴', '🈵', '🈶', '🈷', '🈸', '🈹', '🈺', '🉐', '🉑', '🌀', '🌁', '🌂', '🌃', '🌄', '🌅', '🌆', '🌇', '🌈', '🌉', '🌊', '🌋', '🌌', '🌍', '🌎', '🌏', '🌐', '🌑', '🌒', '🌓', '🌔', '🌕', '🌖', '🌗', '🌘', '🌙', '🌚', '🌛', '🌜', '🌝', '🌞', '🌟', '🌠', '🌡', '🌤', '🌥', '🌦', '🌧', '🌨', '🌩', '🌪', '🌫', '🌬', '🌭', '🌮', '🌯', '🌰', '🌱', '🌲', '🌳', '🌴', '🌵', '🌶', '🌷', '🌸', '🌹', '🌺', '🌻', '🌼', '🌽', '🌾', '🌿', '🍀', '🍁', '🍂', '🍃', '🍄', '‍', '🟫', '🍅', '🍆', '🍇', '🍈', '🍉', '🍊', '🍋', '🟩', '🍌', '🍍', '🍎', '🍏', '🍐', '🍑', '🍒', '🍓', '🍔', '🍕', '🍖', '🍗', '🍘', '🍙', '🍚', '🍛', '🍜', '🍝', '🍞', '🍟', '🍠', '🍡', '🍢', '🍣', '🍤', '🍥', '🍦', '🍧', '🍨', '🍩', '🍪', '🍫', '🍬', '🍭', '🍮', '🍯', '🍰', '🍱', '🍲', '🍳', '🍴', '🍵', '🍶', '🍷', '🍸', '🍹', '🍺', '🍻', '🍼', '🍽', '🍾', '🍿', '🎀', '🎁', '🎂', '🎃', '🎄', '🎅', '🏻', '🏼', '🏽', '🏾', '🏿', '🎆', '🎇', '🎈', '🎉', '🎊', '🎋', '🎌', '🎍', '🎎', '🎏', '🎐', '🎑', '🎒', '🎓', '🎖', '🎗', '🎙', '🎚', '🎛', '🎞', '🎟', '🎠', '🎡', '🎢', '🎣', '🎤', '🎥', '🎦', '🎧', '🎨', '🎩', '🎪', '🎫', '🎬', '🎭', '🎮', '🎯', '🎰', '🎱', '🎲', '🎳', '🎴', '🎵', '🎶', '🎷', '🎸', '🎹', '🎺', '🎻', '🎼', '🎽', '🎾', '🎿', '🏀', '🏁', '🏂', '🏃', '♀', '️', '➡', '♂', '🏄', '🏅', '🏆', '🏇', '🏈', '🏉', '🏊', '🏋', '🏌', '🏍', '🏎', '🏏', '🏐', '🏑', '🏒', '🏓', '🏔', '🏕', '🏖', '🏗', '🏘', '🏙', '🏚', '🏛', '🏜', '🏝', '🏞', '🏟', '🏠', '🏡', '🏢', '🏣', '🏤', '🏥', '🏦', '🏧', '🏨', '🏩', '🏪', '🏫', '🏬', '🏭', '🏮', '🏯', '🏰', '🏳', '⚧', '🏴', '☠', '󠁧', '󠁢', '󠁥', '󠁮', '󠁿', '󠁳', '󠁣', '󠁴', '󠁷', '󠁬', '🏵', '🏷', '🏸', '🏹', '🏺', '🐀', '🐁', '🐂', '🐃', '🐄', '🐅', '🐆', '🐇', '🐈', '⬛', '🐉', '🐊', '🐋', '🐌', '🐍', '🐎', '🐏', '🐐', '🐑', '🐒', '🐓', '🐔', '🐕', '🦺', '🐖', '🐗', '🐘', '🐙', '🐚', '🐛', '🐜', '🐝', '🐞', '🐟', '🐠', '🐡', '🐢', '🐣', '🐤', '🐥', '🐦', '🔥', '🐧', '🐨', '🐩', '🐪', '🐫', '🐬', '🐭', '🐮', '🐯', '🐰', '🐱', '🐲', '🐳', '🐴', '🐵', '🐶', '🐷', '🐸', '🐹', '🐺', '🐻', '❄', '🐼', '🐽', '🐾', '🐿', '👀', '👁', '🗨', '👂', '👃', '👄', '👅', '👆', '👇', '👈', '👉', '👊', '👋', '👌', '👍', '👎', '👏', '👐', '👑', '👒', '👓', '👔', '👕', '👖', '👗', '👘', '👙', '👚', '👛', '👜', '👝', '👞', '👟', '👠', '👡', '👢', '👣', '👤', '👥', '👦', '👧', '👨', '💻', '💼', '🔧', '🔬', '🚀', '🚒', '🤝', '🦯', '🦰', '🦱', '🦲', '🦳', '🦼', '🦽', '🫯', '⚕', '⚖', '✈', '❤', '💋', '👩', '👪', '👫', '👬', '👭', '👮', '👯', '👰', '👱', '👲', '👳', '👴', '👵', '👶', '👷', '👸', '👹', '👺', '👻', '👼', '👽', '👾', '👿', '💀', '💁', '💂', '💃', '💄', '💅', '💆', '💇', '💈', '💉', '💊', '💌', '💍', '💎', '💏', '💐', '💑', '💒', '💓', '💔', '💕', '💖', '💗', '💘', '💙', '💚', '💛', '💜', '💝', '💞', '💟', '💠', '💡', '💢', '💣', '💤', '💥', '💦', '💧', '💨', '💩', '💪', '💫', '💬', '💭', '💮', '💯', '💰', '💱', '💲', '💳', '💴', '💵', '💶', '💷', '💸', '💹', '💺', '💽', '💾', '💿', '📀', '📁', '📂', '📃', '📄', '📅', '📆', '📇', '📈', '📉', '📊', '📋', '📌', '📍', '📎', '📏', '📐', '📑', '📒', '📓', '📔', '📕', '📖', '📗', '📘', '📙', '📚', '📛', '📜', '📝', '📞', '📟', '📠', '📡', '📢', '📣', '📤', '📥', '📦', '📧', '📨', '📩', '📪', '📫', '📬', '📭', '📮', '📯', '📰', '📱', '📲', '📳', '📴', '📵', '📶', '📷', '📸', '📹', '📺', '📻', '📼', '📽', '📿', '🔀', '🔁', '🔂', '🔃', '🔄', '🔅', '🔆', '🔇', '🔈', '🔉', '🔊', '🔋', '🔌', '🔍', '🔎', '🔏', '🔐', '🔑', '🔒', '🔓', '🔔', '🔕', '🔖', '🔗', '🔘', '🔙', '🔚', '🔛', '🔜', '🔝', '🔞', '🔟', '🔠', '🔡', '🔢', '🔣', '🔤', '🔦', '🔨', '🔩', '🔪', '🔫', '🔭', '🔮', '🔯', '🔰', '🔱', '🔲', '🔳', '🔴', '🔵', '🔶', '🔷', '🔸', '🔹', '🔺', '🔻', '🔼', '🔽', '🕉', '🕊', '🕋', '🕌', '🕍', '🕎', '🕐', '🕑', '🕒', '🕓', '🕔', '🕕', '🕖', '🕗', '🕘', '🕙', '🕚', '🕛', '🕜', '🕝', '🕞', '🕟', '🕠', '🕡', '🕢', '🕣', '🕤', '🕥', '🕦', '🕧', '🕯', '🕰', '🕳', '🕴', '🕵', '🕶', '🕷', '🕸', '🕹', '🕺', '🖇', '🖊', '🖋', '🖌', '🖍', '🖐', '🖕', '🖖', '🖤', '🖥', '🖨', '🖱', '🖲', '🖼', '🗂', '🗃', '🗄', '🗑', '🗒', '🗓', '🗜', '🗝', '🗞', '🗡', '🗣', '🗯', '🗳', '🗺', '🗻', '🗼', '🗽', '🗾', '🗿', '😀', '😁', '😂', '😃', '😄', '😅', '😆', '😇', '😈', '😉', '😊', '😋', '😌', '😍', '😎', '😏', '😐', '😑', '😒', '😓', '😔', '😕', '😖', '😗', '😘', '😙', '😚', '😛', '😜', '😝', '😞', '😟', '😠', '😡', '😢', '😣', '😤', '😥', '😦', '😧', '😨', '😩', '😪', '😫', '😬', '😭', '😮', '😯', '😰', '😱', '😲', '😳', '😴', '😵', '😶', '😷', '😸', '😹', '😺', '😻', '😼', '😽', '😾', '😿', '🙀', '🙁', '🙂', '↔', '↕', '🙃', '🙄', '🙅', '🙆', '🙇', '🙈', '🙉', '🙊', '🙋', '🙌', '🙍', '🙎', '🙏', '🚁', '🚂', '🚃', '🚄', '🚅', '🚆', '🚇', '🚈', '🚉', '🚊', '🚋', '🚌', '🚍', '🚎', '🚏', '🚐', '🚑', '🚓', '🚔', '🚕', '🚖', '🚗', '🚘', '🚙', '🚚', '🚛', '🚜', '🚝', '🚞', '🚟', '🚠', '🚡', '🚢', '🚣', '🚤', '🚥', '🚦', '🚧', '🚨', '🚩', '🚪', '🚫', '🚬', '🚭', '🚮', '🚯', '🚰', '🚱', '🚲', '🚳', '🚴', '🚵', '🚶', '🚷', '🚸', '🚹', '🚺', '🚻', '🚼', '🚽', '🚾', '🚿', '🛀', '🛁', '🛂', '🛃', '🛄', '🛅', '🛋', '🛌', '🛍', '🛎', '🛏', '🛐', '🛑', '🛒', '🛕', '🛖', '🛗', '🛘', '🛜', '🛝', '🛞', '🛟', '🛠', '🛡', '🛢', '🛣', '🛤', '🛥', '🛩', '🛫', '🛬', '🛰', '🛳', '🛴', '🛵', '🛶', '🛷', '🛸', '🛹', '🛺', '🛻', '🛼', '🟠', '🟡', '🟢', '🟣', '🟤', '🟥', '🟦', '🟧', '🟨', '🟪', '🟰', '🤌', '🤍', '🤎', '🤏', '🤐', '🤑', '🤒', '🤓', '🤔', '🤕', '🤖', '🤗', '🤘', '🤙', '🤚', '🤛', '🤜', '🤞', '🤟', '🤠', '🤡', '🤢', '🤣', '🤤', '🤥', '🤦', '🤧', '🤨', '🤩', '🤪', '🤫', '🤬', '🤭', '🤮', '🤯', '🤰', '🤱', '🤲', '🤳', '🤴', '🤵', '🤶', '🤷', '🤸', '🤹', '🤺', '🤼', '🤽', '🤾', '🤿', '🥀', '🥁', '🥂', '🥃', '🥄', '🥅', '🥇', '🥈', '🥉', '🥊', '🥋', '🥌', '🥍', '🥎', '🥏', '🥐', '🥑', '🥒', '🥓', '🥔', '🥕', '🥖', '🥗', '🥘', '🥙', '🥚', '🥛', '🥜', '🥝', '🥞', '🥟', '🥠', '🥡', '🥢', '🥣', '🥤', '🥥', '🥦', '🥧', '🥨', '🥩', '🥪', '🥫', '🥬', '🥭', '🥮', '🥯', '🥰', '🥱', '🥲', '🥳', '🥴', '🥵', '🥶', '🥷', '🥸', '🥹', '🥺', '🥻', '🥼', '🥽', '🥾', '🥿', '🦀', '🦁', '🦂', '🦃', '🦄', '🦅', '🦆', '🦇', '🦈', '🦉', '🦊', '🦋', '🦌', '🦍', '🦎', '🦏', '🦐', '🦑', '🦒', '🦓', '🦔', '🦕', '🦖', '🦗', '🦘', '🦙', '🦚', '🦛', '🦜', '🦝', '🦞', '🦟', '🦠', '🦡', '🦢', '🦣', '🦤', '🦥', '🦦', '🦧', '🦨', '🦩', '🦪', '🦫', '🦬', '🦭', '🦮', '🦴', '🦵', '🦶', '🦷', '🦸', '🦹', '🦻', '🦾', '🦿', '🧀', '🧁', '🧂', '🧃', '🧄', '🧅', '🧆', '🧇', '🧈', '🧉', '🧊', '🧋', '🧌', '🧍', '🧎', '🧏', '🧐', '🧑', '🩰', '🧒', '🧓', '🧔', '🧕', '🧖', '🧗', '🧘', '🧙', '🧚', '🧛', '🧜', '🧝', '🧞', '🧟', '🧠', '🧡', '🧢', '🧣', '🧤', '🧥', '🧦', '🧧', '🧨', '🧩', '🧪', '🧫', '🧬', '🧭', '🧮', '🧯', '🧰', '🧱', '🧲', '🧳', '🧴', '🧵', '🧶', '🧷', '🧸', '🧹', '🧺', '🧻', '🧼', '🧽', '🧾', '🧿', '🩱', '🩲', '🩳', '🩴', '🩵', '🩶', '🩷', '🩸', '🩹', '🩺', '🩻', '🩼', '🪀', '🪁', '🪂', '🪃', '🪄', '🪅', '🪆', '🪇', '🪈', '🪉', '🪊', '🪎', '🪏', '🪐', '🪑', '🪒', '🪓', '🪔', '🪕', '🪖', '🪗', '🪘', '🪙', '🪚', '🪛', '🪜', '🪝', '🪞', '🪟', '🪠', '🪡', '🪢', '🪣', '🪤', '🪥', '🪦', '🪧', '🪨', '🪩', '🪪', '🪫', '🪬', '🪭', '🪮', '🪯', '🪰', '🪱', '🪲', '🪳', '🪴', '🪵', '🪶', '🪷', '🪸', '🪹', '🪺', '🪻', '🪼', '🪽', '🪾', '🪿', '🫀', '🫁', '🫂', '🫃', '🫄', '🫅', '🫆', '🫈', '🫍', '🫎', '🫏', '🫐', '🫑', '🫒', '🫓', '🫔', '🫕', '🫖', '🫗', '🫘', '🫙', '🫚', '🫛', '🫜', '🫟', '🫠', '🫡', '🫢', '🫣', '🫤', '🫥', '🫦', '🫧', '🫨', '🫩', '🫪', '🫰', '🫱', '🫲', '🫳', '🫴', '🫵', '🫶', '🫷', '🫸', '‼', '⁉', '™', 'ℹ', '↖', '↗', '↘', '↙', '↩', '↪', '⃣', '⌚', '⌛', '⌨', '⏏', '⏩', '⏪', '⏫', '⏬', '⏭', '⏮', '⏯', '⏰', '⏱', '⏲', '⏳', '⏸', '⏹', '⏺', 'Ⓜ', '▪', '▫', '▶', '◀', '◻', '◼', '◽', '◾', '☀', '☁', '☂', '☃', '☄', '☎', '☑', '☔', '☕', '☘', '☝', '☢', '☣', '☦', '☪', '☮', '☯', '☸', '☹', '☺', '♈', '♉', '♊', '♋', '♌', '♍', '♎', '♏', '♐', '♑', '♒', '♓', '♟', '♠', '♣', '♥', '♦', '♨', '♻', '♾', '♿', '⚒', '⚓', '⚔', '⚗', '⚙', '⚛', '⚜', '⚠', '⚡', '⚪', '⚫', '⚰', '⚱', '⚽', '⚾', '⛄', '⛅', '⛈', '⛎', '⛏', '⛑', '⛓', '⛔', '⛩', '⛪', '⛰', '⛱', '⛲', '⛳', '⛴', '⛵', '⛷', '⛸', '⛹', '⛺', '⛽', '✂', '✅', '✉', '✊', '✋', '✌', '✍', '✏', '✒', '✔', '✖', '✝', '✡', '✨', '✳', '✴', '❇', '❌', '❎', '❓', '❔', '❕', '❗', '❣', '➕', '➖', '➗', '➰', '➿', '⤴', '⤵', '⬅', '⬆', '⬇', '⬜', '⭐', '⭕', '〰', '〽', '㊗', '㊙', '' );
6209 // END: emoji arrays
6210
6211 if ( 'entities' === $type ) {
6212 return $entities;
6213 }
6214
6215 return $partials;
6216}
6217
6218/**
6219 * Shortens a URL, to be used as link text.
6220 *
6221 * @since 1.2.0
6222 * @since 4.4.0 Moved to wp-includes/formatting.php from wp-admin/includes/misc.php and added $length param.
6223 *
6224 * @param string $url URL to shorten.
6225 * @param int $length Optional. Maximum length of the shortened URL. Default 35 characters.
6226 * @return string Shortened URL.
6227 */
6228function url_shorten( $url, $length = 35 ) {
6229 $stripped = str_replace( array( 'https://', 'http://', 'www.' ), '', $url );
6230 $short_url = untrailingslashit( $stripped );
6231
6232 if ( strlen( $short_url ) > $length ) {
6233 $short_url = substr( $short_url, 0, $length - 3 ) . '…';
6234 }
6235 return $short_url;
6236}
6237
6238/**
6239 * Sanitizes a hex color.
6240 *
6241 * Returns either '', a 3 or 6 digit hex color (with #), or nothing.
6242 * For sanitizing values without a #, see sanitize_hex_color_no_hash().
6243 *
6244 * @since 3.4.0
6245 *
6246 * @param string $color
6247 * @return string|void
6248 */
6249function sanitize_hex_color( $color ) {
6250 if ( '' === $color ) {
6251 return '';
6252 }
6253
6254 // 3 or 6 hex digits, or the empty string.
6255 if ( preg_match( '|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) ) {
6256 return $color;
6257 }
6258}
6259
6260/**
6261 * Sanitizes a hex color without a hash. Use sanitize_hex_color() when possible.
6262 *
6263 * Saving hex colors without a hash puts the burden of adding the hash on the
6264 * UI, which makes it difficult to use or upgrade to other color types such as
6265 * rgba, hsl, rgb, and HTML color names.
6266 *
6267 * Returns either '', a 3 or 6 digit hex color (without a #), or null.
6268 *
6269 * @since 3.4.0
6270 *
6271 * @param string $color The color value to sanitize. Can be with or without a #.
6272 * @return string|null The sanitized hex color without the hash prefix,
6273 * empty string if input is empty, or null if invalid.
6274 */
6275function sanitize_hex_color_no_hash( $color ) {
6276 $color = ltrim( $color, '#' );
6277
6278 if ( '' === $color ) {
6279 return '';
6280 }
6281
6282 return sanitize_hex_color( '#' . $color ) ? $color : null;
6283}
6284
6285/**
6286 * Ensures that any hex color is properly hashed.
6287 * Otherwise, returns value untouched.
6288 *
6289 * This method should only be necessary if using sanitize_hex_color_no_hash().
6290 *
6291 * @since 3.4.0
6292 *
6293 * @param string $color The color value to add the hash prefix to. Can be with or without a #.
6294 * @return string The color with the hash prefix if it's a valid hex color,
6295 * otherwise the original value.
6296 */
6297function maybe_hash_hex_color( $color ) {
6298 $unhashed = sanitize_hex_color_no_hash( $color );
6299 if ( $unhashed ) {
6300 return '#' . $unhashed;
6301 }
6302
6303 return $color;
6304}
6305