Ticket #40419: 40419.patch
File 40419.patch, 160.5 KB (added by , 8 years ago) |
---|
-
wp-includes/formatting.php
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8
35 35 * @staticvar bool $run_texturize 36 36 * 37 37 * @param string $text The text to be formatted 38 * @param bool $reset Set to true for unit testing. Translated patterns will reset. 38 * @param bool $reset Set to true for unit testing. Translated patterns will reset. 39 * 39 40 * @return string The string replaced with html entities 40 41 */ 41 42 function wptexturize( $text, $reset = false ) { 42 43 global $wp_cockneyreplace, $shortcode_tags; 43 44 static $static_characters = null, 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 45 $static_replacements = null, 46 $dynamic_characters = null, 47 $dynamic_replacements = null, 48 $default_no_texturize_tags = null, 49 $default_no_texturize_shortcodes = null, 50 $run_texturize = true, 51 $apos = null, 52 $prime = null, 53 $double_prime = null, 54 $opening_quote = null, 55 $closing_quote = null, 56 $opening_single_quote = null, 57 $closing_single_quote = null, 58 $open_q_flag = '<!--oq-->', 59 $open_sq_flag = '<!--osq-->', 60 $apos_flag = '<!--apos-->'; 60 61 61 62 // If there's nothing to do, just stop. 62 63 if ( empty( $text ) || false === $run_texturize ) { … … 107 108 /* translators: em dash */ 108 109 $em_dash = _x( '—', 'em dash' ); 109 110 110 $default_no_texturize_tags = array('pre', 'code', 'kbd', 'style', 'script', 'tt');111 $default_no_texturize_shortcodes = array( 'code');111 $default_no_texturize_tags = array( 'pre', 'code', 'kbd', 'style', 'script', 'tt' ); 112 $default_no_texturize_shortcodes = array( 'code' ); 112 113 113 114 // if a plugin has provided an autocorrect array, use it 114 if ( isset( $wp_cockneyreplace) ) {115 $cockney = array_keys( $wp_cockneyreplace );115 if ( isset( $wp_cockneyreplace ) ) { 116 $cockney = array_keys( $wp_cockneyreplace ); 116 117 $cockneyreplace = array_values( $wp_cockneyreplace ); 117 118 } else { 118 119 /* translators: This is a comma-separated list of words that defy the syntax of quotations in normal use, … … 126 127 'Comma-separated list of replacement words in your language' ) ); 127 128 } 128 129 129 $static_characters = array_merge( array( '...', '``', '\'\'', ' (tm)' ), $cockney ); 130 $static_replacements = array_merge( array( '…', $opening_quote, $closing_quote, ' ™' ), $cockneyreplace ); 130 $static_characters = array_merge( array( '...', '``', '\'\'', ' (tm)' ), $cockney ); 131 $static_replacements = array_merge( array( 132 '…', 133 $opening_quote, 134 $closing_quote, 135 ' ™' 136 ), $cockneyreplace ); 131 137 132 138 133 139 // Pattern-based replacements of characters. 134 140 // Sort the remaining patterns into several arrays for performance tuning. 135 $dynamic_characters = array( 'apos' => array(), 'quote' => array(), 'dash' => array() );141 $dynamic_characters = array( 'apos' => array(), 'quote' => array(), 'dash' => array() ); 136 142 $dynamic_replacements = array( 'apos' => array(), 'quote' => array(), 'dash' => array() ); 137 $dynamic = array();138 $spaces = wp_spaces_regexp();143 $dynamic = array(); 144 $spaces = wp_spaces_regexp(); 139 145 140 146 // '99' and '99" are ambiguous among other patterns; assume it's an abbreviated year at the end of a quotation. 141 147 if ( "'" !== $apos || "'" !== $closing_single_quote ) { … … 147 153 148 154 // '99 '99s '99's (apostrophe) But never '9 or '99% or '999 or '99.0. 149 155 if ( "'" !== $apos ) { 150 $dynamic[ '/\'(?=\d\d(?:\Z|(?![%\d]|[.,]\d)))/'] = $apos_flag;156 $dynamic['/\'(?=\d\d(?:\Z|(?![%\d]|[.,]\d)))/'] = $apos_flag; 151 157 } 152 158 153 159 // Quoted Numbers like '0.42' … … 165 171 $dynamic[ '/(?<!' . $spaces . ')\'(?!\Z|[.,:;!?"\'(){}[\]\-]|&[lg]t;|' . $spaces . ')/' ] = $apos_flag; 166 172 } 167 173 168 $dynamic_characters['apos'] = array_keys( $dynamic );174 $dynamic_characters['apos'] = array_keys( $dynamic ); 169 175 $dynamic_replacements['apos'] = array_values( $dynamic ); 170 $dynamic = array();176 $dynamic = array(); 171 177 172 178 // Quoted Numbers like "42" 173 179 if ( '"' !== $opening_quote && '"' !== $closing_quote ) { … … 179 185 $dynamic[ '/(?<=\A|[([{\-]|<|' . $spaces . ')"(?!' . $spaces . ')/' ] = $open_q_flag; 180 186 } 181 187 182 $dynamic_characters['quote'] = array_keys( $dynamic );188 $dynamic_characters['quote'] = array_keys( $dynamic ); 183 189 $dynamic_replacements['quote'] = array_values( $dynamic ); 184 $dynamic = array();190 $dynamic = array(); 185 191 186 192 // Dashes and spaces 187 $dynamic[ '/---/' ]= $em_dash;193 $dynamic['/---/'] = $em_dash; 188 194 $dynamic[ '/(?<=^|' . $spaces . ')--(?=$|' . $spaces . ')/' ] = $em_dash; 189 $dynamic[ '/(?<!xn)--/' ]= $en_dash;190 $dynamic[ '/(?<=^|' . $spaces . ')-(?=$|' . $spaces . ')/' ] = $en_dash;195 $dynamic['/(?<!xn)--/'] = $en_dash; 196 $dynamic[ '/(?<=^|' . $spaces . ')-(?=$|' . $spaces . ')/' ] = $en_dash; 191 197 192 $dynamic_characters['dash'] = array_keys( $dynamic );198 $dynamic_characters['dash'] = array_keys( $dynamic ); 193 199 $dynamic_replacements['dash'] = array_values( $dynamic ); 194 200 } 195 201 … … 211 217 */ 212 218 $no_texturize_shortcodes = apply_filters( 'no_texturize_shortcodes', $default_no_texturize_shortcodes ); 213 219 214 $no_texturize_tags_stack = array();220 $no_texturize_tags_stack = array(); 215 221 $no_texturize_shortcodes_stack = array(); 216 222 217 223 // Look for shortcodes and HTML elements. 218 224 219 225 preg_match_all( '@\[/?([^<>&/\[\]\x00-\x20=]++)@', $text, $matches ); 220 $tagnames = array_intersect( array_keys( $shortcode_tags ), $matches[1] );226 $tagnames = array_intersect( array_keys( $shortcode_tags ), $matches[1] ); 221 227 $found_shortcodes = ! empty( $tagnames ); 222 $shortcode_regex = $found_shortcodes ? _get_wptexturize_shortcode_regex( $tagnames ) : '';223 $regex = _get_wptexturize_split_regex( $shortcode_regex );228 $shortcode_regex = $found_shortcodes ? _get_wptexturize_shortcode_regex( $tagnames ) : ''; 229 $regex = _get_wptexturize_split_regex( $shortcode_regex ); 224 230 225 $textarr = preg_split( $regex, $text, - 1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );231 $textarr = preg_split( $regex, $text, - 1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY ); 226 232 227 233 foreach ( $textarr as &$curl ) { 228 234 // Only call _wptexturize_pushpop_element if $curl is a delimiter. … … 247 253 } elseif ( '[' === $first && $found_shortcodes && 1 === preg_match( '/^' . $shortcode_regex . '$/', $curl ) ) { 248 254 // This is a shortcode delimiter. 249 255 250 if ( '[[' !== substr( $curl, 0, 2 ) && ']]' !== substr( $curl, - 2 ) ) {256 if ( '[[' !== substr( $curl, 0, 2 ) && ']]' !== substr( $curl, - 2 ) ) { 251 257 // Looks like a normal shortcode. 252 258 _wptexturize_pushpop_element( $curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes ); 253 259 } else { … … 295 301 * 296 302 * @since 4.3.0 297 303 * 298 * @param string $haystack 299 * @param string $needle 300 * @param string $prime 301 * @param string $open_quote 304 * @param string $haystack The plain text to be searched. 305 * @param string $needle The character to search for such as ' or ". 306 * @param string $prime The prime char to use for replacement. 307 * @param string $open_quote The opening quote char. Opening quote replacement must be 302 308 * accomplished already. 303 309 * @param string $close_quote The closing quote char to use for replacement. 310 * 304 311 * @return string The $haystack value after primes and quotes replacements. 305 312 */ 306 313 function wptexturize_primes( $haystack, $needle, $prime, $open_quote, $close_quote ) { 307 $spaces = wp_spaces_regexp();308 $flag = '<!--wp-prime-or-quote-->';309 $quote_pattern = "/$needle(?=\\Z|[.,:;!?)}\\-\\]]|>|" . $spaces . ")/";314 $spaces = wp_spaces_regexp(); 315 $flag = '<!--wp-prime-or-quote-->'; 316 $quote_pattern = "/$needle(?=\\Z|[.,:;!?)}\\-\\]]|>|" . $spaces . ")/"; 310 317 $prime_pattern = "/(?<=\\d)$needle/"; 311 318 $flag_after_digit = "/(?<=\\d)$flag/"; 312 319 $flag_no_digit = "/(?<!\\d)$flag/"; … … 317 324 if ( false === strpos( $sentence, $needle ) ) { 318 325 continue; 319 326 } elseif ( 0 !== $key && 0 === substr_count( $sentence, $close_quote ) ) { 320 $sentence = preg_replace( $quote_pattern, $flag, $sentence, - 1, $count );327 $sentence = preg_replace( $quote_pattern, $flag, $sentence, - 1, $count ); 321 328 if ( $count > 1 ) { 322 329 // This sentence appears to have multiple closing quotes. Attempt Vulcan logic. 323 $sentence = preg_replace( $flag_no_digit, $close_quote, $sentence, - 1, $count2 );330 $sentence = preg_replace( $flag_no_digit, $close_quote, $sentence, - 1, $count2 ); 324 331 if ( 0 === $count2 ) { 325 332 // Try looking for a quote followed by a period. 326 333 $count2 = substr_count( $sentence, "$flag." ); … … 369 376 * @access private 370 377 * 371 378 * @param string $text Text to check. Must be a tag like `<html>` or `[shortcode]`. 372 * @param array 373 * @param array 379 * @param array $stack List of open tag elements. 380 * @param array $disabled_elements The tag names to match against. Spaces are not allowed in tag names. 374 381 */ 375 382 function _wptexturize_pushpop_element( $text, &$stack, $disabled_elements ) { 376 383 // Is it an opening tag or closing tag? … … 388 395 // Parse out the tag name. 389 396 $space = strpos( $text, ' ' ); 390 397 if ( false === $space ) { 391 $space = - 1;398 $space = - 1; 392 399 } else { 393 400 $space -= $name_offset; 394 401 } … … 422 429 * @since 0.71 423 430 * 424 431 * @param string $pee The text which has to be formatted. 425 * @param bool $brOptional. If set, this will convert all remaining line-breaks432 * @param bool $br Optional. If set, this will convert all remaining line-breaks 426 433 * after paragraphing. Default true. 434 * 427 435 * @return string Text which has been converted into correct paragraph tags. 428 436 */ 429 437 function wpautop( $pee, $br = true ) { 430 438 $pre_tags = array(); 431 439 432 if ( trim( $pee) === '' )440 if ( trim( $pee ) === '' ) { 433 441 return ''; 442 } 434 443 435 444 // Just to make things a little easier, pad the end. 436 445 $pee = $pee . "\n"; … … 439 448 * Pre tags shouldn't be touched by autop. 440 449 * Replace pre tags with placeholders and bring them back after autop. 441 450 */ 442 if ( strpos( $pee, '<pre') !== false ) {451 if ( strpos( $pee, '<pre' ) !== false ) { 443 452 $pee_parts = explode( '</pre>', $pee ); 444 $last_pee = array_pop($pee_parts);445 $pee = '';446 $i = 0;453 $last_pee = array_pop( $pee_parts ); 454 $pee = ''; 455 $i = 0; 447 456 448 457 foreach ( $pee_parts as $pee_part ) { 449 $start = strpos( $pee_part, '<pre');458 $start = strpos( $pee_part, '<pre' ); 450 459 451 460 // Malformed html? 452 461 if ( $start === false ) { … … 454 463 continue; 455 464 } 456 465 457 $name = "<pre wp-pre-tag-$i></pre>";458 $pre_tags[ $name] = substr( $pee_part, $start ) . '</pre>';466 $name = "<pre wp-pre-tag-$i></pre>"; 467 $pre_tags[ $name ] = substr( $pee_part, $start ) . '</pre>'; 459 468 460 469 $pee .= substr( $pee_part, 0, $start ) . $name; 461 $i ++;470 $i ++; 462 471 } 463 472 464 473 $pee .= $last_pee; 465 474 } 466 475 // Change multiple <br>s into two line breaks, which will turn into paragraphs. 467 $pee = preg_replace( '|<br\s*/?>\s*<br\s*/?>|', "\n\n", $pee);476 $pee = preg_replace( '|<br\s*/?>\s*<br\s*/?>|', "\n\n", $pee ); 468 477 469 478 $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)'; 470 479 471 480 // Add a double line break above block-level opening tags. 472 $pee = preg_replace( '!(<' . $allblocks . '[\s/>])!', "\n\n$1", $pee);481 $pee = preg_replace( '!(<' . $allblocks . '[\s/>])!', "\n\n$1", $pee ); 473 482 474 483 // Add a double line break below block-level closing tags. 475 $pee = preg_replace( '!(</' . $allblocks . '>)!', "$1\n\n", $pee);484 $pee = preg_replace( '!(</' . $allblocks . '>)!', "$1\n\n", $pee ); 476 485 477 486 // Standardize newline characters to "\n". 478 $pee = str_replace( array("\r\n", "\r"), "\n", $pee);487 $pee = str_replace( array( "\r\n", "\r" ), "\n", $pee ); 479 488 480 489 // Find newlines in all elements and add placeholders. 481 490 $pee = wp_replace_in_html_tags( $pee, array( "\n" => " <!-- wpnl --> " ) ); … … 513 522 } 514 523 515 524 // Remove more than two contiguous line breaks. 516 $pee = preg_replace( "/\n\n+/", "\n\n", $pee);525 $pee = preg_replace( "/\n\n+/", "\n\n", $pee ); 517 526 518 527 // Split up the contents into an array of strings, separated by double line breaks. 519 $pees = preg_split( '/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);528 $pees = preg_split( '/\n\s*\n/', $pee, - 1, PREG_SPLIT_NO_EMPTY ); 520 529 521 530 // Reset $pee prior to rebuilding. 522 531 $pee = ''; 523 532 524 533 // Rebuild the content as a string, wrapping every bit with a <p>. 525 534 foreach ( $pees as $tinkle ) { 526 $pee .= '<p>' . trim( $tinkle, "\n") . "</p>\n";535 $pee .= '<p>' . trim( $tinkle, "\n" ) . "</p>\n"; 527 536 } 528 537 529 538 // Under certain strange conditions it could create a P of entirely whitespace. 530 $pee = preg_replace( '|<p>\s*</p>|', '', $pee);539 $pee = preg_replace( '|<p>\s*</p>|', '', $pee ); 531 540 532 541 // Add a closing <p> inside <div>, <address>, or <form> tag if missing. 533 $pee = preg_replace( '!<p>([^<]+)</(div|address|form)>!', "<p>$1</p></$2>", $pee);542 $pee = preg_replace( '!<p>([^<]+)</(div|address|form)>!', "<p>$1</p></$2>", $pee ); 534 543 535 544 // If an opening or closing block element tag is wrapped in a <p>, unwrap it. 536 $pee = preg_replace( '!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee);545 $pee = preg_replace( '!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee ); 537 546 538 547 // In some cases <li> may get wrapped in <p>, fix them. 539 $pee = preg_replace( "|<p>(<li.+?)</p>|", "$1", $pee);548 $pee = preg_replace( "|<p>(<li.+?)</p>|", "$1", $pee ); 540 549 541 550 // If a <blockquote> is wrapped with a <p>, move it inside the <blockquote>. 542 $pee = preg_replace( '|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $pee);543 $pee = str_replace( '</blockquote></p>', '</p></blockquote>', $pee);551 $pee = preg_replace( '|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $pee ); 552 $pee = str_replace( '</blockquote></p>', '</p></blockquote>', $pee ); 544 553 545 554 // If an opening or closing block element tag is preceded by an opening <p> tag, remove it. 546 $pee = preg_replace( '!<p>\s*(</?' . $allblocks . '[^>]*>)!', "$1", $pee);555 $pee = preg_replace( '!<p>\s*(</?' . $allblocks . '[^>]*>)!', "$1", $pee ); 547 556 548 557 // If an opening or closing block element tag is followed by a closing <p> tag, remove it. 549 $pee = preg_replace( '!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee);558 $pee = preg_replace( '!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee ); 550 559 551 560 // Optionally insert line breaks. 552 561 if ( $br ) { 553 562 // Replace newlines that shouldn't be touched with a placeholder. 554 $pee = preg_replace_callback( '/<(script|style).*?<\/\\1>/s', '_autop_newline_preservation_helper', $pee);563 $pee = preg_replace_callback( '/<(script|style).*?<\/\\1>/s', '_autop_newline_preservation_helper', $pee ); 555 564 556 565 // Normalize <br> 557 566 $pee = str_replace( array( '<br>', '<br/>' ), '<br />', $pee ); 558 567 559 568 // Replace any new line characters that aren't preceded by a <br /> with a <br />. 560 $pee = preg_replace( '|(?<!<br />)\s*\n|', "<br />\n", $pee);569 $pee = preg_replace( '|(?<!<br />)\s*\n|', "<br />\n", $pee ); 561 570 562 571 // Replace newline placeholders with newlines. 563 $pee = str_replace( '<WPPreserveNewline />', "\n", $pee);572 $pee = str_replace( '<WPPreserveNewline />', "\n", $pee ); 564 573 } 565 574 566 575 // If a <br /> tag is after an opening or closing block tag, remove it. 567 $pee = preg_replace( '!(</?' . $allblocks . '[^>]*>)\s*<br />!', "$1", $pee);576 $pee = preg_replace( '!(</?' . $allblocks . '[^>]*>)\s*<br />!', "$1", $pee ); 568 577 569 578 // If a <br /> tag is before a subset of opening or closing block tags, remove it. 570 $pee = preg_replace( '!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);579 $pee = preg_replace( '!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee ); 571 580 $pee = preg_replace( "|\n</p>$|", '</p>', $pee ); 572 581 573 582 // Replace placeholder <pre> tags with their original content. 574 if ( !empty($pre_tags) ) 575 $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee); 583 if ( ! empty( $pre_tags ) ) { 584 $pee = str_replace( array_keys( $pre_tags ), array_values( $pre_tags ), $pee ); 585 } 576 586 577 587 // Restore newlines in all elements. 578 588 if ( false !== strpos( $pee, '<!-- wpnl -->' ) ) { … … 588 598 * @since 4.2.4 589 599 * 590 600 * @param string $input The text which has to be formatted. 601 * 591 602 * @return array The formatted text. 592 603 */ 593 604 function wp_html_split( $input ) { 594 return preg_split( get_html_split_regex(), $input, - 1, PREG_SPLIT_DELIM_CAPTURE );605 return preg_split( get_html_split_regex(), $input, - 1, PREG_SPLIT_DELIM_CAPTURE ); 595 606 } 596 607 597 608 /** … … 606 617 607 618 if ( ! isset( $regex ) ) { 608 619 $comments = 609 620 '!' // Start of comment, after the <. 610 621 . '(?:' // Unroll the loop: Consume everything until --> is found. 611 . 612 . 622 . '-(?!->)' // Dash not followed by end of comment. 623 . '[^\-]*+' // Consume non-dashes. 613 624 . ')*+' // Loop possessively. 614 625 . '(?:-->)?'; // End of comment. If not found, match all input. 615 626 616 627 $cdata = 617 628 '!\[CDATA\[' // Start of comment, after the <. 618 629 . '[^\]]*+' // Consume non-]. 619 630 . '(?:' // Unroll the loop: Consume everything until ]]> is found. 620 . 621 . 631 . '](?!]>)' // One ] not followed by end of comment. 632 . '[^\]]*+' // Consume non-]. 622 633 . ')*+' // Loop possessively. 623 634 . '(?:]]>)?'; // End of comment. If not found, match all input. 624 635 625 636 $escaped = 626 627 . 637 '(?=' // Is the element escaped? 638 . '!--' 628 639 . '|' 629 . 640 . '!\[CDATA\[' 630 641 . ')' 631 642 . '(?(?=!-)' // If yes, which type? 632 . 643 . $comments 633 644 . '|' 634 . 645 . $cdata 635 646 . ')'; 636 647 637 648 $regex = 638 639 . 640 . 641 . 642 . 643 . 644 . 649 '/(' // Capture the entire match. 650 . '<' // Find start of element. 651 . '(?' // Conditional expression follows. 652 . $escaped // Find end of escaped element. 653 . '|' // ... else ... 654 . '[^>]*>?' // Find end of normal element. 655 . ')' 645 656 . ')/'; 646 657 } 647 658 … … 657 668 * @since 4.4.0 658 669 * 659 670 * @param string $shortcode_regex The result from _get_wptexturize_shortcode_regex(). Optional. 671 * 660 672 * @return string The regular expression 661 673 */ 662 674 function _get_wptexturize_split_regex( $shortcode_regex = '' ) { … … 664 676 665 677 if ( ! isset( $html_regex ) ) { 666 678 $comment_regex = 667 679 '!' // Start of comment, after the <. 668 680 . '(?:' // Unroll the loop: Consume everything until --> is found. 669 . 670 . 681 . '-(?!->)' // Dash not followed by end of comment. 682 . '[^\-]*+' // Consume non-dashes. 671 683 . ')*+' // Loop possessively. 672 684 . '(?:-->)?'; // End of comment. If not found, match all input. 673 685 674 $html_regex = 675 686 $html_regex = // Needs replaced with wp_html_split() per Shortcode API Roadmap. 687 '<' // Find start of element. 676 688 . '(?(?=!--)' // Is this a comment? 677 . 689 . $comment_regex // Find end of comment. 678 690 . '|' 679 . 691 . '[^>]*>?' // Find end of element. If not found, match all input. 680 692 . ')'; 681 693 } 682 694 … … 698 710 * @since 4.4.0 699 711 * 700 712 * @param array $tagnames List of shortcodes to find. 713 * 701 714 * @return string The regular expression 702 715 */ 703 716 function _get_wptexturize_shortcode_regex( $tagnames ) { 704 717 $tagregexp = join( '|', array_map( 'preg_quote', $tagnames ) ); 705 718 $tagregexp = "(?:$tagregexp)(?=[\\s\\]\\/])"; // Excerpt of get_shortcode_regex(). 706 $regex =707 719 $regex = 720 '\[' // Find start of shortcode. 708 721 . '[\/\[]?' // Shortcodes may begin with [/ or [[ 709 722 . $tagregexp // Only match registered shortcodes, because performance. 710 723 . '(?:' 711 . 724 . '[^\[\]<>]+' // Shortcodes do not contain other shortcodes. Quantifier critical. 712 725 . '|' 713 . 726 . '<[^\[\]>]*>' // HTML elements permitted. Prevents matching ] before >. 714 727 . ')*+' // Possessive critical. 715 728 . '\]' // Find end of shortcode. 716 729 . '\]?'; // Shortcodes may end with ]] … … 725 738 * 726 739 * @param string $haystack The text which has to be formatted. 727 740 * @param array $replace_pairs In the form array('from' => 'to', ...). 741 * 728 742 * @return string The formatted text. 729 743 */ 730 744 function wp_replace_in_html_tags( $haystack, $replace_pairs ) { … … 735 749 // Optimize when searching for one item. 736 750 if ( 1 === count( $replace_pairs ) ) { 737 751 // Extract $needle and $replace. 738 foreach ( $replace_pairs as $needle => $replace ); 752 foreach ( $replace_pairs as $needle => $replace ) { 753 ; 754 } 739 755 740 756 // Loop through delimiters (elements) only. 741 757 for ( $i = 1, $c = count( $textarr ); $i < $c; $i += 2 ) { 742 if ( false !== strpos( $textarr[ $i], $needle ) ) {743 $textarr[ $i] = str_replace( $needle, $replace, $textarr[$i] );744 $changed = true;758 if ( false !== strpos( $textarr[ $i ], $needle ) ) { 759 $textarr[ $i ] = str_replace( $needle, $replace, $textarr[ $i ] ); 760 $changed = true; 745 761 } 746 762 } 747 763 } else { … … 751 767 // Loop through delimiters (elements) only. 752 768 for ( $i = 1, $c = count( $textarr ); $i < $c; $i += 2 ) { 753 769 foreach ( $needles as $needle ) { 754 if ( false !== strpos( $textarr[ $i], $needle ) ) {755 $textarr[ $i] = strtr( $textarr[$i], $replace_pairs );756 $changed = true;770 if ( false !== strpos( $textarr[ $i ], $needle ) ) { 771 $textarr[ $i ] = strtr( $textarr[ $i ], $replace_pairs ); 772 $changed = true; 757 773 // After one strtr() break out of the foreach loop and look at next element. 758 774 break; 759 775 } … … 775 791 * @access private 776 792 * 777 793 * @param array $matches preg_replace_callback matches array 794 * 778 795 * @return string 779 796 */ 780 797 function _autop_newline_preservation_helper( $matches ) { … … 791 808 * @global array $shortcode_tags 792 809 * 793 810 * @param string $pee The content. 811 * 794 812 * @return string The filtered content. 795 813 */ 796 814 function shortcode_unautop( $pee ) { 797 815 global $shortcode_tags; 798 816 799 if ( empty( $shortcode_tags ) || ! is_array( $shortcode_tags ) ) {817 if ( empty( $shortcode_tags ) || ! is_array( $shortcode_tags ) ) { 800 818 return $pee; 801 819 } 802 820 803 821 $tagregexp = join( '|', array_map( 'preg_quote', array_keys( $shortcode_tags ) ) ); 804 $spaces = wp_spaces_regexp();822 $spaces = wp_spaces_regexp(); 805 823 806 824 $pattern = 807 825 '/' 808 826 . '<p>' // Opening paragraph 809 827 . '(?:' . $spaces . ')*+' // Optional leading whitespace 810 828 . '(' // 1: The shortcode 811 . 812 . 813 . 814 815 . 816 . 817 . 818 . 819 . 820 . 821 . 822 . 823 . 824 . 825 . 826 . 827 . 828 . 829 . 830 . 831 . 832 . 829 . '\\[' // Opening bracket 830 . "($tagregexp)" // 2: Shortcode name 831 . '(?![\\w-])' // Not followed by word character or hyphen 832 // Unroll the loop: Inside the opening shortcode tag 833 . '[^\\]\\/]*' // Not a closing bracket or forward slash 834 . '(?:' 835 . '\\/(?!\\])' // A forward slash not followed by a closing bracket 836 . '[^\\]\\/]*' // Not a closing bracket or forward slash 837 . ')*?' 838 . '(?:' 839 . '\\/\\]' // Self closing tag and closing bracket 840 . '|' 841 . '\\]' // Closing bracket 842 . '(?:' // Unroll the loop: Optionally, anything between the opening and closing shortcode tags 843 . '[^\\[]*+' // Not an opening bracket 844 . '(?:' 845 . '\\[(?!\\/\\2\\])' // An opening bracket not followed by the closing shortcode tag 846 . '[^\\[]*+' // Not an opening bracket 847 . ')*+' 848 . '\\[\\/\\2\\]' // Closing shortcode tag 849 . ')?' 850 . ')' 833 851 . ')' 834 852 . '(?:' . $spaces . ')*+' // optional trailing whitespace 835 853 . '<\\/p>' // closing paragraph … … 848 866 * @since 1.2.1 849 867 * 850 868 * @param string $str The string to be checked 869 * 851 870 * @return bool True if $str fits a UTF-8 model, false otherwise. 852 871 */ 853 872 function seems_utf8( $str ) { 854 873 mbstring_binary_safe_encoding(); 855 $length = strlen( $str);874 $length = strlen( $str ); 856 875 reset_mbstring_encoding(); 857 for ($i=0; $i < $length; $i++) { 858 $c = ord($str[$i]); 859 if ($c < 0x80) $n = 0; // 0bbbbbbb 860 elseif (($c & 0xE0) == 0xC0) $n=1; // 110bbbbb 861 elseif (($c & 0xF0) == 0xE0) $n=2; // 1110bbbb 862 elseif (($c & 0xF8) == 0xF0) $n=3; // 11110bbb 863 elseif (($c & 0xFC) == 0xF8) $n=4; // 111110bb 864 elseif (($c & 0xFE) == 0xFC) $n=5; // 1111110b 865 else return false; // Does not match any model 866 for ($j=0; $j<$n; $j++) { // n bytes matching 10bbbbbb follow ? 867 if ((++$i == $length) || ((ord($str[$i]) & 0xC0) != 0x80)) 876 for ( $i = 0; $i < $length; $i ++ ) { 877 $c = ord( $str[ $i ] ); 878 if ( $c < 0x80 ) { 879 $n = 0; 880 } // 0bbbbbbb 881 elseif ( ( $c & 0xE0 ) == 0xC0 ) { 882 $n = 1; 883 } // 110bbbbb 884 elseif ( ( $c & 0xF0 ) == 0xE0 ) { 885 $n = 2; 886 } // 1110bbbb 887 elseif ( ( $c & 0xF8 ) == 0xF0 ) { 888 $n = 3; 889 } // 11110bbb 890 elseif ( ( $c & 0xFC ) == 0xF8 ) { 891 $n = 4; 892 } // 111110bb 893 elseif ( ( $c & 0xFE ) == 0xFC ) { 894 $n = 5; 895 } // 1111110b 896 else { 897 return false; 898 } // Does not match any model 899 for ( $j = 0; $j < $n; $j ++ ) { // n bytes matching 10bbbbbb follow ? 900 if ( ( ++ $i == $length ) || ( ( ord( $str[ $i ] ) & 0xC0 ) != 0x80 ) ) { 868 901 return false; 902 } 869 903 } 870 904 } 905 871 906 return true; 872 907 } 873 908 … … 884 919 * 885 920 * @staticvar string $_charset 886 921 * 887 * @param string $stringThe text which is to be encoded.888 * @param int|string $quote_style 922 * @param string $string The text which is to be encoded. 923 * @param int|string $quote_style Optional. Converts double quotes if set to ENT_COMPAT, 889 924 * both single and double if set to ENT_QUOTES or none if set to ENT_NOQUOTES. 890 925 * Also compatible with old values; converting single quotes if set to 'single', 891 926 * double if set to 'double' or both if otherwise set. 892 927 * Default is ENT_NOQUOTES. 893 * @param string $charset Optional. The character encoding of the string. Default is false. 894 * @param bool $double_encode Optional. Whether to encode existing html entities. Default is false. 928 * @param string $charset Optional. The character encoding of the string. Default is false. 929 * @param bool $double_encode Optional. Whether to encode existing html entities. Default is false. 930 * 895 931 * @return string The encoded text with HTML entities. 896 932 */ 897 933 function _wp_specialchars( $string, $quote_style = ENT_NOQUOTES, $charset = false, $double_encode = false ) { 898 934 $string = (string) $string; 899 935 900 if ( 0 === strlen( $string ) ) 936 if ( 0 === strlen( $string ) ) { 901 937 return ''; 938 } 902 939 903 940 // Don't bother if there are no specialchars - saves some processing 904 if ( ! preg_match( '/[&<>"\']/', $string ) ) 941 if ( ! preg_match( '/[&<>"\']/', $string ) ) { 905 942 return $string; 943 } 906 944 907 945 // Account for the previous behaviour of the function when the $quote_style is not an accepted value 908 if ( empty( $quote_style ) ) 946 if ( empty( $quote_style ) ) { 909 947 $quote_style = ENT_NOQUOTES; 910 elseif ( ! in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) )948 } elseif ( ! in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) { 911 949 $quote_style = ENT_QUOTES; 950 } 912 951 913 952 // Store the site charset as a static to avoid multiple calls to wp_load_alloptions() 914 953 if ( ! $charset ) { 915 954 static $_charset = null; 916 955 if ( ! isset( $_charset ) ) { 917 956 $alloptions = wp_load_alloptions(); 918 $_charset = isset( $alloptions['blog_charset'] ) ? $alloptions['blog_charset'] : '';957 $_charset = isset( $alloptions['blog_charset'] ) ? $alloptions['blog_charset'] : ''; 919 958 } 920 959 $charset = $_charset; 921 960 } 922 961 923 if ( in_array( $charset, array( 'utf8', 'utf-8', 'UTF8' ) ) ) 962 if ( in_array( $charset, array( 'utf8', 'utf-8', 'UTF8' ) ) ) { 924 963 $charset = 'UTF-8'; 964 } 925 965 926 966 $_quote_style = $quote_style; 927 967 928 968 if ( $quote_style === 'double' ) { 929 $quote_style = ENT_COMPAT;969 $quote_style = ENT_COMPAT; 930 970 $_quote_style = ENT_COMPAT; 931 971 } elseif ( $quote_style === 'single' ) { 932 972 $quote_style = ENT_NOQUOTES; … … 941 981 $string = @htmlspecialchars( $string, $quote_style, $charset, $double_encode ); 942 982 943 983 // Back-compat. 944 if ( 'single' === $_quote_style ) 984 if ( 'single' === $_quote_style ) { 945 985 $string = str_replace( "'", ''', $string ); 986 } 946 987 947 988 return $string; 948 989 } … … 957 998 * 958 999 * @since 2.8.0 959 1000 * 960 * @param string 1001 * @param string $string The text which is to be decoded. 961 1002 * @param string|int $quote_style Optional. Converts double quotes if set to ENT_COMPAT, 962 1003 * both single and double if set to ENT_QUOTES or 963 1004 * none if set to ENT_NOQUOTES. … … 965 1006 * converting single quotes if set to 'single', 966 1007 * double if set to 'double' or both if otherwise set. 967 1008 * Default is ENT_NOQUOTES. 1009 * 968 1010 * @return string The decoded text without HTML entities. 969 1011 */ 970 1012 function wp_specialchars_decode( $string, $quote_style = ENT_NOQUOTES ) { … … 982 1024 // Match the previous behaviour of _wp_specialchars() when the $quote_style is not an accepted value 983 1025 if ( empty( $quote_style ) ) { 984 1026 $quote_style = ENT_NOQUOTES; 985 } elseif ( ! in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) {1027 } elseif ( ! in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) { 986 1028 $quote_style = ENT_QUOTES; 987 1029 } 988 1030 989 1031 // More complete than get_html_translation_table( HTML_SPECIALCHARS ) 990 $single = array( ''' => '\'', ''' => '\'' ); 991 $single_preg = array( '/�*39;/' => ''', '/�*27;/i' => ''' ); 992 $double = array( '"' => '"', '"' => '"', '"' => '"' ); 993 $double_preg = array( '/�*34;/' => '"', '/�*22;/i' => '"' ); 994 $others = array( '<' => '<', '<' => '<', '>' => '>', '>' => '>', '&' => '&', '&' => '&', '&' => '&' ); 995 $others_preg = array( '/�*60;/' => '<', '/�*62;/' => '>', '/�*38;/' => '&', '/�*26;/i' => '&' ); 1032 $single = array( ''' => '\'', ''' => '\'' ); 1033 $single_preg = array( '/�*39;/' => ''', '/�*27;/i' => ''' ); 1034 $double = array( '"' => '"', '"' => '"', '"' => '"' ); 1035 $double_preg = array( '/�*34;/' => '"', '/�*22;/i' => '"' ); 1036 $others = array( 1037 '<' => '<', 1038 '<' => '<', 1039 '>' => '>', 1040 '>' => '>', 1041 '&' => '&', 1042 '&' => '&', 1043 '&' => '&' 1044 ); 1045 $others_preg = array( 1046 '/�*60;/' => '<', 1047 '/�*62;/' => '>', 1048 '/�*38;/' => '&', 1049 '/�*26;/i' => '&' 1050 ); 996 1051 997 1052 if ( $quote_style === ENT_QUOTES ) { 998 $translation = array_merge( $single, $double, $others );1053 $translation = array_merge( $single, $double, $others ); 999 1054 $translation_preg = array_merge( $single_preg, $double_preg, $others_preg ); 1000 1055 } elseif ( $quote_style === ENT_COMPAT || $quote_style === 'double' ) { 1001 $translation = array_merge( $double, $others );1056 $translation = array_merge( $double, $others ); 1002 1057 $translation_preg = array_merge( $double_preg, $others_preg ); 1003 1058 } elseif ( $quote_style === 'single' ) { 1004 $translation = array_merge( $single, $others );1059 $translation = array_merge( $single, $others ); 1005 1060 $translation_preg = array_merge( $single_preg, $others_preg ); 1006 1061 } elseif ( $quote_style === ENT_NOQUOTES ) { 1007 $translation = $others;1062 $translation = $others; 1008 1063 $translation_preg = $others_preg; 1009 1064 } 1010 1065 … … 1023 1078 * @staticvar bool $is_utf8 1024 1079 * @staticvar bool $utf8_pcre 1025 1080 * 1026 * @param string $string The text which is to be checked. 1027 * @param bool $strip Optional. Whether to attempt to strip out invalid UTF8. Default is false. 1081 * @param string $string The text which is to be checked. 1082 * @param bool $strip Optional. Whether to attempt to strip out invalid UTF8. Default is false. 1083 * 1028 1084 * @return string The checked text. 1029 1085 */ 1030 1086 function wp_check_invalid_utf8( $string, $strip = false ) { … … 1049 1105 $utf8_pcre = @preg_match( '/^./u', 'a' ); 1050 1106 } 1051 1107 // We can't demand utf8 in the PCRE installation, so just return the string in those cases 1052 if ( ! $utf8_pcre ) {1108 if ( ! $utf8_pcre ) { 1053 1109 return $string; 1054 1110 } 1055 1111 … … 1072 1128 * @since 1.5.0 1073 1129 * 1074 1130 * @param string $utf8_string 1075 * @param int $length Max length of the string 1131 * @param int $length Max length of the string 1132 * 1076 1133 * @return string String with Unicode encoded for URI. 1077 1134 */ 1078 1135 function utf8_uri_encode( $utf8_string, $length = 0 ) { 1079 $unicode = '';1080 $values = array();1081 $num_octets = 1;1136 $unicode = ''; 1137 $values = array(); 1138 $num_octets = 1; 1082 1139 $unicode_length = 0; 1083 1140 1084 1141 mbstring_binary_safe_encoding(); 1085 1142 $string_length = strlen( $utf8_string ); 1086 1143 reset_mbstring_encoding(); 1087 1144 1088 for ( $i = 0; $i < $string_length; $i++ ) {1145 for ( $i = 0; $i < $string_length; $i ++ ) { 1089 1146 1090 1147 $value = ord( $utf8_string[ $i ] ); 1091 1148 1092 1149 if ( $value < 128 ) { 1093 if ( $length && ( $unicode_length >= $length ) ) 1150 if ( $length && ( $unicode_length >= $length ) ) { 1094 1151 break; 1095 $unicode .= chr($value); 1096 $unicode_length++; 1152 } 1153 $unicode .= chr( $value ); 1154 $unicode_length ++; 1097 1155 } else { 1098 1156 if ( count( $values ) == 0 ) { 1099 1157 if ( $value < 224 ) { … … 1107 1165 1108 1166 $values[] = $value; 1109 1167 1110 if ( $length && ( $unicode_length + ( $num_octets * 3) ) > $length )1168 if ( $length && ( $unicode_length + ( $num_octets * 3 ) ) > $length ) { 1111 1169 break; 1170 } 1112 1171 if ( count( $values ) == $num_octets ) { 1113 for ( $j = 0; $j < $num_octets; $j ++ ) {1172 for ( $j = 0; $j < $num_octets; $j ++ ) { 1114 1173 $unicode .= '%' . dechex( $values[ $j ] ); 1115 1174 } 1116 1175 1117 1176 $unicode_length += $num_octets * 3; 1118 1177 1119 $values = array();1178 $values = array(); 1120 1179 $num_octets = 1; 1121 1180 } 1122 1181 } … … 1509 1568 * @since 4.8.0 Added locale support for `bs_BA`. 1510 1569 * 1511 1570 * @param string $string Text that might have accent characters 1571 * 1512 1572 * @return string Filtered string with replaced "nice" characters. 1513 1573 */ 1514 1574 function remove_accents( $string ) { 1515 if ( ! preg_match('/[\x80-\xff]/', $string) )1575 if ( ! preg_match( '/[\x80-\xff]/', $string ) ) { 1516 1576 return $string; 1577 } 1517 1578 1518 if ( seems_utf8($string)) {1579 if ( seems_utf8( $string ) ) { 1519 1580 $chars = array( 1520 // Decompositions for Latin-1 Supplement 1521 'ª' => 'a', 'º' => 'o', 1522 'À' => 'A', 'Á' => 'A', 1523 'Â' => 'A', 'Ã' => 'A', 1524 'Ä' => 'A', 'Å' => 'A', 1525 'Æ' => 'AE','Ç' => 'C', 1526 'È' => 'E', 'É' => 'E', 1527 'Ê' => 'E', 'Ë' => 'E', 1528 'Ì' => 'I', 'Í' => 'I', 1529 'Î' => 'I', 'Ï' => 'I', 1530 'Ð' => 'D', 'Ñ' => 'N', 1531 'Ò' => 'O', 'Ó' => 'O', 1532 'Ô' => 'O', 'Õ' => 'O', 1533 'Ö' => 'O', 'Ù' => 'U', 1534 'Ú' => 'U', 'Û' => 'U', 1535 'Ü' => 'U', 'Ý' => 'Y', 1536 'Þ' => 'TH','ß' => 's', 1537 'à' => 'a', 'á' => 'a', 1538 'â' => 'a', 'ã' => 'a', 1539 'ä' => 'a', 'å' => 'a', 1540 'æ' => 'ae','ç' => 'c', 1541 'è' => 'e', 'é' => 'e', 1542 'ê' => 'e', 'ë' => 'e', 1543 'ì' => 'i', 'í' => 'i', 1544 'î' => 'i', 'ï' => 'i', 1545 'ð' => 'd', 'ñ' => 'n', 1546 'ò' => 'o', 'ó' => 'o', 1547 'ô' => 'o', 'õ' => 'o', 1548 'ö' => 'o', 'ø' => 'o', 1549 'ù' => 'u', 'ú' => 'u', 1550 'û' => 'u', 'ü' => 'u', 1551 'ý' => 'y', 'þ' => 'th', 1552 'ÿ' => 'y', 'Ø' => 'O', 1553 // Decompositions for Latin Extended-A 1554 'Ā' => 'A', 'ā' => 'a', 1555 'Ă' => 'A', 'ă' => 'a', 1556 'Ą' => 'A', 'ą' => 'a', 1557 'Ć' => 'C', 'ć' => 'c', 1558 'Ĉ' => 'C', 'ĉ' => 'c', 1559 'Ċ' => 'C', 'ċ' => 'c', 1560 'Č' => 'C', 'č' => 'c', 1561 'Ď' => 'D', 'ď' => 'd', 1562 'Đ' => 'D', 'đ' => 'd', 1563 'Ē' => 'E', 'ē' => 'e', 1564 'Ĕ' => 'E', 'ĕ' => 'e', 1565 'Ė' => 'E', 'ė' => 'e', 1566 'Ę' => 'E', 'ę' => 'e', 1567 'Ě' => 'E', 'ě' => 'e', 1568 'Ĝ' => 'G', 'ĝ' => 'g', 1569 'Ğ' => 'G', 'ğ' => 'g', 1570 'Ġ' => 'G', 'ġ' => 'g', 1571 'Ģ' => 'G', 'ģ' => 'g', 1572 'Ĥ' => 'H', 'ĥ' => 'h', 1573 'Ħ' => 'H', 'ħ' => 'h', 1574 'Ĩ' => 'I', 'ĩ' => 'i', 1575 'Ī' => 'I', 'ī' => 'i', 1576 'Ĭ' => 'I', 'ĭ' => 'i', 1577 'Į' => 'I', 'į' => 'i', 1578 'İ' => 'I', 'ı' => 'i', 1579 'IJ' => 'IJ','ij' => 'ij', 1580 'Ĵ' => 'J', 'ĵ' => 'j', 1581 'Ķ' => 'K', 'ķ' => 'k', 1582 'ĸ' => 'k', 'Ĺ' => 'L', 1583 'ĺ' => 'l', 'Ļ' => 'L', 1584 'ļ' => 'l', 'Ľ' => 'L', 1585 'ľ' => 'l', 'Ŀ' => 'L', 1586 'ŀ' => 'l', 'Ł' => 'L', 1587 'ł' => 'l', 'Ń' => 'N', 1588 'ń' => 'n', 'Ņ' => 'N', 1589 'ņ' => 'n', 'Ň' => 'N', 1590 'ň' => 'n', 'ʼn' => 'n', 1591 'Ŋ' => 'N', 'ŋ' => 'n', 1592 'Ō' => 'O', 'ō' => 'o', 1593 'Ŏ' => 'O', 'ŏ' => 'o', 1594 'Ő' => 'O', 'ő' => 'o', 1595 'Œ' => 'OE','œ' => 'oe', 1596 'Ŕ' => 'R','ŕ' => 'r', 1597 'Ŗ' => 'R','ŗ' => 'r', 1598 'Ř' => 'R','ř' => 'r', 1599 'Ś' => 'S','ś' => 's', 1600 'Ŝ' => 'S','ŝ' => 's', 1601 'Ş' => 'S','ş' => 's', 1602 'Š' => 'S', 'š' => 's', 1603 'Ţ' => 'T', 'ţ' => 't', 1604 'Ť' => 'T', 'ť' => 't', 1605 'Ŧ' => 'T', 'ŧ' => 't', 1606 'Ũ' => 'U', 'ũ' => 'u', 1607 'Ū' => 'U', 'ū' => 'u', 1608 'Ŭ' => 'U', 'ŭ' => 'u', 1609 'Ů' => 'U', 'ů' => 'u', 1610 'Ű' => 'U', 'ű' => 'u', 1611 'Ų' => 'U', 'ų' => 'u', 1612 'Ŵ' => 'W', 'ŵ' => 'w', 1613 'Ŷ' => 'Y', 'ŷ' => 'y', 1614 'Ÿ' => 'Y', 'Ź' => 'Z', 1615 'ź' => 'z', 'Ż' => 'Z', 1616 'ż' => 'z', 'Ž' => 'Z', 1617 'ž' => 'z', 'ſ' => 's', 1618 // Decompositions for Latin Extended-B 1619 'Ș' => 'S', 'ș' => 's', 1620 'Ț' => 'T', 'ț' => 't', 1621 // Euro Sign 1622 '€' => 'E', 1623 // GBP (Pound) Sign 1624 '£' => '', 1625 // Vowels with diacritic (Vietnamese) 1626 // unmarked 1627 'Ơ' => 'O', 'ơ' => 'o', 1628 'Ư' => 'U', 'ư' => 'u', 1629 // grave accent 1630 'Ầ' => 'A', 'ầ' => 'a', 1631 'Ằ' => 'A', 'ằ' => 'a', 1632 'Ề' => 'E', 'ề' => 'e', 1633 'Ồ' => 'O', 'ồ' => 'o', 1634 'Ờ' => 'O', 'ờ' => 'o', 1635 'Ừ' => 'U', 'ừ' => 'u', 1636 'Ỳ' => 'Y', 'ỳ' => 'y', 1637 // hook 1638 'Ả' => 'A', 'ả' => 'a', 1639 'Ẩ' => 'A', 'ẩ' => 'a', 1640 'Ẳ' => 'A', 'ẳ' => 'a', 1641 'Ẻ' => 'E', 'ẻ' => 'e', 1642 'Ể' => 'E', 'ể' => 'e', 1643 'Ỉ' => 'I', 'ỉ' => 'i', 1644 'Ỏ' => 'O', 'ỏ' => 'o', 1645 'Ổ' => 'O', 'ổ' => 'o', 1646 'Ở' => 'O', 'ở' => 'o', 1647 'Ủ' => 'U', 'ủ' => 'u', 1648 'Ử' => 'U', 'ử' => 'u', 1649 'Ỷ' => 'Y', 'ỷ' => 'y', 1650 // tilde 1651 'Ẫ' => 'A', 'ẫ' => 'a', 1652 'Ẵ' => 'A', 'ẵ' => 'a', 1653 'Ẽ' => 'E', 'ẽ' => 'e', 1654 'Ễ' => 'E', 'ễ' => 'e', 1655 'Ỗ' => 'O', 'ỗ' => 'o', 1656 'Ỡ' => 'O', 'ỡ' => 'o', 1657 'Ữ' => 'U', 'ữ' => 'u', 1658 'Ỹ' => 'Y', 'ỹ' => 'y', 1659 // acute accent 1660 'Ấ' => 'A', 'ấ' => 'a', 1661 'Ắ' => 'A', 'ắ' => 'a', 1662 'Ế' => 'E', 'ế' => 'e', 1663 'Ố' => 'O', 'ố' => 'o', 1664 'Ớ' => 'O', 'ớ' => 'o', 1665 'Ứ' => 'U', 'ứ' => 'u', 1666 // dot below 1667 'Ạ' => 'A', 'ạ' => 'a', 1668 'Ậ' => 'A', 'ậ' => 'a', 1669 'Ặ' => 'A', 'ặ' => 'a', 1670 'Ẹ' => 'E', 'ẹ' => 'e', 1671 'Ệ' => 'E', 'ệ' => 'e', 1672 'Ị' => 'I', 'ị' => 'i', 1673 'Ọ' => 'O', 'ọ' => 'o', 1674 'Ộ' => 'O', 'ộ' => 'o', 1675 'Ợ' => 'O', 'ợ' => 'o', 1676 'Ụ' => 'U', 'ụ' => 'u', 1677 'Ự' => 'U', 'ự' => 'u', 1678 'Ỵ' => 'Y', 'ỵ' => 'y', 1679 // Vowels with diacritic (Chinese, Hanyu Pinyin) 1680 'ɑ' => 'a', 1681 // macron 1682 'Ǖ' => 'U', 'ǖ' => 'u', 1683 // acute accent 1684 'Ǘ' => 'U', 'ǘ' => 'u', 1685 // caron 1686 'Ǎ' => 'A', 'ǎ' => 'a', 1687 'Ǐ' => 'I', 'ǐ' => 'i', 1688 'Ǒ' => 'O', 'ǒ' => 'o', 1689 'Ǔ' => 'U', 'ǔ' => 'u', 1690 'Ǚ' => 'U', 'ǚ' => 'u', 1691 // grave accent 1692 'Ǜ' => 'U', 'ǜ' => 'u', 1581 // Decompositions for Latin-1 Supplement 1582 'ª' => 'a', 1583 'º' => 'o', 1584 'À' => 'A', 1585 'Á' => 'A', 1586 'Â' => 'A', 1587 'Ã' => 'A', 1588 'Ä' => 'A', 1589 'Å' => 'A', 1590 'Æ' => 'AE', 1591 'Ç' => 'C', 1592 'È' => 'E', 1593 'É' => 'E', 1594 'Ê' => 'E', 1595 'Ë' => 'E', 1596 'Ì' => 'I', 1597 'Í' => 'I', 1598 'Î' => 'I', 1599 'Ï' => 'I', 1600 'Ð' => 'D', 1601 'Ñ' => 'N', 1602 'Ò' => 'O', 1603 'Ó' => 'O', 1604 'Ô' => 'O', 1605 'Õ' => 'O', 1606 'Ö' => 'O', 1607 'Ù' => 'U', 1608 'Ú' => 'U', 1609 'Û' => 'U', 1610 'Ü' => 'U', 1611 'Ý' => 'Y', 1612 'Þ' => 'TH', 1613 'ß' => 's', 1614 'à' => 'a', 1615 'á' => 'a', 1616 'â' => 'a', 1617 'ã' => 'a', 1618 'ä' => 'a', 1619 'å' => 'a', 1620 'æ' => 'ae', 1621 'ç' => 'c', 1622 'è' => 'e', 1623 'é' => 'e', 1624 'ê' => 'e', 1625 'ë' => 'e', 1626 'ì' => 'i', 1627 'í' => 'i', 1628 'î' => 'i', 1629 'ï' => 'i', 1630 'ð' => 'd', 1631 'ñ' => 'n', 1632 'ò' => 'o', 1633 'ó' => 'o', 1634 'ô' => 'o', 1635 'õ' => 'o', 1636 'ö' => 'o', 1637 'ø' => 'o', 1638 'ù' => 'u', 1639 'ú' => 'u', 1640 'û' => 'u', 1641 'ü' => 'u', 1642 'ý' => 'y', 1643 'þ' => 'th', 1644 'ÿ' => 'y', 1645 'Ø' => 'O', 1646 // Decompositions for Latin Extended-A 1647 'Ā' => 'A', 1648 'ā' => 'a', 1649 'Ă' => 'A', 1650 'ă' => 'a', 1651 'Ą' => 'A', 1652 'ą' => 'a', 1653 'Ć' => 'C', 1654 'ć' => 'c', 1655 'Ĉ' => 'C', 1656 'ĉ' => 'c', 1657 'Ċ' => 'C', 1658 'ċ' => 'c', 1659 'Č' => 'C', 1660 'č' => 'c', 1661 'Ď' => 'D', 1662 'ď' => 'd', 1663 'Đ' => 'D', 1664 'đ' => 'd', 1665 'Ē' => 'E', 1666 'ē' => 'e', 1667 'Ĕ' => 'E', 1668 'ĕ' => 'e', 1669 'Ė' => 'E', 1670 'ė' => 'e', 1671 'Ę' => 'E', 1672 'ę' => 'e', 1673 'Ě' => 'E', 1674 'ě' => 'e', 1675 'Ĝ' => 'G', 1676 'ĝ' => 'g', 1677 'Ğ' => 'G', 1678 'ğ' => 'g', 1679 'Ġ' => 'G', 1680 'ġ' => 'g', 1681 'Ģ' => 'G', 1682 'ģ' => 'g', 1683 'Ĥ' => 'H', 1684 'ĥ' => 'h', 1685 'Ħ' => 'H', 1686 'ħ' => 'h', 1687 'Ĩ' => 'I', 1688 'ĩ' => 'i', 1689 'Ī' => 'I', 1690 'ī' => 'i', 1691 'Ĭ' => 'I', 1692 'ĭ' => 'i', 1693 'Į' => 'I', 1694 'į' => 'i', 1695 'İ' => 'I', 1696 'ı' => 'i', 1697 'IJ' => 'IJ', 1698 'ij' => 'ij', 1699 'Ĵ' => 'J', 1700 'ĵ' => 'j', 1701 'Ķ' => 'K', 1702 'ķ' => 'k', 1703 'ĸ' => 'k', 1704 'Ĺ' => 'L', 1705 'ĺ' => 'l', 1706 'Ļ' => 'L', 1707 'ļ' => 'l', 1708 'Ľ' => 'L', 1709 'ľ' => 'l', 1710 'Ŀ' => 'L', 1711 'ŀ' => 'l', 1712 'Ł' => 'L', 1713 'ł' => 'l', 1714 'Ń' => 'N', 1715 'ń' => 'n', 1716 'Ņ' => 'N', 1717 'ņ' => 'n', 1718 'Ň' => 'N', 1719 'ň' => 'n', 1720 'ʼn' => 'n', 1721 'Ŋ' => 'N', 1722 'ŋ' => 'n', 1723 'Ō' => 'O', 1724 'ō' => 'o', 1725 'Ŏ' => 'O', 1726 'ŏ' => 'o', 1727 'Ő' => 'O', 1728 'ő' => 'o', 1729 'Œ' => 'OE', 1730 'œ' => 'oe', 1731 'Ŕ' => 'R', 1732 'ŕ' => 'r', 1733 'Ŗ' => 'R', 1734 'ŗ' => 'r', 1735 'Ř' => 'R', 1736 'ř' => 'r', 1737 'Ś' => 'S', 1738 'ś' => 's', 1739 'Ŝ' => 'S', 1740 'ŝ' => 's', 1741 'Ş' => 'S', 1742 'ş' => 's', 1743 'Š' => 'S', 1744 'š' => 's', 1745 'Ţ' => 'T', 1746 'ţ' => 't', 1747 'Ť' => 'T', 1748 'ť' => 't', 1749 'Ŧ' => 'T', 1750 'ŧ' => 't', 1751 'Ũ' => 'U', 1752 'ũ' => 'u', 1753 'Ū' => 'U', 1754 'ū' => 'u', 1755 'Ŭ' => 'U', 1756 'ŭ' => 'u', 1757 'Ů' => 'U', 1758 'ů' => 'u', 1759 'Ű' => 'U', 1760 'ű' => 'u', 1761 'Ų' => 'U', 1762 'ų' => 'u', 1763 'Ŵ' => 'W', 1764 'ŵ' => 'w', 1765 'Ŷ' => 'Y', 1766 'ŷ' => 'y', 1767 'Ÿ' => 'Y', 1768 'Ź' => 'Z', 1769 'ź' => 'z', 1770 'Ż' => 'Z', 1771 'ż' => 'z', 1772 'Ž' => 'Z', 1773 'ž' => 'z', 1774 'ſ' => 's', 1775 // Decompositions for Latin Extended-B 1776 'Ș' => 'S', 1777 'ș' => 's', 1778 'Ț' => 'T', 1779 'ț' => 't', 1780 // Euro Sign 1781 '€' => 'E', 1782 // GBP (Pound) Sign 1783 '£' => '', 1784 // Vowels with diacritic (Vietnamese) 1785 // unmarked 1786 'Ơ' => 'O', 1787 'ơ' => 'o', 1788 'Ư' => 'U', 1789 'ư' => 'u', 1790 // grave accent 1791 'Ầ' => 'A', 1792 'ầ' => 'a', 1793 'Ằ' => 'A', 1794 'ằ' => 'a', 1795 'Ề' => 'E', 1796 'ề' => 'e', 1797 'Ồ' => 'O', 1798 'ồ' => 'o', 1799 'Ờ' => 'O', 1800 'ờ' => 'o', 1801 'Ừ' => 'U', 1802 'ừ' => 'u', 1803 'Ỳ' => 'Y', 1804 'ỳ' => 'y', 1805 // hook 1806 'Ả' => 'A', 1807 'ả' => 'a', 1808 'Ẩ' => 'A', 1809 'ẩ' => 'a', 1810 'Ẳ' => 'A', 1811 'ẳ' => 'a', 1812 'Ẻ' => 'E', 1813 'ẻ' => 'e', 1814 'Ể' => 'E', 1815 'ể' => 'e', 1816 'Ỉ' => 'I', 1817 'ỉ' => 'i', 1818 'Ỏ' => 'O', 1819 'ỏ' => 'o', 1820 'Ổ' => 'O', 1821 'ổ' => 'o', 1822 'Ở' => 'O', 1823 'ở' => 'o', 1824 'Ủ' => 'U', 1825 'ủ' => 'u', 1826 'Ử' => 'U', 1827 'ử' => 'u', 1828 'Ỷ' => 'Y', 1829 'ỷ' => 'y', 1830 // tilde 1831 'Ẫ' => 'A', 1832 'ẫ' => 'a', 1833 'Ẵ' => 'A', 1834 'ẵ' => 'a', 1835 'Ẽ' => 'E', 1836 'ẽ' => 'e', 1837 'Ễ' => 'E', 1838 'ễ' => 'e', 1839 'Ỗ' => 'O', 1840 'ỗ' => 'o', 1841 'Ỡ' => 'O', 1842 'ỡ' => 'o', 1843 'Ữ' => 'U', 1844 'ữ' => 'u', 1845 'Ỹ' => 'Y', 1846 'ỹ' => 'y', 1847 // acute accent 1848 'Ấ' => 'A', 1849 'ấ' => 'a', 1850 'Ắ' => 'A', 1851 'ắ' => 'a', 1852 'Ế' => 'E', 1853 'ế' => 'e', 1854 'Ố' => 'O', 1855 'ố' => 'o', 1856 'Ớ' => 'O', 1857 'ớ' => 'o', 1858 'Ứ' => 'U', 1859 'ứ' => 'u', 1860 // dot below 1861 'Ạ' => 'A', 1862 'ạ' => 'a', 1863 'Ậ' => 'A', 1864 'ậ' => 'a', 1865 'Ặ' => 'A', 1866 'ặ' => 'a', 1867 'Ẹ' => 'E', 1868 'ẹ' => 'e', 1869 'Ệ' => 'E', 1870 'ệ' => 'e', 1871 'Ị' => 'I', 1872 'ị' => 'i', 1873 'Ọ' => 'O', 1874 'ọ' => 'o', 1875 'Ộ' => 'O', 1876 'ộ' => 'o', 1877 'Ợ' => 'O', 1878 'ợ' => 'o', 1879 'Ụ' => 'U', 1880 'ụ' => 'u', 1881 'Ự' => 'U', 1882 'ự' => 'u', 1883 'Ỵ' => 'Y', 1884 'ỵ' => 'y', 1885 // Vowels with diacritic (Chinese, Hanyu Pinyin) 1886 'ɑ' => 'a', 1887 // macron 1888 'Ǖ' => 'U', 1889 'ǖ' => 'u', 1890 // acute accent 1891 'Ǘ' => 'U', 1892 'ǘ' => 'u', 1893 // caron 1894 'Ǎ' => 'A', 1895 'ǎ' => 'a', 1896 'Ǐ' => 'I', 1897 'ǐ' => 'i', 1898 'Ǒ' => 'O', 1899 'ǒ' => 'o', 1900 'Ǔ' => 'U', 1901 'ǔ' => 'u', 1902 'Ǚ' => 'U', 1903 'ǚ' => 'u', 1904 // grave accent 1905 'Ǜ' => 'U', 1906 'ǜ' => 'u', 1693 1907 ); 1694 1908 1695 1909 // Used for locale-specific rules 1696 1910 $locale = get_locale(); 1697 1911 1698 1912 if ( 'de_DE' == $locale || 'de_DE_formal' == $locale || 'de_CH' == $locale || 'de_CH_informal' == $locale ) { 1699 $chars[ 'Ä'] = 'Ae';1700 $chars[ 'ä'] = 'ae';1701 $chars[ 'Ö'] = 'Oe';1702 $chars[ 'ö'] = 'oe';1703 $chars[ 'Ü'] = 'Ue';1704 $chars[ 'ü'] = 'ue';1705 $chars[ 'ß'] = 'ss';1913 $chars['Ä'] = 'Ae'; 1914 $chars['ä'] = 'ae'; 1915 $chars['Ö'] = 'Oe'; 1916 $chars['ö'] = 'oe'; 1917 $chars['Ü'] = 'Ue'; 1918 $chars['ü'] = 'ue'; 1919 $chars['ß'] = 'ss'; 1706 1920 } elseif ( 'da_DK' === $locale ) { 1707 $chars[ 'Æ'] = 'Ae';1708 $chars[ 'æ'] = 'ae';1709 $chars[ 'Ø'] = 'Oe';1710 $chars[ 'ø'] = 'oe';1711 $chars[ 'Å'] = 'Aa';1712 $chars[ 'å'] = 'aa';1921 $chars['Æ'] = 'Ae'; 1922 $chars['æ'] = 'ae'; 1923 $chars['Ø'] = 'Oe'; 1924 $chars['ø'] = 'oe'; 1925 $chars['Å'] = 'Aa'; 1926 $chars['å'] = 'aa'; 1713 1927 } elseif ( 'ca' === $locale ) { 1714 $chars[ 'l·l'] = 'll';1928 $chars['l·l'] = 'll'; 1715 1929 } elseif ( 'sr_RS' === $locale || 'bs_BA' === $locale ) { 1716 $chars[ 'Đ'] = 'DJ';1717 $chars[ 'đ'] = 'dj';1930 $chars['Đ'] = 'DJ'; 1931 $chars['đ'] = 'dj'; 1718 1932 } 1719 1933 1720 $string = strtr( $string, $chars);1934 $string = strtr( $string, $chars ); 1721 1935 } else { 1722 1936 $chars = array(); 1723 1937 // Assume ISO-8859-1 if not UTF-8 1724 1938 $chars['in'] = "\x80\x83\x8a\x8e\x9a\x9e" 1725 ."\x9f\xa2\xa5\xb5\xc0\xc1\xc2"1726 ."\xc3\xc4\xc5\xc7\xc8\xc9\xca"1727 ."\xcb\xcc\xcd\xce\xcf\xd1\xd2"1728 ."\xd3\xd4\xd5\xd6\xd8\xd9\xda"1729 ."\xdb\xdc\xdd\xe0\xe1\xe2\xe3"1730 ."\xe4\xe5\xe7\xe8\xe9\xea\xeb"1731 ."\xec\xed\xee\xef\xf1\xf2\xf3"1732 ."\xf4\xf5\xf6\xf8\xf9\xfa\xfb"1733 ."\xfc\xfd\xff";1939 . "\x9f\xa2\xa5\xb5\xc0\xc1\xc2" 1940 . "\xc3\xc4\xc5\xc7\xc8\xc9\xca" 1941 . "\xcb\xcc\xcd\xce\xcf\xd1\xd2" 1942 . "\xd3\xd4\xd5\xd6\xd8\xd9\xda" 1943 . "\xdb\xdc\xdd\xe0\xe1\xe2\xe3" 1944 . "\xe4\xe5\xe7\xe8\xe9\xea\xeb" 1945 . "\xec\xed\xee\xef\xf1\xf2\xf3" 1946 . "\xf4\xf5\xf6\xf8\xf9\xfa\xfb" 1947 . "\xfc\xfd\xff"; 1734 1948 1735 1949 $chars['out'] = "EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy"; 1736 1950 1737 $string = strtr($string, $chars['in'], $chars['out']);1738 $double_chars = array();1739 $double_chars['in'] = array("\x8c", "\x9c", "\xc6", "\xd0", "\xde", "\xdf", "\xe6", "\xf0", "\xfe");1740 $double_chars['out'] = array( 'OE', 'oe', 'AE', 'DH', 'TH', 'ss', 'ae', 'dh', 'th');1741 $string = str_replace($double_chars['in'], $double_chars['out'], $string);1951 $string = strtr( $string, $chars['in'], $chars['out'] ); 1952 $double_chars = array(); 1953 $double_chars['in'] = array( "\x8c", "\x9c", "\xc6", "\xd0", "\xde", "\xdf", "\xe6", "\xf0", "\xfe" ); 1954 $double_chars['out'] = array( 'OE', 'oe', 'AE', 'DH', 'TH', 'ss', 'ae', 'dh', 'th' ); 1955 $string = str_replace( $double_chars['in'], $double_chars['out'], $string ); 1742 1956 } 1743 1957 1744 1958 return $string; … … 1757 1971 * @since 2.1.0 1758 1972 * 1759 1973 * @param string $filename The filename to be sanitized 1974 * 1760 1975 * @return string The sanitized filename 1761 1976 */ 1762 1977 function sanitize_file_name( $filename ) { 1763 $filename_raw = $filename; 1764 $special_chars = array("?", "[", "]", "/", "\\", "=", "<", ">", ":", ";", ",", "'", "\"", "&", "$", "#", "*", "(", ")", "|", "~", "`", "!", "{", "}", "%", "+", chr(0)); 1978 $filename_raw = $filename; 1979 $special_chars = array( 1980 "?", 1981 "[", 1982 "]", 1983 "/", 1984 "\\", 1985 "=", 1986 "<", 1987 ">", 1988 ":", 1989 ";", 1990 ",", 1991 "'", 1992 "\"", 1993 "&", 1994 "$", 1995 "#", 1996 "*", 1997 "(", 1998 ")", 1999 "|", 2000 "~", 2001 "`", 2002 "!", 2003 "{", 2004 "}", 2005 "%", 2006 "+", 2007 chr( 0 ) 2008 ); 1765 2009 /** 1766 2010 * Filters the list of characters to remove from a filename. 1767 2011 * 1768 2012 * @since 2.8.0 1769 2013 * 1770 * @param array 1771 * @param string $filename_raw 2014 * @param array $special_chars Characters to remove. 2015 * @param string $filename_raw Filename as it was passed into sanitize_file_name(). 1772 2016 */ 1773 2017 $special_chars = apply_filters( 'sanitize_file_name_chars', $special_chars, $filename_raw ); 1774 $filename = preg_replace( "#\x{00a0}#siu", ' ', $filename );1775 $filename = str_replace( $special_chars, '', $filename );1776 $filename = str_replace( array( '%20', '+' ), '-', $filename );1777 $filename = preg_replace( '/[\r\n\t -]+/', '-', $filename );1778 $filename = trim( $filename, '.-_' );2018 $filename = preg_replace( "#\x{00a0}#siu", ' ', $filename ); 2019 $filename = str_replace( $special_chars, '', $filename ); 2020 $filename = str_replace( array( '%20', '+' ), '-', $filename ); 2021 $filename = preg_replace( '/[\r\n\t -]+/', '-', $filename ); 2022 $filename = trim( $filename, '.-_' ); 1779 2023 1780 2024 if ( false === strpos( $filename, '.' ) ) { 1781 2025 $mime_types = wp_get_mime_types(); 1782 $filetype = wp_check_filetype( 'test.' . $filename, $mime_types );2026 $filetype = wp_check_filetype( 'test.' . $filename, $mime_types ); 1783 2027 if ( $filetype['ext'] === $filename ) { 1784 2028 $filename = 'unnamed-file.' . $filetype['ext']; 1785 2029 } 1786 2030 } 1787 2031 1788 2032 // Split the filename into a base and extension[s] 1789 $parts = explode( '.', $filename);2033 $parts = explode( '.', $filename ); 1790 2034 1791 2035 // Return if only one extension 1792 2036 if ( count( $parts ) <= 2 ) { … … 1795 2039 * 1796 2040 * @since 2.8.0 1797 2041 * 1798 * @param string $filename 2042 * @param string $filename Sanitized filename. 1799 2043 * @param string $filename_raw The filename prior to sanitization. 1800 2044 */ 1801 2045 return apply_filters( 'sanitize_file_name', $filename, $filename_raw ); 1802 2046 } 1803 2047 1804 2048 // Process multiple extensions 1805 $filename = array_shift($parts);1806 $extension = array_pop( $parts);1807 $mimes = get_allowed_mime_types();2049 $filename = array_shift( $parts ); 2050 $extension = array_pop( $parts ); 2051 $mimes = get_allowed_mime_types(); 1808 2052 1809 2053 /* 1810 2054 * Loop over any intermediate extensions. Postfix them with a trailing underscore 1811 2055 * if they are a 2 - 5 character long alpha string not in the extension whitelist. 1812 2056 */ 1813 foreach ( (array) $parts as $part ) {2057 foreach ( (array) $parts as $part ) { 1814 2058 $filename .= '.' . $part; 1815 2059 1816 if ( preg_match( "/^[a-zA-Z]{2,5}\d?$/", $part) ) {2060 if ( preg_match( "/^[a-zA-Z]{2,5}\d?$/", $part ) ) { 1817 2061 $allowed = false; 1818 2062 foreach ( $mimes as $ext_preg => $mime_match ) { 1819 2063 $ext_preg = '!^(' . $ext_preg . ')$!i'; … … 1822 2066 break; 1823 2067 } 1824 2068 } 1825 if ( ! $allowed )2069 if ( ! $allowed ) { 1826 2070 $filename .= '_'; 2071 } 1827 2072 } 1828 2073 } 1829 2074 $filename .= '.' . $extension; 2075 1830 2076 /** This filter is documented in wp-includes/formatting.php */ 1831 return apply_filters( 'sanitize_file_name', $filename, $filename_raw);2077 return apply_filters( 'sanitize_file_name', $filename, $filename_raw ); 1832 2078 } 1833 2079 1834 2080 /** … … 1842 2088 * @since 2.0.0 1843 2089 * 1844 2090 * @param string $username The username to be sanitized. 1845 * @param bool $strict If set limits $username to specific characters. Default false. 2091 * @param bool $strict If set limits $username to specific characters. Default false. 2092 * 1846 2093 * @return string The sanitized username, after passing through filters. 1847 2094 */ 1848 2095 function sanitize_user( $username, $strict = false ) { 1849 2096 $raw_username = $username; 1850 $username = wp_strip_all_tags( $username );1851 $username = remove_accents( $username );2097 $username = wp_strip_all_tags( $username ); 2098 $username = remove_accents( $username ); 1852 2099 // Kill octets 1853 2100 $username = preg_replace( '|%([a-fA-F0-9][a-fA-F0-9])|', '', $username ); 1854 2101 $username = preg_replace( '/&.+?;/', '', $username ); // Kill entities 1855 2102 1856 2103 // If strict, reduce to ASCII for max portability. 1857 if ( $strict ) 2104 if ( $strict ) { 1858 2105 $username = preg_replace( '|[^a-z0-9 _.\-@]|i', '', $username ); 2106 } 1859 2107 1860 2108 $username = trim( $username ); 1861 2109 // Consolidate contiguous whitespace … … 1866 2114 * 1867 2115 * @since 2.0.1 1868 2116 * 1869 * @param string $username 2117 * @param string $username Sanitized username. 1870 2118 * @param string $raw_username The username prior to sanitization. 1871 * @param bool $strictWhether to limit the sanitization to specific characters. Default false.2119 * @param bool $strict Whether to limit the sanitization to specific characters. Default false. 1872 2120 */ 1873 2121 return apply_filters( 'sanitize_user', $username, $raw_username, $strict ); 1874 2122 } … … 1881 2129 * @since 3.0.0 1882 2130 * 1883 2131 * @param string $key String key 2132 * 1884 2133 * @return string Sanitized key 1885 2134 */ 1886 2135 function sanitize_key( $key ) { 1887 2136 $raw_key = $key; 1888 $key = strtolower( $key );1889 $key = preg_replace( '/[^a-z0-9_\-]/', '', $key );2137 $key = strtolower( $key ); 2138 $key = preg_replace( '/[^a-z0-9_\-]/', '', $key ); 1890 2139 1891 2140 /** 1892 2141 * Filters a sanitized key string. 1893 2142 * 1894 2143 * @since 3.0.0 1895 2144 * 1896 * @param string $key 2145 * @param string $key Sanitized key. 1897 2146 * @param string $raw_key The key prior to sanitization. 1898 2147 */ 1899 2148 return apply_filters( 'sanitize_key', $key, $raw_key ); … … 1908 2157 * 1909 2158 * @since 1.0.0 1910 2159 * 1911 * @param string $title 2160 * @param string $title The string to be sanitized. 1912 2161 * @param string $fallback_title Optional. A title to use if $title is empty. 1913 * @param string $context Optional. The operation for which the string is sanitized 2162 * @param string $context Optional. The operation for which the string is sanitized 2163 * 1914 2164 * @return string The sanitized string. 1915 2165 */ 1916 2166 function sanitize_title( $title, $fallback_title = '', $context = 'save' ) { 1917 2167 $raw_title = $title; 1918 2168 1919 if ( 'save' == $context ) 1920 $title = remove_accents($title); 2169 if ( 'save' == $context ) { 2170 $title = remove_accents( $title ); 2171 } 1921 2172 1922 2173 /** 1923 2174 * Filters a sanitized title string. 1924 2175 * 1925 2176 * @since 1.2.0 1926 2177 * 1927 * @param string $title 2178 * @param string $title Sanitized title. 1928 2179 * @param string $raw_title The title prior to sanitization. 1929 * @param string $context 2180 * @param string $context The context for which the title is being sanitized. 1930 2181 */ 1931 2182 $title = apply_filters( 'sanitize_title', $title, $raw_title, $context ); 1932 2183 1933 if ( '' === $title || false === $title ) 2184 if ( '' === $title || false === $title ) { 1934 2185 $title = $fallback_title; 2186 } 1935 2187 1936 2188 return $title; 1937 2189 } … … 1944 2196 * @since 3.1.0 1945 2197 * 1946 2198 * @param string $title The string to be sanitized. 2199 * 1947 2200 * @return string The sanitized string. 1948 2201 */ 1949 2202 function sanitize_title_for_query( $title ) { … … 1958 2211 * 1959 2212 * @since 1.2.0 1960 2213 * 1961 * @param string $title 2214 * @param string $title The title to be sanitized. 1962 2215 * @param string $raw_title Optional. Not used. 1963 * @param string $context Optional. The operation for which the string is sanitized. 2216 * @param string $context Optional. The operation for which the string is sanitized. 2217 * 1964 2218 * @return string The sanitized title. 1965 2219 */ 1966 2220 function sanitize_title_with_dashes( $title, $raw_title = '', $context = 'display' ) { 1967 $title = strip_tags( $title);2221 $title = strip_tags( $title ); 1968 2222 // Preserve escaped octets. 1969 $title = preg_replace( '|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title);2223 $title = preg_replace( '|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title ); 1970 2224 // Remove percent signs that are not part of an octet. 1971 $title = str_replace( '%', '', $title);2225 $title = str_replace( '%', '', $title ); 1972 2226 // Restore octets. 1973 $title = preg_replace( '|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title);2227 $title = preg_replace( '|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title ); 1974 2228 1975 if ( seems_utf8($title)) {1976 if ( function_exists('mb_strtolower')) {1977 $title = mb_strtolower( $title, 'UTF-8');2229 if ( seems_utf8( $title ) ) { 2230 if ( function_exists( 'mb_strtolower' ) ) { 2231 $title = mb_strtolower( $title, 'UTF-8' ); 1978 2232 } 1979 $title = utf8_uri_encode( $title, 200);2233 $title = utf8_uri_encode( $title, 200 ); 1980 2234 } 1981 2235 1982 $title = strtolower( $title);2236 $title = strtolower( $title ); 1983 2237 1984 2238 if ( 'save' == $context ) { 1985 2239 // Convert nbsp, ndash and mdash to hyphens … … 1990 2244 // Strip these characters entirely 1991 2245 $title = str_replace( array( 1992 2246 // iexcl and iquest 1993 '%c2%a1', '%c2%bf', 2247 '%c2%a1', 2248 '%c2%bf', 1994 2249 // angle quotes 1995 '%c2%ab', '%c2%bb', '%e2%80%b9', '%e2%80%ba', 2250 '%c2%ab', 2251 '%c2%bb', 2252 '%e2%80%b9', 2253 '%e2%80%ba', 1996 2254 // curly quotes 1997 '%e2%80%98', '%e2%80%99', '%e2%80%9c', '%e2%80%9d', 1998 '%e2%80%9a', '%e2%80%9b', '%e2%80%9e', '%e2%80%9f', 2255 '%e2%80%98', 2256 '%e2%80%99', 2257 '%e2%80%9c', 2258 '%e2%80%9d', 2259 '%e2%80%9a', 2260 '%e2%80%9b', 2261 '%e2%80%9e', 2262 '%e2%80%9f', 1999 2263 // copy, reg, deg, hellip and trade 2000 '%c2%a9', '%c2%ae', '%c2%b0', '%e2%80%a6', '%e2%84%a2', 2264 '%c2%a9', 2265 '%c2%ae', 2266 '%c2%b0', 2267 '%e2%80%a6', 2268 '%e2%84%a2', 2001 2269 // acute accents 2002 '%c2%b4', '%cb%8a', '%cc%81', '%cd%81', 2270 '%c2%b4', 2271 '%cb%8a', 2272 '%cc%81', 2273 '%cd%81', 2003 2274 // grave accent, macron, caron 2004 '%cc%80', '%cc%84', '%cc%8c', 2275 '%cc%80', 2276 '%cc%84', 2277 '%cc%8c', 2005 2278 ), '', $title ); 2006 2279 2007 2280 // Convert times to x 2008 2281 $title = str_replace( '%c3%97', 'x', $title ); 2009 2282 } 2010 2283 2011 $title = preg_replace( '/&.+?;/', '', $title); // kill entities2012 $title = str_replace( '.', '-', $title);2284 $title = preg_replace( '/&.+?;/', '', $title ); // kill entities 2285 $title = str_replace( '.', '-', $title ); 2013 2286 2014 $title = preg_replace( '/[^%a-z0-9 _-]/', '', $title);2015 $title = preg_replace( '/\s+/', '-', $title);2016 $title = preg_replace( '|-+|', '-', $title);2017 $title = trim( $title, '-');2287 $title = preg_replace( '/[^%a-z0-9 _-]/', '', $title ); 2288 $title = preg_replace( '/\s+/', '-', $title ); 2289 $title = preg_replace( '|-+|', '-', $title ); 2290 $title = trim( $title, '-' ); 2018 2291 2019 2292 return $title; 2020 2293 } … … 2030 2303 * @since 2.5.1 2031 2304 * 2032 2305 * @param string $orderby Order by clause to be validated. 2306 * 2033 2307 * @return string|false Returns $orderby if valid, false otherwise. 2034 2308 */ 2035 2309 function sanitize_sql_orderby( $orderby ) { 2036 2310 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 ) ) { 2037 2311 return $orderby; 2038 2312 } 2313 2039 2314 return false; 2040 2315 } 2041 2316 … … 2049 2324 * 2050 2325 * @since 2.8.0 2051 2326 * 2052 * @param string $class 2327 * @param string $class The classname to be sanitized 2053 2328 * @param string $fallback Optional. The value to return if the sanitization ends up as an empty string. 2054 * Defaults to an empty string. 2329 * Defaults to an empty string. 2330 * 2055 2331 * @return string The sanitized value 2056 2332 */ 2057 2333 function sanitize_html_class( $class, $fallback = '' ) { … … 2064 2340 if ( '' == $sanitized && $fallback ) { 2065 2341 return sanitize_html_class( $fallback ); 2066 2342 } 2343 2067 2344 /** 2068 2345 * Filters a sanitized HTML class string. 2069 2346 * 2070 2347 * @since 2.8.0 2071 2348 * 2072 2349 * @param string $sanitized The sanitized HTML class. 2073 * @param string $class 2074 * @param string $fallback 2350 * @param string $class HTML class before sanitization. 2351 * @param string $fallback The fallback string. 2075 2352 */ 2076 2353 return apply_filters( 'sanitize_html_class', $sanitized, $class, $fallback ); 2077 2354 } … … 2081 2358 * 2082 2359 * @since 0.71 2083 2360 * 2084 * @param string $content 2361 * @param string $content String of characters to be converted. 2085 2362 * @param string $deprecated Not used. 2363 * 2086 2364 * @return string Converted string. 2087 2365 */ 2088 2366 function convert_chars( $content, $deprecated = '' ) { … … 2103 2381 * @since 4.3.0 2104 2382 * 2105 2383 * @param string $content String with entities that need converting. 2384 * 2106 2385 * @return string Converted string. 2107 2386 */ 2108 2387 function convert_invalid_entities( $content ) { … … 2153 2432 * 2154 2433 * @since 0.71 2155 2434 * 2156 * @param string $text Text to be balanced 2157 * @param bool $force If true, forces balancing, ignoring the value of the option. Default false. 2435 * @param string $text Text to be balanced 2436 * @param bool $force If true, forces balancing, ignoring the value of the option. Default false. 2437 * 2158 2438 * @return string Balanced text 2159 2439 */ 2160 2440 function balanceTags( $text, $force = false ) { 2161 if ( $force || get_option( 'use_balanceTags') == 1 ) {2441 if ( $force || get_option( 'use_balanceTags' ) == 1 ) { 2162 2442 return force_balance_tags( $text ); 2163 2443 } else { 2164 2444 return $text; … … 2176 2456 * @version 1.1 2177 2457 * @todo Make better - change loop condition to $text in 1.2 2178 2458 * @internal Modified by Scott Reilly (coffee2code) 02 Aug 2004 2179 * 2180 * 2181 * 2459 * 1.1 Fixed handling of append/stack pop order of end text 2460 * Added Cleaning Hooks 2461 * 1.0 First Version 2182 2462 * 2183 2463 * @param string $text Text to be balanced. 2464 * 2184 2465 * @return string Balanced text. 2185 2466 */ 2186 2467 function force_balance_tags( $text ) { 2187 $tagstack = array();2468 $tagstack = array(); 2188 2469 $stacksize = 0; 2189 $tagqueue = '';2190 $newtext = '';2470 $tagqueue = ''; 2471 $newtext = ''; 2191 2472 // Known single-entity/self-closing tags 2192 $single_tags = array( 'area', 'base', 'basefont', 'br', 'col', 'command', 'embed', 'frame', 'hr', 'img', 'input', 'isindex', 'link', 'meta', 'param', 'source' ); 2473 $single_tags = array( 2474 'area', 2475 'base', 2476 'basefont', 2477 'br', 2478 'col', 2479 'command', 2480 'embed', 2481 'frame', 2482 'hr', 2483 'img', 2484 'input', 2485 'isindex', 2486 'link', 2487 'meta', 2488 'param', 2489 'source' 2490 ); 2193 2491 // Tags that can be immediately nested within themselves 2194 2492 $nestable_tags = array( 'blockquote', 'div', 'object', 'q', 'span' ); 2195 2493 2196 2494 // WP bug fix for comments - in case you REALLY meant to type '< !--' 2197 $text = str_replace( '< !--', '< !--', $text);2495 $text = str_replace( '< !--', '< !--', $text ); 2198 2496 // WP bug fix for LOVE <3 (and other situations with '<' before a number) 2199 $text = preg_replace( '#<([0-9]{1})#', '<$1', $text);2497 $text = preg_replace( '#<([0-9]{1})#', '<$1', $text ); 2200 2498 2201 while ( preg_match( "/<(\/?[\w:]*)\s*([^>]*)>/", $text, $regex) ) {2499 while ( preg_match( "/<(\/?[\w:]*)\s*([^>]*)>/", $text, $regex ) ) { 2202 2500 $newtext .= $tagqueue; 2203 2501 2204 $i = strpos( $text, $regex[0]);2205 $l = strlen( $regex[0]);2502 $i = strpos( $text, $regex[0] ); 2503 $l = strlen( $regex[0] ); 2206 2504 2207 2505 // clear the shifter 2208 2506 $tagqueue = ''; 2209 2507 // Pop or Push 2210 if ( isset( $regex[1][0]) && '/' == $regex[1][0] ) { // End Tag2211 $tag = strtolower( substr($regex[1],1));2508 if ( isset( $regex[1][0] ) && '/' == $regex[1][0] ) { // End Tag 2509 $tag = strtolower( substr( $regex[1], 1 ) ); 2212 2510 // if too many closing tags 2213 2511 if ( $stacksize <= 0 ) { 2214 2512 $tag = ''; 2215 2513 // or close to be safe $tag = '/' . $tag; 2216 } 2217 // if stacktop value = tag close value then pop 2218 elseif ( $tagstack[$stacksize - 1] == $tag ) { // found closing tag 2514 } // if stacktop value = tag close value then pop 2515 elseif ( $tagstack[ $stacksize - 1 ] == $tag ) { // found closing tag 2219 2516 $tag = '</' . $tag . '>'; // Close Tag 2220 2517 // Pop 2221 2518 array_pop( $tagstack ); 2222 $stacksize --;2519 $stacksize --; 2223 2520 } else { // closing tag not at top, search for it 2224 for ( $j = $stacksize -1; $j >= 0; $j-- ) {2225 if ( $tagstack[ $j] == $tag ) {2226 // add tag to tagqueue2227 for ( $k = $stacksize -1; $k >= $j; $k--) {2521 for ( $j = $stacksize - 1; $j >= 0; $j -- ) { 2522 if ( $tagstack[ $j ] == $tag ) { 2523 // add tag to tagqueue 2524 for ( $k = $stacksize - 1; $k >= $j; $k -- ) { 2228 2525 $tagqueue .= '</' . array_pop( $tagstack ) . '>'; 2229 $stacksize --;2526 $stacksize --; 2230 2527 } 2231 2528 break; 2232 2529 } … … 2234 2531 $tag = ''; 2235 2532 } 2236 2533 } else { // Begin Tag 2237 $tag = strtolower( $regex[1]);2534 $tag = strtolower( $regex[1] ); 2238 2535 2239 2536 // Tag Cleaning 2240 2537 2241 2538 // If it's an empty tag "< >", do nothing 2242 2539 if ( '' == $tag ) { 2243 2540 // do nothing 2244 } 2245 // ElseIf it presents itself as a self-closing tag... 2246 elseif ( substr( $regex[2], -1 ) == '/' ) { 2541 } // ElseIf it presents itself as a self-closing tag... 2542 elseif ( substr( $regex[2], - 1 ) == '/' ) { 2247 2543 // ...but it isn't a known single-entity self-closing tag, then don't let it be treated as such and 2248 2544 // immediately close it with a closing tag (the tag will encapsulate no text as a result) 2249 if ( ! in_array( $tag, $single_tags ) ) 2250 $regex[2] = trim( substr( $regex[2], 0, - 1 ) ) . "></$tag";2251 }2252 // ElseIf it's a known single-entity tag but it doesn't close itself, do so2253 elseif ( in_array($tag, $single_tags) ) {2545 if ( ! in_array( $tag, $single_tags ) ) { 2546 $regex[2] = trim( substr( $regex[2], 0, - 1 ) ) . "></$tag"; 2547 } 2548 } // ElseIf it's a known single-entity tag but it doesn't close itself, do so 2549 elseif ( in_array( $tag, $single_tags ) ) { 2254 2550 $regex[2] .= '/'; 2255 } 2256 // Else it's not a single-entity tag 2551 } // Else it's not a single-entity tag 2257 2552 else { 2258 2553 // If the top of the stack is the same as the tag we want to push, close previous tag 2259 if ( $stacksize > 0 && ! in_array($tag, $nestable_tags) && $tagstack[$stacksize - 1] == $tag ) {2554 if ( $stacksize > 0 && ! in_array( $tag, $nestable_tags ) && $tagstack[ $stacksize - 1 ] == $tag ) { 2260 2555 $tagqueue = '</' . array_pop( $tagstack ) . '>'; 2261 $stacksize --;2556 $stacksize --; 2262 2557 } 2263 2558 $stacksize = array_push( $tagstack, $tag ); 2264 2559 } 2265 2560 2266 2561 // Attributes 2267 2562 $attributes = $regex[2]; 2268 if ( ! empty( $attributes ) && $attributes[0] != '>' ) 2563 if ( ! empty( $attributes ) && $attributes[0] != '>' ) { 2269 2564 $attributes = ' ' . $attributes; 2565 } 2270 2566 2271 2567 $tag = '<' . $tag . $attributes . '>'; 2272 2568 //If already queuing a close tag, then put this tag on, too 2273 if ( ! empty($tagqueue) ) {2569 if ( ! empty( $tagqueue ) ) { 2274 2570 $tagqueue .= $tag; 2275 $tag = '';2571 $tag = ''; 2276 2572 } 2277 2573 } 2278 $newtext .= substr( $text, 0, $i) . $tag;2279 $text = substr($text, $i + $l);2574 $newtext .= substr( $text, 0, $i ) . $tag; 2575 $text = substr( $text, $i + $l ); 2280 2576 } 2281 2577 2282 2578 // Clear Tag Queue … … 2286 2582 $newtext .= $text; 2287 2583 2288 2584 // Empty Stack 2289 while( $x = array_pop($tagstack) ) 2290 $newtext .= '</' . $x . '>'; // Add remaining tags to close 2585 while ( $x = array_pop( $tagstack ) ) { 2586 $newtext .= '</' . $x . '>'; 2587 } // Add remaining tags to close 2291 2588 2292 2589 // WP fix for the bug with HTML comments 2293 $newtext = str_replace( "< !--","<!--",$newtext);2294 $newtext = str_replace( "< !--","< !--",$newtext);2590 $newtext = str_replace( "< !--", "<!--", $newtext ); 2591 $newtext = str_replace( "< !--", "< !--", $newtext ); 2295 2592 2296 2593 return $newtext; 2297 2594 } … … 2306 2603 * @since 0.71 2307 2604 * @since 4.4.0 The `$richedit` parameter was renamed to `$rich_text` for clarity. 2308 2605 * 2309 * @param string $content 2310 * @param bool 2606 * @param string $content The text about to be edited. 2607 * @param bool $rich_text Optional. Whether `$content` should be considered rich text, 2311 2608 * in which case it would not be passed through esc_textarea(). 2312 2609 * Default false. 2610 * 2313 2611 * @return string The text after the filter (and possibly htmlspecialchars()) has been run. 2314 2612 */ 2315 2613 function format_to_edit( $content, $rich_text = false ) { … … 2321 2619 * @param string $content The text, prior to formatting for editing. 2322 2620 */ 2323 2621 $content = apply_filters( 'format_to_edit', $content ); 2324 if ( ! $rich_text ) 2622 if ( ! $rich_text ) { 2325 2623 $content = esc_textarea( $content ); 2624 } 2625 2326 2626 return $content; 2327 2627 } 2328 2628 … … 2339 2639 * 2340 2640 * @since 0.71 2341 2641 * 2342 * @param int $number Number to append zeros to if not greater than threshold. 2343 * @param int $threshold Digit places number needs to be to not have zeros added. 2642 * @param int $number Number to append zeros to if not greater than threshold. 2643 * @param int $threshold Digit places number needs to be to not have zeros added. 2644 * 2344 2645 * @return string Adds leading zeros to number if needed. 2345 2646 */ 2346 2647 function zeroise( $number, $threshold ) { … … 2353 2654 * @since 0.71 2354 2655 * 2355 2656 * @param string $string Value to which backslashes will be added. 2657 * 2356 2658 * @return string String with backslashes inserted. 2357 2659 */ 2358 2660 function backslashit( $string ) { 2359 if ( isset( $string[0] ) && $string[0] >= '0' && $string[0] <= '9' ) 2661 if ( isset( $string[0] ) && $string[0] >= '0' && $string[0] <= '9' ) { 2360 2662 $string = '\\\\' . $string; 2663 } 2664 2361 2665 return addcslashes( $string, 'A..Za..z' ); 2362 2666 } 2363 2667 … … 2373 2677 * @since 1.2.0 2374 2678 * 2375 2679 * @param string $string What to add the trailing slash to. 2680 * 2376 2681 * @return string String with trailing slash added. 2377 2682 */ 2378 2683 function trailingslashit( $string ) { … … 2388 2693 * @since 2.2.0 2389 2694 * 2390 2695 * @param string $string What to remove the trailing slashes from. 2696 * 2391 2697 * @return string String without the trailing slashes. 2392 2698 */ 2393 2699 function untrailingslashit( $string ) { … … 2403 2709 * @since 0.71 2404 2710 * 2405 2711 * @param string $gpc The string returned from HTTP request data. 2712 * 2406 2713 * @return string Returns a string escaped with slashes. 2407 2714 */ 2408 function addslashes_gpc($gpc) { 2409 if ( get_magic_quotes_gpc() ) 2410 $gpc = stripslashes($gpc); 2715 function addslashes_gpc( $gpc ) { 2716 if ( get_magic_quotes_gpc() ) { 2717 $gpc = stripslashes( $gpc ); 2718 } 2411 2719 2412 return wp_slash( $gpc);2720 return wp_slash( $gpc ); 2413 2721 } 2414 2722 2415 2723 /** … … 2418 2726 * @since 2.0.0 2419 2727 * 2420 2728 * @param mixed $value The value to be stripped. 2729 * 2421 2730 * @return mixed Stripped value. 2422 2731 */ 2423 2732 function stripslashes_deep( $value ) { … … 2430 2739 * @since 4.4.0 2431 2740 * 2432 2741 * @param mixed $value The array or string to be stripped. 2742 * 2433 2743 * @return mixed $value The stripped value. 2434 2744 */ 2435 2745 function stripslashes_from_strings_only( $value ) { … … 2442 2752 * @since 2.2.0 2443 2753 * 2444 2754 * @param mixed $value The array or string to be encoded. 2755 * 2445 2756 * @return mixed $value The encoded value. 2446 2757 */ 2447 2758 function urlencode_deep( $value ) { … … 2454 2765 * @since 3.4.0 2455 2766 * 2456 2767 * @param mixed $value The array or string to be encoded. 2768 * 2457 2769 * @return mixed $value The encoded value. 2458 2770 */ 2459 2771 function rawurlencode_deep( $value ) { … … 2466 2778 * @since 4.4.0 2467 2779 * 2468 2780 * @param mixed $value The array or string to be decoded. 2781 * 2469 2782 * @return mixed $value The decoded value. 2470 2783 */ 2471 2784 function urldecode_deep( $value ) { … … 2478 2791 * @since 0.71 2479 2792 * 2480 2793 * @param string $email_address Email address. 2481 * @param int $hex_encoding Optional. Set to 1 to enable hex encoding. 2794 * @param int $hex_encoding Optional. Set to 1 to enable hex encoding. 2795 * 2482 2796 * @return string Converted email address. 2483 2797 */ 2484 2798 function antispambot( $email_address, $hex_encoding = 0 ) { 2485 2799 $email_no_spam_address = ''; 2486 for ( $i = 0, $len = strlen( $email_address ); $i < $len; $i ++ ) {2800 for ( $i = 0, $len = strlen( $email_address ); $i < $len; $i ++ ) { 2487 2801 $j = rand( 0, 1 + $hex_encoding ); 2488 2802 if ( $j == 0 ) { 2489 $email_no_spam_address .= '&#' . ord( $email_address[ $i] ) . ';';2803 $email_no_spam_address .= '&#' . ord( $email_address[ $i ] ) . ';'; 2490 2804 } elseif ( $j == 1 ) { 2491 $email_no_spam_address .= $email_address[ $i];2805 $email_no_spam_address .= $email_address[ $i ]; 2492 2806 } elseif ( $j == 2 ) { 2493 $email_no_spam_address .= '%' . zeroise( dechex( ord( $email_address[ $i] ) ), 2 );2807 $email_no_spam_address .= '%' . zeroise( dechex( ord( $email_address[ $i ] ) ), 2 ); 2494 2808 } 2495 2809 } 2496 2810 … … 2506 2820 * @access private 2507 2821 * 2508 2822 * @param array $matches Single Regex Match. 2823 * 2509 2824 * @return string HTML A element with URI address. 2510 2825 */ 2511 2826 function _make_url_clickable_cb( $matches ) { … … 2514 2829 if ( ')' == $matches[3] && strpos( $url, '(' ) ) { 2515 2830 // If the trailing character is a closing parethesis, and the URL has an opening parenthesis in it, add the closing parenthesis to the URL. 2516 2831 // Then we can let the parenthesis balancer do its thing below. 2517 $url .= $matches[3];2832 $url .= $matches[3]; 2518 2833 $suffix = ''; 2519 2834 } else { 2520 2835 $suffix = $matches[3]; … … 2523 2838 // Include parentheses in the URL only if paired 2524 2839 while ( substr_count( $url, '(' ) < substr_count( $url, ')' ) ) { 2525 2840 $suffix = strrchr( $url, ')' ) . $suffix; 2526 $url = substr( $url, 0, strrpos( $url, ')' ) );2841 $url = substr( $url, 0, strrpos( $url, ')' ) ); 2527 2842 } 2528 2843 2529 $url = esc_url( $url);2530 if ( empty( $url) )2844 $url = esc_url( $url ); 2845 if ( empty( $url ) ) { 2531 2846 return $matches[0]; 2847 } 2532 2848 2533 2849 return $matches[1] . "<a href=\"$url\" rel=\"nofollow\">$url</a>" . $suffix; 2534 2850 } … … 2542 2858 * @access private 2543 2859 * 2544 2860 * @param array $matches Single Regex Match. 2861 * 2545 2862 * @return string HTML A element with URL address. 2546 2863 */ 2547 2864 function _make_web_ftp_clickable_cb( $matches ) { 2548 $ret = '';2865 $ret = ''; 2549 2866 $dest = $matches[2]; 2550 2867 $dest = 'http://' . $dest; 2551 2868 2552 2869 // removed trailing [.,;:)] from URL 2553 if ( in_array( substr( $dest, -1), array('.', ',', ';', ':', ')') ) === true ) {2554 $ret = substr($dest, -1);2555 $dest = substr( $dest, 0, strlen($dest)-1);2870 if ( in_array( substr( $dest, - 1 ), array( '.', ',', ';', ':', ')' ) ) === true ) { 2871 $ret = substr( $dest, - 1 ); 2872 $dest = substr( $dest, 0, strlen( $dest ) - 1 ); 2556 2873 } 2557 2874 2558 $dest = esc_url( $dest);2559 if ( empty( $dest) )2875 $dest = esc_url( $dest ); 2876 if ( empty( $dest ) ) { 2560 2877 return $matches[0]; 2878 } 2561 2879 2562 2880 return $matches[1] . "<a href=\"$dest\" rel=\"nofollow\">$dest</a>$ret"; 2563 2881 } … … 2571 2889 * @access private 2572 2890 * 2573 2891 * @param array $matches Single Regex Match. 2892 * 2574 2893 * @return string HTML A element with email address. 2575 2894 */ 2576 2895 function _make_email_clickable_cb( $matches ) { 2577 2896 $email = $matches[2] . '@' . $matches[3]; 2897 2578 2898 return $matches[1] . "<a href=\"mailto:$email\">$email</a>"; 2579 2899 } 2580 2900 … … 2587 2907 * @since 0.71 2588 2908 * 2589 2909 * @param string $text Content to convert URIs. 2910 * 2590 2911 * @return string Content with converted URIs. 2591 2912 */ 2592 2913 function make_clickable( $text ) { 2593 $r = '';2594 $textarr = preg_split( '/(<[^<>]+>)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // split out HTML tags2914 $r = ''; 2915 $textarr = preg_split( '/(<[^<>]+>)/', $text, - 1, PREG_SPLIT_DELIM_CAPTURE ); // split out HTML tags 2595 2916 $nested_code_pre = 0; // Keep track of how many levels link is nested inside <pre> or <code> 2596 2917 foreach ( $textarr as $piece ) { 2597 2918 2598 if ( preg_match( '|^<code[\s>]|i', $piece ) || preg_match( '|^<pre[\s>]|i', $piece ) || preg_match( '|^<script[\s>]|i', $piece ) || preg_match( '|^<style[\s>]|i', $piece ) ) 2599 $nested_code_pre++; 2600 elseif ( $nested_code_pre && ( '</code>' === strtolower( $piece ) || '</pre>' === strtolower( $piece ) || '</script>' === strtolower( $piece ) || '</style>' === strtolower( $piece ) ) ) 2601 $nested_code_pre--; 2919 if ( preg_match( '|^<code[\s>]|i', $piece ) || preg_match( '|^<pre[\s>]|i', $piece ) || preg_match( '|^<script[\s>]|i', $piece ) || preg_match( '|^<style[\s>]|i', $piece ) ) { 2920 $nested_code_pre ++; 2921 } elseif ( $nested_code_pre && ( '</code>' === strtolower( $piece ) || '</pre>' === strtolower( $piece ) || '</script>' === strtolower( $piece ) || '</style>' === strtolower( $piece ) ) ) { 2922 $nested_code_pre --; 2923 } 2602 2924 2603 2925 if ( $nested_code_pre || empty( $piece ) || ( $piece[0] === '<' && ! preg_match( '|^<\s*[\w]{1,20}+://|', $piece ) ) ) { 2604 2926 $r .= $piece; … … 2631 2953 ) 2632 2954 (\)?) # 3: Trailing closing parenthesis (for parethesis balancing post processing) 2633 2955 ~xS'; // The regex is a non-anchored pattern and does not have a single fixed starting character. 2634 2956 // Tell PCRE to spend more time optimizing since, when used on a page load, it will probably be used several times. 2635 2957 2636 2958 $ret = preg_replace_callback( $url_clickable, '_make_url_clickable_cb', $ret ); 2637 2959 2638 2960 $ret = preg_replace_callback( '#([\s>])((www|ftp)\.[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]+)#is', '_make_web_ftp_clickable_cb', $ret ); 2639 2961 $ret = preg_replace_callback( '#([\s>])([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})#i', '_make_email_clickable_cb', $ret ); 2640 2962 2641 $ret = substr( $ret, 1, - 1 ); // Remove our whitespace padding.2642 $r .= $ret;2963 $ret = substr( $ret, 1, - 1 ); // Remove our whitespace padding. 2964 $r .= $ret; 2643 2965 } 2644 2966 } 2645 2967 … … 2673 2995 * @access private 2674 2996 * 2675 2997 * @param string $string The string to split. 2676 * @param int $goal The desired chunk length. 2998 * @param int $goal The desired chunk length. 2999 * 2677 3000 * @return array Numeric array of chunks. 2678 3001 */ 2679 3002 function _split_str_by_whitespace( $string, $goal ) { … … 2691 3014 } 2692 3015 } 2693 3016 2694 $chunks[] = substr( $string, 0, $pos + 1 );2695 $string = substr( $string, $pos + 1 );3017 $chunks[] = substr( $string, 0, $pos + 1 ); 3018 $string = substr( $string, $pos + 1 ); 2696 3019 $string_nullspace = substr( $string_nullspace, $pos + 1 ); 2697 3020 } 2698 3021 … … 2709 3032 * @since 1.5.0 2710 3033 * 2711 3034 * @param string $text Content that may contain HTML A elements. 3035 * 2712 3036 * @return string Converted content. 2713 3037 */ 2714 3038 function wp_rel_nofollow( $text ) { 2715 3039 // This is a pre save filter, so text is already escaped. 2716 $text = stripslashes($text); 2717 $text = preg_replace_callback('|<a (.+?)>|i', 'wp_rel_nofollow_callback', $text); 3040 $text = stripslashes( $text ); 3041 $text = preg_replace_callback( '|<a (.+?)>|i', 'wp_rel_nofollow_callback', $text ); 3042 2718 3043 return wp_slash( $text ); 2719 3044 } 2720 3045 … … 2727 3052 * @since 2.3.0 2728 3053 * 2729 3054 * @param array $matches Single Match 3055 * 2730 3056 * @return string HTML A Element with rel nofollow. 2731 3057 */ 2732 3058 function wp_rel_nofollow_callback( $matches ) { … … 2754 3080 } 2755 3081 $text = trim( $html ); 2756 3082 } 3083 2757 3084 return "<a $text rel=\"$rel\">"; 2758 3085 } 2759 3086 … … 2770 3097 * @global array $wpsmiliestrans 2771 3098 * 2772 3099 * @param array $matches Single match. Smiley code to convert to image. 3100 * 2773 3101 * @return string Image string for smiley. 2774 3102 */ 2775 3103 function translate_smiley( $matches ) { 2776 3104 global $wpsmiliestrans; 2777 3105 2778 if ( count( $matches ) == 0 ) 3106 if ( count( $matches ) == 0 ) { 2779 3107 return ''; 3108 } 2780 3109 2781 3110 $smiley = trim( reset( $matches ) ); 2782 $img = $wpsmiliestrans[ $smiley ];3111 $img = $wpsmiliestrans[ $smiley ]; 2783 3112 2784 $matches = array();2785 $ext = preg_match( '/\.([^.]+)$/', $img, $matches ) ? strtolower( $matches[1] ) : false;3113 $matches = array(); 3114 $ext = preg_match( '/\.([^.]+)$/', $img, $matches ) ? strtolower( $matches[1] ) : false; 2786 3115 $image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png' ); 2787 3116 2788 3117 // Don't convert smilies that aren't images - they're probably emoji. … … 2796 3125 * @since 2.9.0 2797 3126 * 2798 3127 * @param string $smiley_url URL for the smiley image. 2799 * @param string $img 2800 * @param string $site_url 3128 * @param string $img Filename for the smiley image. 3129 * @param string $site_url Site URL, as returned by site_url(). 2801 3130 */ 2802 3131 $src_url = apply_filters( 'smilies_src', includes_url( "images/smilies/$img" ), $img, site_url() ); 2803 3132 … … 2815 3144 * @global string|array $wp_smiliessearch 2816 3145 * 2817 3146 * @param string $text Content to convert smilies from text. 3147 * 2818 3148 * @return string Converted content with text smilies replaced with images. 2819 3149 */ 2820 3150 function convert_smilies( $text ) { … … 2822 3152 $output = ''; 2823 3153 if ( get_option( 'use_smilies' ) && ! empty( $wp_smiliessearch ) ) { 2824 3154 // HTML loop taken from texturize function, could possible be consolidated 2825 $textarr = preg_split( '/(<.*>)/U', $text, - 1, PREG_SPLIT_DELIM_CAPTURE ); // capture the tags as well as in between2826 $stop = count( $textarr );// loop stuff3155 $textarr = preg_split( '/(<.*>)/U', $text, - 1, PREG_SPLIT_DELIM_CAPTURE ); // capture the tags as well as in between 3156 $stop = count( $textarr );// loop stuff 2827 3157 2828 3158 // Ignore proessing of specific tags 2829 $tags_to_ignore = 'code|pre|style|script|textarea';3159 $tags_to_ignore = 'code|pre|style|script|textarea'; 2830 3160 $ignore_block_element = ''; 2831 3161 2832 for ( $i = 0; $i < $stop; $i ++ ) {2833 $content = $textarr[ $i];3162 for ( $i = 0; $i < $stop; $i ++ ) { 3163 $content = $textarr[ $i ]; 2834 3164 2835 3165 // If we're in an ignore block, wait until we find its closing tag 2836 if ( '' == $ignore_block_element && preg_match( '/^<(' . $tags_to_ignore . ')>/', $content, $matches ) ) 3166 if ( '' == $ignore_block_element && preg_match( '/^<(' . $tags_to_ignore . ')>/', $content, $matches ) ) { 2837 3167 $ignore_block_element = $matches[1]; 2838 3168 } 2839 3169 2840 3170 // If it's not a tag and not in ignore block 2841 if ( '' == 3171 if ( '' == $ignore_block_element && strlen( $content ) > 0 && '<' != $content[0] ) { 2842 3172 $content = preg_replace_callback( $wp_smiliessearch, 'translate_smiley', $content ); 2843 3173 } 2844 3174 2845 3175 // did we exit ignore block 2846 if ( '' != $ignore_block_element && '</' . $ignore_block_element . '>' == $content ) 3176 if ( '' != $ignore_block_element && '</' . $ignore_block_element . '>' == $content ) { 2847 3177 $ignore_block_element = ''; 2848 3178 } 2849 3179 … … 2853 3183 // return default text. 2854 3184 $output = $text; 2855 3185 } 3186 2856 3187 return $output; 2857 3188 } 2858 3189 … … 2863 3194 * 2864 3195 * @since 0.71 2865 3196 * 2866 * @param string $email Email address to verify. 2867 * @param bool $deprecated Deprecated. 3197 * @param string $email Email address to verify. 3198 * @param bool $deprecated Deprecated. 3199 * 2868 3200 * @return string|bool Either false or the valid email address. 2869 3201 */ 2870 3202 function is_email( $email, $deprecated = false ) { 2871 if ( ! empty( $deprecated ) ) 3203 if ( ! empty( $deprecated ) ) { 2872 3204 _deprecated_argument( __FUNCTION__, '3.0.0' ); 3205 } 2873 3206 2874 3207 // Test for the minimum length the email can be 2875 3208 if ( strlen( $email ) < 3 ) { … … 2882 3215 * 2883 3216 * @since 2.8.0 2884 3217 * 2885 * @param bool 2886 * @param string $email 2887 * @param string $context 3218 * @param bool $is_email Whether the email address has passed the is_email() checks. Default false. 3219 * @param string $email The email address being checked. 3220 * @param string $context Context under which the email was tested. 2888 3221 */ 2889 3222 return apply_filters( 'is_email', false, $email, 'email_too_short' ); 2890 3223 } … … 2900 3233 2901 3234 // LOCAL PART 2902 3235 // Test for invalid characters 2903 if ( ! preg_match( '/^[a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]+$/', $local ) ) {3236 if ( ! preg_match( '/^[a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]+$/', $local ) ) { 2904 3237 /** This filter is documented in wp-includes/formatting.php */ 2905 3238 return apply_filters( 'is_email', false, $email, 'local_invalid_chars' ); 2906 3239 } … … 2936 3269 } 2937 3270 2938 3271 // Test for invalid characters 2939 if ( ! preg_match('/^[a-z0-9-]+$/i', $sub ) ) {3272 if ( ! preg_match( '/^[a-z0-9-]+$/i', $sub ) ) { 2940 3273 /** This filter is documented in wp-includes/formatting.php */ 2941 3274 return apply_filters( 'is_email', false, $email, 'sub_invalid_chars' ); 2942 3275 } 2943 3276 } 2944 3277 2945 3278 // Congratulations your email made it! 3279 2946 3280 /** This filter is documented in wp-includes/formatting.php */ 2947 3281 return apply_filters( 'is_email', $email, $email, null ); 2948 3282 } … … 2953 3287 * @since 1.2.0 2954 3288 * 2955 3289 * @param string $string Subject line 3290 * 2956 3291 * @return string Converted string to ASCII 2957 3292 */ 2958 3293 function wp_iso_descrambler( $string ) { 2959 3294 /* this may only work with iso-8859-1, I'm afraid */ 2960 if ( !preg_match('#\=\?(.+)\?Q\?(.+)\?\=#i', $string, $matches)) {3295 if ( ! preg_match( '#\=\?(.+)\?Q\?(.+)\?\=#i', $string, $matches ) ) { 2961 3296 return $string; 2962 3297 } else { 2963 $subject = str_replace('_', ' ', $matches[2]); 3298 $subject = str_replace( '_', ' ', $matches[2] ); 3299 2964 3300 return preg_replace_callback( '#\=([0-9a-f]{2})#i', '_wp_iso_convert', $subject ); 2965 3301 } 2966 3302 } … … 2972 3308 * @access private 2973 3309 * 2974 3310 * @param array $match The preg_replace_callback matches array 3311 * 2975 3312 * @return string Converted chars 2976 3313 */ 2977 3314 function _wp_iso_convert( $match ) { … … 2990 3327 * 2991 3328 * @param string $string The date to be converted. 2992 3329 * @param string $format The format string for the returned date (default is Y-m-d H:i:s) 3330 * 2993 3331 * @return string GMT version of the date provided. 2994 3332 */ 2995 3333 function get_gmt_from_date( $string, $format = 'Y-m-d H:i:s' ) { … … 3007 3345 if ( false === $datetime ) { 3008 3346 return gmdate( $format, 0 ); 3009 3347 } 3348 3010 3349 return gmdate( $format, $datetime ); 3011 3350 } 3012 3351 $string_time = gmmktime( $matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1] ); 3013 $string_gmt = gmdate( $format, $string_time - get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );3352 $string_gmt = gmdate( $format, $string_time - get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); 3014 3353 } 3354 3015 3355 return $string_gmt; 3016 3356 } 3017 3357 … … 3027 3367 * 3028 3368 * @param string $string The date to be converted. 3029 3369 * @param string $format The format string for the returned date (default is Y-m-d H:i:s) 3370 * 3030 3371 * @return string Formatted date relative to the timezone / GMT offset. 3031 3372 */ 3032 3373 function get_date_from_gmt( $string, $format = 'Y-m-d H:i:s' ) { 3033 3374 $tz = get_option( 'timezone_string' ); 3034 3375 if ( $tz ) { 3035 3376 $datetime = date_create( $string, new DateTimeZone( 'UTC' ) ); 3036 if ( ! $datetime ) 3377 if ( ! $datetime ) { 3037 3378 return date( $format, 0 ); 3379 } 3038 3380 $datetime->setTimezone( new DateTimeZone( $tz ) ); 3039 3381 $string_localtime = $datetime->format( $format ); 3040 3382 } else { 3041 if ( ! preg_match( '#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $string, $matches) )3383 if ( ! preg_match( '#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $string, $matches ) ) { 3042 3384 return date( $format, 0 ); 3043 $string_time = gmmktime( $matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1] ); 3385 } 3386 $string_time = gmmktime( $matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1] ); 3044 3387 $string_localtime = gmdate( $format, $string_time + get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); 3045 3388 } 3389 3046 3390 return $string_localtime; 3047 3391 } 3048 3392 … … 3052 3396 * @since 1.5.0 3053 3397 * 3054 3398 * @param string $timezone Either 'Z' for 0 offset or '±hhmm'. 3399 * 3055 3400 * @return int|float The offset in seconds. 3056 3401 */ 3057 3402 function iso8601_timezone_to_offset( $timezone ) { 3058 3403 // $timezone is either 'Z' or '[+|-]hhmm' 3059 if ( $timezone == 'Z') {3404 if ( $timezone == 'Z' ) { 3060 3405 $offset = 0; 3061 3406 } else { 3062 $sign = ( substr($timezone, 0, 1) == '+') ? 1 : -1;3063 $hours = intval( substr($timezone, 1, 2));3064 $minutes = intval( substr($timezone, 3, 4)) / 60;3065 $offset = $sign * HOUR_IN_SECONDS * ( $hours + $minutes);3407 $sign = ( substr( $timezone, 0, 1 ) == '+' ) ? 1 : - 1; 3408 $hours = intval( substr( $timezone, 1, 2 ) ); 3409 $minutes = intval( substr( $timezone, 3, 4 ) ) / 60; 3410 $offset = $sign * HOUR_IN_SECONDS * ( $hours + $minutes ); 3066 3411 } 3412 3067 3413 return $offset; 3068 3414 } 3069 3415 … … 3073 3419 * @since 1.5.0 3074 3420 * 3075 3421 * @param string $date_string Date and time in ISO 8601 format {@link https://en.wikipedia.org/wiki/ISO_8601}. 3076 * @param string $timezone Optional. If set to GMT returns the time minus gmt_offset. Default is 'user'. 3422 * @param string $timezone Optional. If set to GMT returns the time minus gmt_offset. Default is 'user'. 3423 * 3077 3424 * @return string The date and time in MySQL DateTime format - Y-m-d H:i:s. 3078 3425 */ 3079 3426 function iso8601_to_datetime( $date_string, $timezone = 'user' ) { 3080 $timezone = strtolower( $timezone);3427 $timezone = strtolower( $timezone ); 3081 3428 3082 if ( $timezone == 'gmt') {3429 if ( $timezone == 'gmt' ) { 3083 3430 3084 preg_match( '#([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(Z|[\+|\-][0-9]{2,4}){0,1}#', $date_string, $date_bits);3431 preg_match( '#([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(Z|[\+|\-][0-9]{2,4}){0,1}#', $date_string, $date_bits ); 3085 3432 3086 if ( !empty($date_bits[7])) { // we have a timezone, so let's compute an offset3087 $offset = iso8601_timezone_to_offset( $date_bits[7]);3433 if ( ! empty( $date_bits[7] ) ) { // we have a timezone, so let's compute an offset 3434 $offset = iso8601_timezone_to_offset( $date_bits[7] ); 3088 3435 } else { // we don't have a timezone, so we assume user local timezone (not server's!) 3089 $offset = HOUR_IN_SECONDS * get_option( 'gmt_offset');3436 $offset = HOUR_IN_SECONDS * get_option( 'gmt_offset' ); 3090 3437 } 3091 3438 3092 $timestamp = gmmktime( $date_bits[4], $date_bits[5], $date_bits[6], $date_bits[2], $date_bits[3], $date_bits[1]);3439 $timestamp = gmmktime( $date_bits[4], $date_bits[5], $date_bits[6], $date_bits[2], $date_bits[3], $date_bits[1] ); 3093 3440 $timestamp -= $offset; 3094 3441 3095 return gmdate( 'Y-m-d H:i:s', $timestamp);3442 return gmdate( 'Y-m-d H:i:s', $timestamp ); 3096 3443 3097 } elseif ( $timezone == 'user') {3098 return preg_replace( '#([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(Z|[\+|\-][0-9]{2,4}){0,1}#', '$1-$2-$3 $4:$5:$6', $date_string);3444 } elseif ( $timezone == 'user' ) { 3445 return preg_replace( '#([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(Z|[\+|\-][0-9]{2,4}){0,1}#', '$1-$2-$3 $4:$5:$6', $date_string ); 3099 3446 } 3100 3447 } 3101 3448 … … 3105 3452 * @since 1.5.0 3106 3453 * 3107 3454 * @param string $email Email address to filter. 3455 * 3108 3456 * @return string Filtered email address. 3109 3457 */ 3110 3458 function sanitize_email( $email ) { … … 3119 3467 * 3120 3468 * @since 2.8.0 3121 3469 * 3122 * @param string $email 3123 * @param string $email 3470 * @param string $email The sanitized email address. 3471 * @param string $email The email address, as provided to sanitize_email(). 3124 3472 * @param string $message A message to pass to the user. 3125 3473 */ 3126 3474 return apply_filters( 'sanitize_email', '', $email, 'email_too_short' ); … … 3197 3545 $email = $local . '@' . $domain; 3198 3546 3199 3547 // Congratulations your email made it! 3548 3200 3549 /** This filter is documented in wp-includes/formatting.php */ 3201 3550 return apply_filters( 'sanitize_email', $email, $email, null ); 3202 3551 } … … 3210 3559 * @since 1.5.0 3211 3560 * 3212 3561 * @param int $from Unix timestamp from which the difference begins. 3213 * @param int $to Optional. Unix timestamp to end the time difference. Default becomes time() if not set. 3562 * @param int $to Optional. Unix timestamp to end the time difference. Default becomes time() if not set. 3563 * 3214 3564 * @return string Human readable time difference. 3215 3565 */ 3216 3566 function human_time_diff( $from, $to = '' ) { … … 3222 3572 3223 3573 if ( $diff < HOUR_IN_SECONDS ) { 3224 3574 $mins = round( $diff / MINUTE_IN_SECONDS ); 3225 if ( $mins <= 1 ) 3575 if ( $mins <= 1 ) { 3226 3576 $mins = 1; 3577 } 3227 3578 /* translators: Time difference between two dates, in minutes (min=minute). 1: Number of minutes */ 3228 3579 $since = sprintf( _n( '%s min', '%s mins', $mins ), $mins ); 3229 3580 } elseif ( $diff < DAY_IN_SECONDS && $diff >= HOUR_IN_SECONDS ) { 3230 3581 $hours = round( $diff / HOUR_IN_SECONDS ); 3231 if ( $hours <= 1 ) 3582 if ( $hours <= 1 ) { 3232 3583 $hours = 1; 3584 } 3233 3585 /* translators: Time difference between two dates, in hours. 1: Number of hours */ 3234 3586 $since = sprintf( _n( '%s hour', '%s hours', $hours ), $hours ); 3235 3587 } elseif ( $diff < WEEK_IN_SECONDS && $diff >= DAY_IN_SECONDS ) { 3236 3588 $days = round( $diff / DAY_IN_SECONDS ); 3237 if ( $days <= 1 ) 3589 if ( $days <= 1 ) { 3238 3590 $days = 1; 3591 } 3239 3592 /* translators: Time difference between two dates, in days. 1: Number of days */ 3240 3593 $since = sprintf( _n( '%s day', '%s days', $days ), $days ); 3241 3594 } elseif ( $diff < MONTH_IN_SECONDS && $diff >= WEEK_IN_SECONDS ) { 3242 3595 $weeks = round( $diff / WEEK_IN_SECONDS ); 3243 if ( $weeks <= 1 ) 3596 if ( $weeks <= 1 ) { 3244 3597 $weeks = 1; 3598 } 3245 3599 /* translators: Time difference between two dates, in weeks. 1: Number of weeks */ 3246 3600 $since = sprintf( _n( '%s week', '%s weeks', $weeks ), $weeks ); 3247 3601 } elseif ( $diff < YEAR_IN_SECONDS && $diff >= MONTH_IN_SECONDS ) { 3248 3602 $months = round( $diff / MONTH_IN_SECONDS ); 3249 if ( $months <= 1 ) 3603 if ( $months <= 1 ) { 3250 3604 $months = 1; 3605 } 3251 3606 /* translators: Time difference between two dates, in months. 1: Number of months */ 3252 3607 $since = sprintf( _n( '%s month', '%s months', $months ), $months ); 3253 3608 } elseif ( $diff >= YEAR_IN_SECONDS ) { 3254 3609 $years = round( $diff / YEAR_IN_SECONDS ); 3255 if ( $years <= 1 ) 3610 if ( $years <= 1 ) { 3256 3611 $years = 1; 3612 } 3257 3613 /* translators: Time difference between two dates, in years. 1: Number of years */ 3258 3614 $since = sprintf( _n( '%s year', '%s years', $years ), $years ); 3259 3615 } … … 3264 3620 * @since 4.0.0 3265 3621 * 3266 3622 * @param string $since The difference in human readable text. 3267 * @param int $diffThe difference in seconds.3268 * @param int $fromUnix timestamp from which the difference begins.3269 * @param int $toUnix timestamp to end the time difference.3623 * @param int $diff The difference in seconds. 3624 * @param int $from Unix timestamp from which the difference begins. 3625 * @param int $to Unix timestamp to end the time difference. 3270 3626 */ 3271 3627 return apply_filters( 'human_time_diff', $since, $diff, $from, $to ); 3272 3628 } … … 3284 3640 * @since 1.5.0 3285 3641 * 3286 3642 * @param string $text Optional. The excerpt. If set to empty, an excerpt is generated. 3643 * 3287 3644 * @return string The excerpt. 3288 3645 */ 3289 3646 function wp_trim_excerpt( $text = '' ) { 3290 3647 $raw_excerpt = $text; 3291 3648 if ( '' == $text ) { 3292 $text = get_the_content( '');3649 $text = get_the_content( '' ); 3293 3650 3294 3651 $text = strip_shortcodes( $text ); 3295 3652 3296 3653 /** This filter is documented in wp-includes/post-template.php */ 3297 3654 $text = apply_filters( 'the_content', $text ); 3298 $text = str_replace( ']]>', ']]>', $text);3655 $text = str_replace( ']]>', ']]>', $text ); 3299 3656 3300 3657 /** 3301 3658 * Filters the number of words in an excerpt. … … 3313 3670 * @param string $more_string The string shown within the more link. 3314 3671 */ 3315 3672 $excerpt_more = apply_filters( 'excerpt_more', ' ' . '[…]' ); 3316 $text = wp_trim_words( $text, $excerpt_length, $excerpt_more );3673 $text = wp_trim_words( $text, $excerpt_length, $excerpt_more ); 3317 3674 } 3675 3318 3676 /** 3319 3677 * Filters the trimmed excerpt string. 3320 3678 * 3321 3679 * @since 2.8.0 3322 3680 * 3323 * @param string $text 3681 * @param string $text The trimmed text. 3324 3682 * @param string $raw_excerpt The text prior to trimming. 3325 3683 */ 3326 3684 return apply_filters( 'wp_trim_excerpt', $text, $raw_excerpt ); … … 3335 3693 * 3336 3694 * @since 3.3.0 3337 3695 * 3338 * @param string $text Text to trim. 3339 * @param int $num_words Number of words. Default 55. 3340 * @param string $more Optional. What to append if $text needs to be trimmed. Default '…'. 3696 * @param string $text Text to trim. 3697 * @param int $num_words Number of words. Default 55. 3698 * @param string $more Optional. What to append if $text needs to be trimmed. Default '…'. 3699 * 3341 3700 * @return string Trimmed text. 3342 3701 */ 3343 3702 function wp_trim_words( $text, $num_words = 55, $more = null ) { … … 3346 3705 } 3347 3706 3348 3707 $original_text = $text; 3349 $text = wp_strip_all_tags( $text );3708 $text = wp_strip_all_tags( $text ); 3350 3709 3351 3710 /* 3352 3711 * translators: If your word count is based on single characters (e.g. East Asian characters), … … 3357 3716 $text = trim( preg_replace( "/[\n\r\t ]+/", ' ', $text ), ' ' ); 3358 3717 preg_match_all( '/./u', $text, $words_array ); 3359 3718 $words_array = array_slice( $words_array[0], 0, $num_words + 1 ); 3360 $sep = '';3719 $sep = ''; 3361 3720 } else { 3362 3721 $words_array = preg_split( "/[\n\r\t ]+/", $text, $num_words + 1, PREG_SPLIT_NO_EMPTY ); 3363 $sep = ' ';3722 $sep = ' '; 3364 3723 } 3365 3724 3366 3725 if ( count( $words_array ) > $num_words ) { … … 3376 3735 * 3377 3736 * @since 3.3.0 3378 3737 * 3379 * @param string $text 3380 * @param int $num_wordsThe number of words to trim the text to. Default 55.3381 * @param string $more 3738 * @param string $text The trimmed text. 3739 * @param int $num_words The number of words to trim the text to. Default 55. 3740 * @param string $more An optional string to append to the end of the trimmed text, e.g. …. 3382 3741 * @param string $original_text The text before it was trimmed. 3383 3742 */ 3384 3743 return apply_filters( 'wp_trim_words', $text, $num_words, $more, $original_text ); … … 3390 3749 * @since 1.5.1 3391 3750 * 3392 3751 * @param string $text The text within which entities will be converted. 3752 * 3393 3753 * @return string Text with converted entities. 3394 3754 */ 3395 3755 function ent2ncr( $text ) { … … 3401 3761 * 3402 3762 * @since 3.3.0 3403 3763 * 3404 * @param null 3405 * @param string $text 3764 * @param null $converted_text The text to be converted. Default null. 3765 * @param string $text The text prior to entity conversion. 3406 3766 */ 3407 3767 $filtered = apply_filters( 'pre_ent2ncr', null, $text ); 3408 if ( null !== $filtered ) 3768 if ( null !== $filtered ) { 3409 3769 return $filtered; 3770 } 3410 3771 3411 3772 $to_ncr = array( 3412 '"' => '"',3413 '&' => '&',3414 '<' => '<',3415 '>' => '>',3416 '|' => '|',3417 ' ' => ' ',3418 '¡' => '¡',3419 '¢' => '¢',3420 '£' => '£',3421 '¤' => '¤',3422 '¥' => '¥',3423 '¦' => '¦',3424 '&brkbar;' => '¦',3425 '§' => '§',3426 '¨' => '¨',3427 '¨' => '¨',3428 '©' => '©',3429 'ª' => 'ª',3430 '«' => '«',3431 '¬' => '¬',3432 '­' => '­',3433 '®' => '®',3434 '¯' => '¯',3435 '&hibar;' => '¯',3436 '°' => '°',3437 '±' => '±',3438 '²' => '²',3439 '³' => '³',3440 '´' => '´',3441 'µ' => 'µ',3442 '¶' => '¶',3443 '·' => '·',3444 '¸' => '¸',3445 '¹' => '¹',3446 'º' => 'º',3447 '»' => '»',3448 '¼' => '¼',3449 '½' => '½',3450 '¾' => '¾',3451 '¿' => '¿',3452 'À' => 'À',3453 'Á' => 'Á',3454 'Â' => 'Â',3455 'Ã' => 'Ã',3456 'Ä' => 'Ä',3457 'Å' => 'Å',3458 'Æ' => 'Æ',3459 'Ç' => 'Ç',3460 'È' => 'È',3461 'É' => 'É',3462 'Ê' => 'Ê',3463 'Ë' => 'Ë',3464 'Ì' => 'Ì',3465 'Í' => 'Í',3466 'Î' => 'Î',3467 'Ï' => 'Ï',3468 'Ð' => 'Ð',3469 'Ñ' => 'Ñ',3470 'Ò' => 'Ò',3471 'Ó' => 'Ó',3472 'Ô' => 'Ô',3473 'Õ' => 'Õ',3474 'Ö' => 'Ö',3475 '×' => '×',3476 'Ø' => 'Ø',3477 'Ù' => 'Ù',3478 'Ú' => 'Ú',3479 'Û' => 'Û',3480 'Ü' => 'Ü',3481 'Ý' => 'Ý',3482 'Þ' => 'Þ',3483 'ß' => 'ß',3484 'à' => 'à',3485 'á' => 'á',3486 'â' => 'â',3487 'ã' => 'ã',3488 'ä' => 'ä',3489 'å' => 'å',3490 'æ' => 'æ',3491 'ç' => 'ç',3492 'è' => 'è',3493 'é' => 'é',3494 'ê' => 'ê',3495 'ë' => 'ë',3496 'ì' => 'ì',3497 'í' => 'í',3498 'î' => 'î',3499 'ï' => 'ï',3500 'ð' => 'ð',3501 'ñ' => 'ñ',3502 'ò' => 'ò',3503 'ó' => 'ó',3504 'ô' => 'ô',3505 'õ' => 'õ',3506 'ö' => 'ö',3507 '÷' => '÷',3508 'ø' => 'ø',3509 'ù' => 'ù',3510 'ú' => 'ú',3511 'û' => 'û',3512 'ü' => 'ü',3513 'ý' => 'ý',3514 'þ' => 'þ',3515 'ÿ' => 'ÿ',3516 'Œ' => 'Œ',3517 'œ' => 'œ',3518 'Š' => 'Š',3519 'š' => 'š',3520 'Ÿ' => 'Ÿ',3521 'ƒ' => 'ƒ',3522 'ˆ' => 'ˆ',3523 '˜' => '˜',3524 'Α' => 'Α',3525 'Β' => 'Β',3526 'Γ' => 'Γ',3527 'Δ' => 'Δ',3528 'Ε' => 'Ε',3529 'Ζ' => 'Ζ',3530 'Η' => 'Η',3531 'Θ' => 'Θ',3532 'Ι' => 'Ι',3533 'Κ' => 'Κ',3534 'Λ' => 'Λ',3535 'Μ' => 'Μ',3536 'Ν' => 'Ν',3537 'Ξ' => 'Ξ',3538 'Ο' => 'Ο',3539 'Π' => 'Π',3540 'Ρ' => 'Ρ',3541 'Σ' => 'Σ',3542 'Τ' => 'Τ',3543 'Υ' => 'Υ',3544 'Φ' => 'Φ',3545 'Χ' => 'Χ',3546 'Ψ' => 'Ψ',3547 'Ω' => 'Ω',3548 'α' => 'α',3549 'β' => 'β',3550 'γ' => 'γ',3551 'δ' => 'δ',3552 'ε' => 'ε',3553 'ζ' => 'ζ',3554 'η' => 'η',3555 'θ' => 'θ',3556 'ι' => 'ι',3557 'κ' => 'κ',3558 'λ' => 'λ',3559 'μ' => 'μ',3560 'ν' => 'ν',3561 'ξ' => 'ξ',3562 'ο' => 'ο',3563 'π' => 'π',3564 'ρ' => 'ρ',3565 'ς' => 'ς',3566 'σ' => 'σ',3567 'τ' => 'τ',3568 'υ' => 'υ',3569 'φ' => 'φ',3570 'χ' => 'χ',3571 'ψ' => 'ψ',3572 'ω' => 'ω',3773 '"' => '"', 3774 '&' => '&', 3775 '<' => '<', 3776 '>' => '>', 3777 '|' => '|', 3778 ' ' => ' ', 3779 '¡' => '¡', 3780 '¢' => '¢', 3781 '£' => '£', 3782 '¤' => '¤', 3783 '¥' => '¥', 3784 '¦' => '¦', 3785 '&brkbar;' => '¦', 3786 '§' => '§', 3787 '¨' => '¨', 3788 '¨' => '¨', 3789 '©' => '©', 3790 'ª' => 'ª', 3791 '«' => '«', 3792 '¬' => '¬', 3793 '­' => '­', 3794 '®' => '®', 3795 '¯' => '¯', 3796 '&hibar;' => '¯', 3797 '°' => '°', 3798 '±' => '±', 3799 '²' => '²', 3800 '³' => '³', 3801 '´' => '´', 3802 'µ' => 'µ', 3803 '¶' => '¶', 3804 '·' => '·', 3805 '¸' => '¸', 3806 '¹' => '¹', 3807 'º' => 'º', 3808 '»' => '»', 3809 '¼' => '¼', 3810 '½' => '½', 3811 '¾' => '¾', 3812 '¿' => '¿', 3813 'À' => 'À', 3814 'Á' => 'Á', 3815 'Â' => 'Â', 3816 'Ã' => 'Ã', 3817 'Ä' => 'Ä', 3818 'Å' => 'Å', 3819 'Æ' => 'Æ', 3820 'Ç' => 'Ç', 3821 'È' => 'È', 3822 'É' => 'É', 3823 'Ê' => 'Ê', 3824 'Ë' => 'Ë', 3825 'Ì' => 'Ì', 3826 'Í' => 'Í', 3827 'Î' => 'Î', 3828 'Ï' => 'Ï', 3829 'Ð' => 'Ð', 3830 'Ñ' => 'Ñ', 3831 'Ò' => 'Ò', 3832 'Ó' => 'Ó', 3833 'Ô' => 'Ô', 3834 'Õ' => 'Õ', 3835 'Ö' => 'Ö', 3836 '×' => '×', 3837 'Ø' => 'Ø', 3838 'Ù' => 'Ù', 3839 'Ú' => 'Ú', 3840 'Û' => 'Û', 3841 'Ü' => 'Ü', 3842 'Ý' => 'Ý', 3843 'Þ' => 'Þ', 3844 'ß' => 'ß', 3845 'à' => 'à', 3846 'á' => 'á', 3847 'â' => 'â', 3848 'ã' => 'ã', 3849 'ä' => 'ä', 3850 'å' => 'å', 3851 'æ' => 'æ', 3852 'ç' => 'ç', 3853 'è' => 'è', 3854 'é' => 'é', 3855 'ê' => 'ê', 3856 'ë' => 'ë', 3857 'ì' => 'ì', 3858 'í' => 'í', 3859 'î' => 'î', 3860 'ï' => 'ï', 3861 'ð' => 'ð', 3862 'ñ' => 'ñ', 3863 'ò' => 'ò', 3864 'ó' => 'ó', 3865 'ô' => 'ô', 3866 'õ' => 'õ', 3867 'ö' => 'ö', 3868 '÷' => '÷', 3869 'ø' => 'ø', 3870 'ù' => 'ù', 3871 'ú' => 'ú', 3872 'û' => 'û', 3873 'ü' => 'ü', 3874 'ý' => 'ý', 3875 'þ' => 'þ', 3876 'ÿ' => 'ÿ', 3877 'Œ' => 'Œ', 3878 'œ' => 'œ', 3879 'Š' => 'Š', 3880 'š' => 'š', 3881 'Ÿ' => 'Ÿ', 3882 'ƒ' => 'ƒ', 3883 'ˆ' => 'ˆ', 3884 '˜' => '˜', 3885 'Α' => 'Α', 3886 'Β' => 'Β', 3887 'Γ' => 'Γ', 3888 'Δ' => 'Δ', 3889 'Ε' => 'Ε', 3890 'Ζ' => 'Ζ', 3891 'Η' => 'Η', 3892 'Θ' => 'Θ', 3893 'Ι' => 'Ι', 3894 'Κ' => 'Κ', 3895 'Λ' => 'Λ', 3896 'Μ' => 'Μ', 3897 'Ν' => 'Ν', 3898 'Ξ' => 'Ξ', 3899 'Ο' => 'Ο', 3900 'Π' => 'Π', 3901 'Ρ' => 'Ρ', 3902 'Σ' => 'Σ', 3903 'Τ' => 'Τ', 3904 'Υ' => 'Υ', 3905 'Φ' => 'Φ', 3906 'Χ' => 'Χ', 3907 'Ψ' => 'Ψ', 3908 'Ω' => 'Ω', 3909 'α' => 'α', 3910 'β' => 'β', 3911 'γ' => 'γ', 3912 'δ' => 'δ', 3913 'ε' => 'ε', 3914 'ζ' => 'ζ', 3915 'η' => 'η', 3916 'θ' => 'θ', 3917 'ι' => 'ι', 3918 'κ' => 'κ', 3919 'λ' => 'λ', 3920 'μ' => 'μ', 3921 'ν' => 'ν', 3922 'ξ' => 'ξ', 3923 'ο' => 'ο', 3924 'π' => 'π', 3925 'ρ' => 'ρ', 3926 'ς' => 'ς', 3927 'σ' => 'σ', 3928 'τ' => 'τ', 3929 'υ' => 'υ', 3930 'φ' => 'φ', 3931 'χ' => 'χ', 3932 'ψ' => 'ψ', 3933 'ω' => 'ω', 3573 3934 'ϑ' => 'ϑ', 3574 'ϒ' => 'ϒ',3575 'ϖ' => 'ϖ',3576 ' ' => ' ',3577 ' ' => ' ',3578 ' ' => ' ',3579 '‌' => '‌',3580 '‍' => '‍',3581 '‎' => '‎',3582 '‏' => '‏',3583 '–' => '–',3584 '—' => '—',3585 '‘' => '‘',3586 '’' => '’',3587 '‚' => '‚',3588 '“' => '“',3589 '”' => '”',3590 '„' => '„',3591 '†' => '†',3592 '‡' => '‡',3593 '•' => '•',3594 '…' => '…',3595 '‰' => '‰',3596 '′' => '′',3597 '″' => '″',3598 '‹' => '‹',3599 '›' => '›',3600 '‾' => '‾',3601 '⁄' => '⁄',3602 '€' => '€',3603 'ℑ' => 'ℑ',3604 '℘' => '℘',3605 'ℜ' => 'ℜ',3606 '™' => '™',3607 'ℵ' => 'ℵ',3608 '↵' => '↵',3609 '⇐' => '⇐',3610 '⇑' => '⇑',3611 '⇒' => '⇒',3612 '⇓' => '⇓',3613 '⇔' => '⇔',3614 '∀' => '∀',3615 '∂' => '∂',3616 '∃' => '∃',3617 '∅' => '∅',3618 '∇' => '∇',3619 '∈' => '∈',3620 '∉' => '∉',3621 '∋' => '∋',3622 '∏' => '∏',3623 '∑' => '∑',3624 '−' => '−',3625 '∗' => '∗',3626 '√' => '√',3627 '∝' => '∝',3628 '∞' => '∞',3629 '∠' => '∠',3630 '∧' => '∧',3631 '∨' => '∨',3632 '∩' => '∩',3633 '∪' => '∪',3634 '∫' => '∫',3635 '∴' => '∴',3636 '∼' => '∼',3637 '≅' => '≅',3638 '≈' => '≈',3639 '≠' => '≠',3640 '≡' => '≡',3641 '≤' => '≤',3642 '≥' => '≥',3643 '⊂' => '⊂',3644 '⊃' => '⊃',3645 '⊄' => '⊄',3646 '⊆' => '⊆',3647 '⊇' => '⊇',3648 '⊕' => '⊕',3649 '⊗' => '⊗',3650 '⊥' => '⊥',3651 '⋅' => '⋅',3652 '⌈' => '⌈',3653 '⌉' => '⌉',3654 '⌊' => '⌊',3655 '⌋' => '⌋',3656 '⟨' => '〈',3657 '⟩' => '〉',3658 '←' => '←',3659 '↑' => '↑',3660 '→' => '→',3661 '↓' => '↓',3662 '↔' => '↔',3663 '◊' => '◊',3664 '♠' => '♠',3665 '♣' => '♣',3666 '♥' => '♥',3667 '♦' => '♦'3935 'ϒ' => 'ϒ', 3936 'ϖ' => 'ϖ', 3937 ' ' => ' ', 3938 ' ' => ' ', 3939 ' ' => ' ', 3940 '‌' => '‌', 3941 '‍' => '‍', 3942 '‎' => '‎', 3943 '‏' => '‏', 3944 '–' => '–', 3945 '—' => '—', 3946 '‘' => '‘', 3947 '’' => '’', 3948 '‚' => '‚', 3949 '“' => '“', 3950 '”' => '”', 3951 '„' => '„', 3952 '†' => '†', 3953 '‡' => '‡', 3954 '•' => '•', 3955 '…' => '…', 3956 '‰' => '‰', 3957 '′' => '′', 3958 '″' => '″', 3959 '‹' => '‹', 3960 '›' => '›', 3961 '‾' => '‾', 3962 '⁄' => '⁄', 3963 '€' => '€', 3964 'ℑ' => 'ℑ', 3965 '℘' => '℘', 3966 'ℜ' => 'ℜ', 3967 '™' => '™', 3968 'ℵ' => 'ℵ', 3969 '↵' => '↵', 3970 '⇐' => '⇐', 3971 '⇑' => '⇑', 3972 '⇒' => '⇒', 3973 '⇓' => '⇓', 3974 '⇔' => '⇔', 3975 '∀' => '∀', 3976 '∂' => '∂', 3977 '∃' => '∃', 3978 '∅' => '∅', 3979 '∇' => '∇', 3980 '∈' => '∈', 3981 '∉' => '∉', 3982 '∋' => '∋', 3983 '∏' => '∏', 3984 '∑' => '∑', 3985 '−' => '−', 3986 '∗' => '∗', 3987 '√' => '√', 3988 '∝' => '∝', 3989 '∞' => '∞', 3990 '∠' => '∠', 3991 '∧' => '∧', 3992 '∨' => '∨', 3993 '∩' => '∩', 3994 '∪' => '∪', 3995 '∫' => '∫', 3996 '∴' => '∴', 3997 '∼' => '∼', 3998 '≅' => '≅', 3999 '≈' => '≈', 4000 '≠' => '≠', 4001 '≡' => '≡', 4002 '≤' => '≤', 4003 '≥' => '≥', 4004 '⊂' => '⊂', 4005 '⊃' => '⊃', 4006 '⊄' => '⊄', 4007 '⊆' => '⊆', 4008 '⊇' => '⊇', 4009 '⊕' => '⊕', 4010 '⊗' => '⊗', 4011 '⊥' => '⊥', 4012 '⋅' => '⋅', 4013 '⌈' => '⌈', 4014 '⌉' => '⌉', 4015 '⌊' => '⌊', 4016 '⌋' => '⌋', 4017 '⟨' => '〈', 4018 '⟩' => '〉', 4019 '←' => '←', 4020 '↑' => '↑', 4021 '→' => '→', 4022 '↓' => '↓', 4023 '↔' => '↔', 4024 '◊' => '◊', 4025 '♠' => '♠', 4026 '♣' => '♣', 4027 '♥' => '♥', 4028 '♦' => '♦' 3668 4029 ); 3669 4030 3670 return str_replace( array_keys( $to_ncr), array_values($to_ncr), $text );4031 return str_replace( array_keys( $to_ncr ), array_values( $to_ncr ), $text ); 3671 4032 } 3672 4033 3673 4034 /** … … 3683 4044 * 3684 4045 * @see _WP_Editors::editor() 3685 4046 * 3686 * @param string $text 4047 * @param string $text The text to be formatted. 3687 4048 * @param string $default_editor The default editor for the current user. 3688 4049 * It is usually either 'html' or 'tinymce'. 4050 * 3689 4051 * @return string The formatted text after filter is applied. 3690 4052 */ 3691 4053 function format_for_editor( $text, $default_editor = null ) { … … 3698 4060 * 3699 4061 * @since 4.3.0 3700 4062 * 3701 * @param string $text 4063 * @param string $text The formatted text. 3702 4064 * @param string $default_editor The default editor for the current user. 3703 4065 * It is usually either 'html' or 'tinymce'. 3704 4066 */ … … 3715 4077 * @since 2.8.1 3716 4078 * @access private 3717 4079 * 3718 * @param string|array $search 4080 * @param string|array $search The value being searched for, otherwise known as the needle. 3719 4081 * An array may be used to designate multiple needles. 3720 * @param string $subject The string being searched and replaced on, otherwise known as the haystack. 4082 * @param string $subject The string being searched and replaced on, otherwise known as the haystack. 4083 * 3721 4084 * @return string The string with the replaced svalues. 3722 4085 */ 3723 4086 function _deep_replace( $search, $subject ) { … … 3743 4106 * @global wpdb $wpdb WordPress database abstraction object. 3744 4107 * 3745 4108 * @param string|array $data Unescaped data 4109 * 3746 4110 * @return string|array Escaped data 3747 4111 */ 3748 4112 function esc_sql( $data ) { 3749 4113 global $wpdb; 4114 3750 4115 return $wpdb->_escape( $data ); 3751 4116 } 3752 4117 … … 3759 4124 * 3760 4125 * @since 2.8.0 3761 4126 * 3762 * @param string $url The URL to be cleaned. 3763 * @param array $protocols Optional. An array of acceptable protocols. 3764 * Defaults to return value of wp_allowed_protocols() 3765 * @param string $_context Private. Use esc_url_raw() for database usage. 4127 * @param string $url The URL to be cleaned. 4128 * @param array $protocols Optional. An array of acceptable protocols. 4129 * Defaults to return value of wp_allowed_protocols() 4130 * @param string $_context Private. Use esc_url_raw() for database usage. 4131 * 3766 4132 * @return string The cleaned $url after the {@see 'clean_url'} filter is applied. 3767 4133 */ 3768 4134 function esc_url( $url, $protocols = null, $_context = 'display' ) { 3769 4135 $original_url = $url; 3770 4136 3771 if ( '' == $url ) 4137 if ( '' == $url ) { 3772 4138 return $url; 4139 } 3773 4140 3774 4141 $url = str_replace( ' ', '%20', $url ); 3775 $url = preg_replace( '|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\[\]\\x80-\\xff]|i', '', $url);4142 $url = preg_replace( '|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\[\]\\x80-\\xff]|i', '', $url ); 3776 4143 3777 4144 if ( '' === $url ) { 3778 4145 return $url; 3779 4146 } 3780 4147 3781 4148 if ( 0 !== stripos( $url, 'mailto:' ) ) { 3782 $strip = array( '%0d', '%0a', '%0D', '%0A');3783 $url = _deep_replace($strip, $url);4149 $strip = array( '%0d', '%0a', '%0D', '%0A' ); 4150 $url = _deep_replace( $strip, $url ); 3784 4151 } 3785 4152 3786 $url = str_replace( ';//', '://', $url);4153 $url = str_replace( ';//', '://', $url ); 3787 4154 /* If the URL doesn't appear to contain a scheme, we 3788 4155 * presume it needs http:// prepended (unless a relative 3789 4156 * link starting with /, # or ? or a php file). 3790 4157 */ 3791 if ( strpos($url, ':') === false && ! in_array( $url[0], array( '/', '#', '?' ) ) && 3792 ! preg_match('/^[a-z0-9-]+?\.php/i', $url) ) 4158 if ( strpos( $url, ':' ) === false && ! in_array( $url[0], array( '/', '#', '?' ) ) && 4159 ! preg_match( '/^[a-z0-9-]+?\.php/i', $url ) 4160 ) { 3793 4161 $url = 'http://' . $url; 4162 } 3794 4163 3795 4164 // Replace ampersands and single quotes only when displaying. 3796 4165 if ( 'display' == $_context ) { … … 3839 4208 if ( '/' === $url[0] ) { 3840 4209 $good_protocol_url = $url; 3841 4210 } else { 3842 if ( ! is_array( $protocols ) ) 4211 if ( ! is_array( $protocols ) ) { 3843 4212 $protocols = wp_allowed_protocols(); 4213 } 3844 4214 $good_protocol_url = wp_kses_bad_protocol( $url, $protocols ); 3845 if ( strtolower( $good_protocol_url ) != strtolower( $url ) ) 4215 if ( strtolower( $good_protocol_url ) != strtolower( $url ) ) { 3846 4216 return ''; 4217 } 3847 4218 } 3848 4219 3849 4220 /** … … 3852 4223 * @since 2.3.0 3853 4224 * 3854 4225 * @param string $good_protocol_url The cleaned URL to be returned. 3855 * @param string $original_url 3856 * @param string $_context 4226 * @param string $original_url The URL prior to cleaning. 4227 * @param string $_context If 'display', replace ampersands and single quotes only. 3857 4228 */ 3858 4229 return apply_filters( 'clean_url', $good_protocol_url, $original_url, $_context ); 3859 4230 } … … 3863 4234 * 3864 4235 * @since 2.8.0 3865 4236 * 3866 * @param string $url The URL to be cleaned. 3867 * @param array $protocols An array of acceptable protocols. 4237 * @param string $url The URL to be cleaned. 4238 * @param array $protocols An array of acceptable protocols. 4239 * 3868 4240 * @return string The cleaned URL. 3869 4241 */ 3870 4242 function esc_url_raw( $url, $protocols = null ) { … … 3879 4251 * @since 1.2.2 3880 4252 * 3881 4253 * @param string $myHTML The text to be converted. 4254 * 3882 4255 * @return string Converted text. 3883 4256 */ 3884 4257 function htmlentities2( $myHTML ) { 3885 $translation_table = get_html_translation_table( HTML_ENTITIES, ENT_QUOTES ); 3886 $translation_table[chr(38)] = '&'; 3887 return preg_replace( "/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/", "&", strtr($myHTML, $translation_table) ); 4258 $translation_table = get_html_translation_table( HTML_ENTITIES, ENT_QUOTES ); 4259 $translation_table[ chr( 38 ) ] = '&'; 4260 4261 return preg_replace( "/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/", "&", strtr( $myHTML, $translation_table ) ); 3888 4262 } 3889 4263 3890 4264 /** … … 3897 4271 * @since 2.8.0 3898 4272 * 3899 4273 * @param string $text The text to be escaped. 4274 * 3900 4275 * @return string Escaped text. 3901 4276 */ 3902 4277 function esc_js( $text ) { … … 3905 4280 $safe_text = preg_replace( '/&#(x)?0*(?(1)27|39);?/i', "'", stripslashes( $safe_text ) ); 3906 4281 $safe_text = str_replace( "\r", '', $safe_text ); 3907 4282 $safe_text = str_replace( "\n", '\\n', addslashes( $safe_text ) ); 4283 3908 4284 /** 3909 4285 * Filters a string cleaned and escaped for output in JavaScript. 3910 4286 * … … 3914 4290 * @since 2.0.6 3915 4291 * 3916 4292 * @param string $safe_text The text after it has been escaped. 3917 * @param string $textThe text prior to being escaped.4293 * @param string $text The text prior to being escaped. 3918 4294 */ 3919 4295 return apply_filters( 'js_escape', $safe_text, $text ); 3920 4296 } … … 3925 4301 * @since 2.8.0 3926 4302 * 3927 4303 * @param string $text 4304 * 3928 4305 * @return string 3929 4306 */ 3930 4307 function esc_html( $text ) { 3931 4308 $safe_text = wp_check_invalid_utf8( $text ); 3932 4309 $safe_text = _wp_specialchars( $safe_text, ENT_QUOTES ); 4310 3933 4311 /** 3934 4312 * Filters a string cleaned and escaped for output in HTML. 3935 4313 * … … 3939 4317 * @since 2.8.0 3940 4318 * 3941 4319 * @param string $safe_text The text after it has been escaped. 3942 * @param string $textThe text prior to being escaped.4320 * @param string $text The text prior to being escaped. 3943 4321 */ 3944 4322 return apply_filters( 'esc_html', $safe_text, $text ); 3945 4323 } … … 3950 4328 * @since 2.8.0 3951 4329 * 3952 4330 * @param string $text 4331 * 3953 4332 * @return string 3954 4333 */ 3955 4334 function esc_attr( $text ) { 3956 4335 $safe_text = wp_check_invalid_utf8( $text ); 3957 4336 $safe_text = _wp_specialchars( $safe_text, ENT_QUOTES ); 4337 3958 4338 /** 3959 4339 * Filters a string cleaned and escaped for output in an HTML attribute. 3960 4340 * … … 3964 4344 * @since 2.0.6 3965 4345 * 3966 4346 * @param string $safe_text The text after it has been escaped. 3967 * @param string $textThe text prior to being escaped.4347 * @param string $text The text prior to being escaped. 3968 4348 */ 3969 4349 return apply_filters( 'attribute_escape', $safe_text, $text ); 3970 4350 } … … 3975 4355 * @since 3.1.0 3976 4356 * 3977 4357 * @param string $text 4358 * 3978 4359 * @return string 3979 4360 */ 3980 4361 function esc_textarea( $text ) { 3981 4362 $safe_text = htmlspecialchars( $text, ENT_QUOTES, get_option( 'blog_charset' ) ); 4363 3982 4364 /** 3983 4365 * Filters a string cleaned and escaped for output in a textarea element. 3984 4366 * 3985 4367 * @since 3.1.0 3986 4368 * 3987 4369 * @param string $safe_text The text after it has been escaped. 3988 * @param string $textThe text prior to being escaped.4370 * @param string $text The text prior to being escaped. 3989 4371 */ 3990 4372 return apply_filters( 'esc_textarea', $safe_text, $text ); 3991 4373 } … … 3996 4378 * @since 2.5.0 3997 4379 * 3998 4380 * @param string $tag_name 4381 * 3999 4382 * @return string 4000 4383 */ 4001 4384 function tag_escape( $tag_name ) { 4002 $safe_tag = strtolower( preg_replace('/[^a-zA-Z0-9_:]/', '', $tag_name) ); 4385 $safe_tag = strtolower( preg_replace( '/[^a-zA-Z0-9_:]/', '', $tag_name ) ); 4386 4003 4387 /** 4004 4388 * Filters a string cleaned and escaped for output as an HTML tag. 4005 4389 * 4006 4390 * @since 2.8.0 4007 4391 * 4008 4392 * @param string $safe_tag The tag name after it has been escaped. 4009 4393 * @param string $tag_name The text before it was escaped. 4010 4394 */ 4011 4395 return apply_filters( 'tag_escape', $safe_tag, $tag_name ); 4012 4396 } … … 4021 4405 * @since 4.1.0 Support was added for relative URLs. 4022 4406 * 4023 4407 * @param string $link Full URL path. 4408 * 4024 4409 * @return string Absolute path. 4025 4410 */ 4026 4411 function wp_make_link_relative( $link ) { … … 4038 4423 * @global wpdb $wpdb WordPress database abstraction object. 4039 4424 * 4040 4425 * @param string $option The name of the option. 4041 * @param string $value The unsanitised value. 4426 * @param string $value The unsanitised value. 4427 * 4042 4428 * @return string Sanitized value. 4043 4429 */ 4044 4430 function sanitize_option( $option, $value ) { 4045 4431 global $wpdb; 4046 4432 4047 4433 $original_value = $value; 4048 $error = '';4434 $error = ''; 4049 4435 4050 4436 switch ( $option ) { 4051 4437 case 'admin_email' : … … 4089 4475 case 'posts_per_page': 4090 4476 case 'posts_per_rss': 4091 4477 $value = (int) $value; 4092 if ( empty( $value) )4478 if ( empty( $value ) ) { 4093 4479 $value = 1; 4094 if ( $value < -1 ) 4095 $value = abs($value); 4480 } 4481 if ( $value < - 1 ) { 4482 $value = abs( $value ); 4483 } 4096 4484 break; 4097 4485 4098 4486 case 'default_ping_status': 4099 4487 case 'default_comment_status': 4100 4488 // Options that if not there have 0 value but need to be something like "closed" 4101 if ( $value == '0' || $value == '' )4489 if ( $value == '0' || $value == '' ) { 4102 4490 $value = 'closed'; 4491 } 4103 4492 break; 4104 4493 4105 4494 case 'blogdescription': … … 4117 4506 break; 4118 4507 4119 4508 case 'blog_charset': 4120 $value = preg_replace( '/[^a-zA-Z0-9_-]/', '', $value); // strips slashes4509 $value = preg_replace( '/[^a-zA-Z0-9_-]/', '', $value ); // strips slashes 4121 4510 break; 4122 4511 4123 4512 case 'blog_public': 4124 4513 // This is the value if the settings checkbox is not checked on POST. Don't rely on this. 4125 if ( null === $value ) 4514 if ( null === $value ) { 4126 4515 $value = 1; 4127 else4516 } else { 4128 4517 $value = intval( $value ); 4518 } 4129 4519 break; 4130 4520 4131 4521 case 'date_format': … … 4151 4541 break; 4152 4542 4153 4543 case 'gmt_offset': 4154 $value = preg_replace( '/[^0-9:.-]/', '', $value); // strips slashes4544 $value = preg_replace( '/[^0-9:.-]/', '', $value ); // strips slashes 4155 4545 break; 4156 4546 4157 4547 case 'siteurl': … … 4195 4585 if ( is_wp_error( $value ) ) { 4196 4586 $error = $value->get_error_message(); 4197 4587 } else { 4198 if ( ! is_array( $value ) ) 4588 if ( ! is_array( $value ) ) { 4199 4589 $value = explode( ' ', $value ); 4590 } 4200 4591 4201 4592 $value = array_values( array_filter( array_map( 'trim', $value ) ) ); 4202 4593 4203 if ( ! $value ) 4594 if ( ! $value ) { 4204 4595 $value = ''; 4596 } 4205 4597 } 4206 4598 break; 4207 4599 … … 4211 4603 if ( is_wp_error( $value ) ) { 4212 4604 $error = $value->get_error_message(); 4213 4605 } else { 4214 if ( ! is_array( $value ) ) 4606 if ( ! is_array( $value ) ) { 4215 4607 $value = explode( "\n", $value ); 4608 } 4216 4609 4217 4610 $domains = array_values( array_filter( array_map( 'trim', $value ) ) ); 4218 $value = array();4611 $value = array(); 4219 4612 4220 4613 foreach ( $domains as $domain ) { 4221 4614 if ( ! preg_match( '/(--|\.\.)/', $domain ) && preg_match( '|^([a-zA-Z0-9-\.])+$|', $domain ) ) { 4222 4615 $value[] = $domain; 4223 4616 } 4224 4617 } 4225 if ( ! $value ) 4618 if ( ! $value ) { 4226 4619 $value = ''; 4620 } 4227 4621 } 4228 4622 break; 4229 4623 … … 4247 4641 4248 4642 if ( 'permalink_structure' === $option && '' !== $value && ! preg_match( '/%[^\/%]+%/', $value ) ) { 4249 4643 $error = sprintf( 4250 4644 /* translators: %s: Codex URL */ 4251 4645 __( 'A structure tag is required when using custom permalinks. <a href="%s">Learn more</a>' ), 4252 4646 __( 'https://codex.wordpress.org/Using_Permalinks#Choosing_your_permalink_structure' ) 4253 4647 ); … … 4255 4649 break; 4256 4650 4257 4651 case 'default_role' : 4258 if ( ! get_role( $value ) && get_role( 'subscriber' ) ) 4652 if ( ! get_role( $value ) && get_role( 'subscriber' ) ) { 4259 4653 $value = 'subscriber'; 4654 } 4260 4655 break; 4261 4656 4262 4657 case 'moderation_keys': … … 4286 4681 * @since 2.3.0 4287 4682 * @since 4.3.0 Added the `$original_value` parameter. 4288 4683 * 4289 * @param string $value 4290 * @param string $option 4684 * @param string $value The sanitized option value. 4685 * @param string $option The option name. 4291 4686 * @param string $original_value The original value passed to the function. 4292 4687 */ 4293 4688 return apply_filters( "sanitize_option_{$option}", $value, $option, $original_value ); … … 4300 4695 * 4301 4696 * @since 4.4.0 4302 4697 * 4303 * @param mixed $valueThe array, object, or scalar.4698 * @param mixed $value The array, object, or scalar. 4304 4699 * @param callable $callback The function to map onto $value. 4700 * 4305 4701 * @return mixed The value with the callback applied to all non-arrays and non-objects inside it. 4306 4702 */ 4307 4703 function map_deep( $value, $callback ) { … … 4330 4726 * @since 2.2.1 4331 4727 * 4332 4728 * @param string $string The string to be parsed. 4333 * @param array $arrayVariables will be stored in this array.4729 * @param array $array Variables will be stored in this array. 4334 4730 */ 4335 4731 function wp_parse_str( $string, &$array ) { 4336 4732 parse_str( $string, $array ); 4337 if ( get_magic_quotes_gpc() ) 4733 if ( get_magic_quotes_gpc() ) { 4338 4734 $array = stripslashes_deep( $array ); 4735 } 4339 4736 /** 4340 4737 * Filters the array of variables derived from a parsed string. 4341 4738 * … … 4354 4751 * @since 2.3.0 4355 4752 * 4356 4753 * @param string $text Text to be converted. 4754 * 4357 4755 * @return string Converted text. 4358 4756 */ 4359 4757 function wp_pre_kses_less_than( $text ) { 4360 return preg_replace_callback( '%<[^>]*?((?=<)|>|$)%', 'wp_pre_kses_less_than_callback', $text);4758 return preg_replace_callback( '%<[^>]*?((?=<)|>|$)%', 'wp_pre_kses_less_than_callback', $text ); 4361 4759 } 4362 4760 4363 4761 /** … … 4366 4764 * @since 2.3.0 4367 4765 * 4368 4766 * @param array $matches Populated by matches to preg_replace. 4767 * 4369 4768 * @return string The text returned after esc_html if needed. 4370 4769 */ 4371 4770 function wp_pre_kses_less_than_callback( $matches ) { 4372 if ( false === strpos($matches[0], '>') ) 4373 return esc_html($matches[0]); 4771 if ( false === strpos( $matches[0], '>' ) ) { 4772 return esc_html( $matches[0] ); 4773 } 4774 4374 4775 return $matches[0]; 4375 4776 } 4376 4777 … … 4380 4781 * @since 2.5.0 4381 4782 * @link https://secure.php.net/sprintf 4382 4783 * 4383 * @param string $pattern The string which formatted args are inserted. 4384 * @param mixed $args ,... Arguments to be formatted into the $pattern string. 4784 * @param string $pattern The string which formatted args are inserted. 4785 * @param mixed $args ,... Arguments to be formatted into the $pattern string. 4786 * 4385 4787 * @return string The formatted string. 4386 4788 */ 4387 4789 function wp_sprintf( $pattern ) { 4388 $args = func_get_args();4389 $len = strlen($pattern);4390 $start = 0;4391 $result = '';4790 $args = func_get_args(); 4791 $len = strlen( $pattern ); 4792 $start = 0; 4793 $result = ''; 4392 4794 $arg_index = 0; 4393 4795 while ( $len > $start ) { 4394 4796 // Last character: append and break 4395 if ( strlen( $pattern) - 1 == $start ) {4396 $result .= substr( $pattern, -1);4797 if ( strlen( $pattern ) - 1 == $start ) { 4798 $result .= substr( $pattern, - 1 ); 4397 4799 break; 4398 4800 } 4399 4801 4400 4802 // Literal %: append and continue 4401 if ( substr( $pattern, $start, 2) == '%%' ) {4402 $start += 2;4803 if ( substr( $pattern, $start, 2 ) == '%%' ) { 4804 $start += 2; 4403 4805 $result .= '%'; 4404 4806 continue; 4405 4807 } 4406 4808 4407 4809 // Get fragment before next % 4408 $end = strpos( $pattern, '%', $start + 1);4409 if ( false === $end ) 4810 $end = strpos( $pattern, '%', $start + 1 ); 4811 if ( false === $end ) { 4410 4812 $end = $len; 4411 $fragment = substr($pattern, $start, $end - $start); 4813 } 4814 $fragment = substr( $pattern, $start, $end - $start ); 4412 4815 4413 4816 // Fragment has a specifier 4414 if ( $pattern[ $start] == '%' ) {4817 if ( $pattern[ $start ] == '%' ) { 4415 4818 // Find numbered arguments or take the next one in order 4416 if ( preg_match( '/^%(\d+)\$/', $fragment, $matches) ) {4417 $arg = isset($args[$matches[1]]) ? $args[$matches[1]] : '';4418 $fragment = str_replace( "%{$matches[1]}$", '%', $fragment);4819 if ( preg_match( '/^%(\d+)\$/', $fragment, $matches ) ) { 4820 $arg = isset( $args[ $matches[1] ] ) ? $args[ $matches[1] ] : ''; 4821 $fragment = str_replace( "%{$matches[1]}$", '%', $fragment ); 4419 4822 } else { 4420 ++ $arg_index;4421 $arg = isset( $args[$arg_index]) ? $args[$arg_index] : '';4823 ++ $arg_index; 4824 $arg = isset( $args[ $arg_index ] ) ? $args[ $arg_index ] : ''; 4422 4825 } 4423 4826 4424 4827 /** … … 4429 4832 * @since 2.5.0 4430 4833 * 4431 4834 * @param string $fragment A fragment from the pattern. 4432 * @param string $arg 4835 * @param string $arg The argument. 4433 4836 */ 4434 4837 $_fragment = apply_filters( 'wp_sprintf', $fragment, $arg ); 4435 if ( $_fragment != $fragment ) 4838 if ( $_fragment != $fragment ) { 4436 4839 $fragment = $_fragment; 4437 else 4438 $fragment = sprintf($fragment, strval($arg) ); 4840 } else { 4841 $fragment = sprintf( $fragment, strval( $arg ) ); 4842 } 4439 4843 } 4440 4844 4441 4845 // Append to result and move to next fragment 4442 4846 $result .= $fragment; 4443 $start = $end;4847 $start = $end; 4444 4848 } 4849 4445 4850 return $result; 4446 4851 } 4447 4852 … … 4455 4860 * @since 2.5.0 4456 4861 * 4457 4862 * @param string $pattern Content containing '%l' at the beginning. 4458 * @param array $args List items to prepend to the content and replace '%l'. 4863 * @param array $args List items to prepend to the content and replace '%l'. 4864 * 4459 4865 * @return string Localized list items and rest of the content. 4460 4866 */ 4461 4867 function wp_sprintf_l( $pattern, $args ) { 4462 4868 // Not a match 4463 if ( substr( $pattern, 0, 2) != '%l' )4869 if ( substr( $pattern, 0, 2 ) != '%l' ) { 4464 4870 return $pattern; 4871 } 4465 4872 4466 4873 // Nothing to work with 4467 if ( empty( $args) )4874 if ( empty( $args ) ) { 4468 4875 return ''; 4876 } 4469 4877 4470 4878 /** 4471 4879 * Filters the translated delimiters used by wp_sprintf_l(). … … 4480 4888 */ 4481 4889 $l = apply_filters( 'wp_sprintf_l', array( 4482 4890 /* translators: used to join items in a list with more than 2 items */ 4483 'between' => sprintf( __( '%s, %s'), '', '' ),4891 'between' => sprintf( __( '%s, %s' ), '', '' ), 4484 4892 /* translators: used to join last two items in a list with more than 2 times */ 4485 'between_last_two' => sprintf( __( '%s, and %s'), '', '' ),4893 'between_last_two' => sprintf( __( '%s, and %s' ), '', '' ), 4486 4894 /* translators: used to join items in a list with only 2 items */ 4487 'between_only_two' => sprintf( __( '%s and %s'), '', '' ),4895 'between_only_two' => sprintf( __( '%s and %s' ), '', '' ), 4488 4896 ) ); 4489 4897 4490 $args = (array) $args; 4491 $result = array_shift($args); 4492 if ( count($args) == 1 ) 4493 $result .= $l['between_only_two'] . array_shift($args); 4898 $args = (array) $args; 4899 $result = array_shift( $args ); 4900 if ( count( $args ) == 1 ) { 4901 $result .= $l['between_only_two'] . array_shift( $args ); 4902 } 4494 4903 // Loop when more than two args 4495 $i = count( $args);4904 $i = count( $args ); 4496 4905 while ( $i ) { 4497 $arg = array_shift( $args);4498 $i --;4499 if ( 0 == $i ) 4906 $arg = array_shift( $args ); 4907 $i --; 4908 if ( 0 == $i ) { 4500 4909 $result .= $l['between_last_two'] . $arg; 4501 else4910 } else { 4502 4911 $result .= $l['between'] . $arg; 4912 } 4503 4913 } 4504 return $result . substr($pattern, 2); 4914 4915 return $result . substr( $pattern, 2 ); 4505 4916 } 4506 4917 4507 4918 /** … … 4513 4924 * 4514 4925 * @since 2.5.0 4515 4926 * 4516 * @param string $str String to get the excerpt from. 4517 * @param int $count Maximum number of characters to take. 4518 * @param string $more Optional. What to append if $str needs to be trimmed. Defaults to empty string. 4927 * @param string $str String to get the excerpt from. 4928 * @param int $count Maximum number of characters to take. 4929 * @param string $more Optional. What to append if $str needs to be trimmed. Defaults to empty string. 4930 * 4519 4931 * @return string The excerpt. 4520 4932 */ 4521 4933 function wp_html_excerpt( $str, $count, $more = null ) { 4522 if ( null === $more ) 4934 if ( null === $more ) { 4523 4935 $more = ''; 4524 $str = wp_strip_all_tags( $str, true ); 4936 } 4937 $str = wp_strip_all_tags( $str, true ); 4525 4938 $excerpt = mb_substr( $str, 0, $count ); 4526 4939 // remove part of an entity at the end 4527 4940 $excerpt = preg_replace( '/&[^;\s]{0,6}$/', '', $excerpt ); 4528 if ( $str != $excerpt ) 4941 if ( $str != $excerpt ) { 4529 4942 $excerpt = trim( $excerpt ) . $more; 4943 } 4944 4530 4945 return $excerpt; 4531 4946 } 4532 4947 … … 4541 4956 * @global string $_links_add_base 4542 4957 * 4543 4958 * @param string $content String to search for links in. 4544 * @param string $base The base URL to prefix to links. 4545 * @param array $attrs The attributes which should be processed. 4959 * @param string $base The base URL to prefix to links. 4960 * @param array $attrs The attributes which should be processed. 4961 * 4546 4962 * @return string The processed content. 4547 4963 */ 4548 function links_add_base_url( $content, $base, $attrs = array( 'src', 'href') ) {4964 function links_add_base_url( $content, $base, $attrs = array( 'src', 'href' ) ) { 4549 4965 global $_links_add_base; 4550 4966 $_links_add_base = $base; 4551 $attrs = implode('|', (array)$attrs); 4967 $attrs = implode( '|', (array) $attrs ); 4968 4552 4969 return preg_replace_callback( "!($attrs)=(['\"])(.+?)\\2!i", '_links_add_base', $content ); 4553 4970 } 4554 4971 … … 4561 4978 * @global string $_links_add_base 4562 4979 * 4563 4980 * @param string $m The matched link. 4981 * 4564 4982 * @return string The processed link. 4565 4983 */ 4566 4984 function _links_add_base( $m ) { 4567 4985 global $_links_add_base; 4986 4568 4987 //1 = attribute name 2 = quotation mark 3 = URL 4569 4988 return $m[1] . '=' . $m[2] . 4570 4571 4572 4573 4574 4989 ( preg_match( '#^(\w{1,20}):#', $m[3], $protocol ) && in_array( $protocol[1], wp_allowed_protocols() ) ? 4990 $m[3] : 4991 WP_Http::make_absolute_url( $m[3], $_links_add_base ) 4992 ) 4993 . $m[2]; 4575 4994 } 4576 4995 4577 4996 /** … … 4587 5006 * @global string $_links_add_target 4588 5007 * 4589 5008 * @param string $content String to search for links in. 4590 * @param string $target The Target to add to the links. 4591 * @param array $tags An array of tags to apply to. 5009 * @param string $target The Target to add to the links. 5010 * @param array $tags An array of tags to apply to. 5011 * 4592 5012 * @return string The processed content. 4593 5013 */ 4594 function links_add_target( $content, $target = '_blank', $tags = array( 'a') ) {5014 function links_add_target( $content, $target = '_blank', $tags = array( 'a' ) ) { 4595 5015 global $_links_add_target; 4596 5016 $_links_add_target = $target; 4597 $tags = implode('|', (array)$tags); 5017 $tags = implode( '|', (array) $tags ); 5018 4598 5019 return preg_replace_callback( "!<($tags)([^>]*)>!i", '_links_add_target', $content ); 4599 5020 } 4600 5021 … … 4607 5028 * @global string $_links_add_target 4608 5029 * 4609 5030 * @param string $m The matched link. 5031 * 4610 5032 * @return string The processed link. 4611 5033 */ 4612 5034 function _links_add_target( $m ) { 4613 5035 global $_links_add_target; 4614 $tag = $m[1]; 4615 $link = preg_replace('|( target=([\'"])(.*?)\2)|i', '', $m[2]); 5036 $tag = $m[1]; 5037 $link = preg_replace( '|( target=([\'"])(.*?)\2)|i', '', $m[2] ); 5038 4616 5039 return '<' . $tag . $link . ' target="' . esc_attr( $_links_add_target ) . '">'; 4617 5040 } 4618 5041 … … 4622 5045 * @since 2.7.0 4623 5046 * 4624 5047 * @param string $str The string to normalize. 5048 * 4625 5049 * @return string The normalized string. 4626 5050 */ 4627 5051 function normalize_whitespace( $str ) { 4628 $str = trim( $str ); 4629 $str = str_replace( "\r", "\n", $str ); 4630 $str = preg_replace( array( '/\n+/', '/[ \t]+/' ), array( "\n", ' ' ), $str ); 5052 $str = trim( $str ); 5053 $str = str_replace( "\r", "\n", $str ); 5054 $str = preg_replace( array( '/\n+/', '/[ \t]+/' ), array( "\n", ' ' ), $str ); 5055 4631 5056 return $str; 4632 5057 } 4633 5058 … … 4640 5065 * 4641 5066 * @since 2.9.0 4642 5067 * 4643 * @param string $string String containing HTML tags 4644 * @param bool $remove_breaks Optional. Whether to remove left over line breaks and white space chars 5068 * @param string $string String containing HTML tags 5069 * @param bool $remove_breaks Optional. Whether to remove left over line breaks and white space chars 5070 * 4645 5071 * @return string The processed string. 4646 5072 */ 4647 function wp_strip_all_tags( $string, $remove_breaks = false) {5073 function wp_strip_all_tags( $string, $remove_breaks = false ) { 4648 5074 $string = preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $string ); 4649 $string = strip_tags( $string);5075 $string = strip_tags( $string ); 4650 5076 4651 if ( $remove_breaks ) 4652 $string = preg_replace('/[\r\n\t ]+/', ' ', $string); 5077 if ( $remove_breaks ) { 5078 $string = preg_replace( '/[\r\n\t ]+/', ' ', $string ); 5079 } 4653 5080 4654 5081 return trim( $string ); 4655 5082 } … … 4670 5097 * @see wp_strip_all_tags() 4671 5098 * 4672 5099 * @param string $str String to sanitize. 5100 * 4673 5101 * @return string Sanitized string. 4674 5102 */ 4675 5103 function sanitize_text_field( $str ) { … … 4681 5109 * @since 2.9.0 4682 5110 * 4683 5111 * @param string $filtered The sanitized string. 4684 * @param string $str 5112 * @param string $str The string prior to being sanitized. 4685 5113 */ 4686 5114 return apply_filters( 'sanitize_text_field', $filtered, $str ); 4687 5115 } … … 4698 5126 * @since 4.7.0 4699 5127 * 4700 5128 * @param string $str String to sanitize. 5129 * 4701 5130 * @return string Sanitized string. 4702 5131 */ 4703 5132 function sanitize_textarea_field( $str ) { … … 4709 5138 * @since 4.7.0 4710 5139 * 4711 5140 * @param string $filtered The sanitized string. 4712 * @param string $str 5141 * @param string $str The string prior to being sanitized. 4713 5142 */ 4714 5143 return apply_filters( 'sanitize_textarea_field', $filtered, $str ); 4715 5144 } … … 4722 5151 * 4723 5152 * @param string $str String to sanitize. 4724 5153 * @param bool $keep_newlines optional Whether to keep newlines. Default: false. 5154 * 4725 5155 * @return string Sanitized string. 4726 5156 */ 4727 5157 function _sanitize_text_fields( $str, $keep_newlines = false ) { 4728 5158 $filtered = wp_check_invalid_utf8( $str ); 4729 5159 4730 if ( strpos( $filtered, '<') !== false ) {5160 if ( strpos( $filtered, '<' ) !== false ) { 4731 5161 $filtered = wp_pre_kses_less_than( $filtered ); 4732 5162 // This will strip extra whitespace for us. 4733 5163 $filtered = wp_strip_all_tags( $filtered, false ); 4734 5164 4735 5165 // Use html entities in a special case to make sure no later 4736 5166 // newline stripping stage could lead to a functional tag 4737 $filtered = str_replace( "<\n", "<\n", $filtered);5167 $filtered = str_replace( "<\n", "<\n", $filtered ); 4738 5168 } 4739 5169 4740 5170 if ( ! $keep_newlines ) { … … 4743 5173 $filtered = trim( $filtered ); 4744 5174 4745 5175 $found = false; 4746 while ( preg_match( '/%[a-f0-9]{2}/i', $filtered, $match) ) {4747 $filtered = str_replace( $match[0], '', $filtered);4748 $found = true;5176 while ( preg_match( '/%[a-f0-9]{2}/i', $filtered, $match ) ) { 5177 $filtered = str_replace( $match[0], '', $filtered ); 5178 $found = true; 4749 5179 } 4750 5180 4751 5181 if ( $found ) { 4752 5182 // Strip out the whitespace that may now exist after removing the octets. 4753 $filtered = trim( preg_replace( '/ +/', ' ', $filtered) );5183 $filtered = trim( preg_replace( '/ +/', ' ', $filtered ) ); 4754 5184 } 4755 5185 4756 5186 return $filtered; … … 4761 5191 * 4762 5192 * @since 3.1.0 4763 5193 * 4764 * @param string $path 5194 * @param string $path A path. 4765 5195 * @param string $suffix If the filename ends in suffix this will also be cut off. 5196 * 4766 5197 * @return string 4767 5198 */ 4768 5199 function wp_basename( $path, $suffix = '' ) { … … 4779 5210 * @staticvar string|false $dblq 4780 5211 * 4781 5212 * @param string $text The text to be modified. 5213 * 4782 5214 * @return string The modified text. 4783 5215 */ 4784 5216 function capital_P_dangit( $text ) { 4785 5217 // Simple replacement for titles 4786 5218 $current_filter = current_filter(); 4787 if ( 'the_title' === $current_filter || 'wp_title' === $current_filter ) 5219 if ( 'the_title' === $current_filter || 'wp_title' === $current_filter ) { 4788 5220 return str_replace( 'Wordpress', 'WordPress', $text ); 5221 } 4789 5222 // Still here? Use the more judicious replacement 4790 5223 static $dblq = false; 4791 5224 if ( false === $dblq ) { 4792 5225 $dblq = _x( '“', 'opening curly double quote' ); 4793 5226 } 5227 4794 5228 return str_replace( 4795 5229 array( ' Wordpress', '‘Wordpress', $dblq . 'Wordpress', '>Wordpress', '(Wordpress' ), 4796 5230 array( ' WordPress', '‘WordPress', $dblq . 'WordPress', '>WordPress', '(WordPress' ), 4797 $text );5231 $text ); 4798 5232 } 4799 5233 4800 5234 /** … … 4803 5237 * @since 3.1.3 4804 5238 * 4805 5239 * @param string $mime_type Mime type 5240 * 4806 5241 * @return string Sanitized mime type 4807 5242 */ 4808 5243 function sanitize_mime_type( $mime_type ) { 4809 5244 $sani_mime_type = preg_replace( '/[^-+*.a-zA-Z0-9\/]/', '', $mime_type ); 5245 4810 5246 /** 4811 5247 * Filters a mime type following sanitization. 4812 5248 * 4813 5249 * @since 3.1.3 4814 5250 * 4815 5251 * @param string $sani_mime_type The sanitized mime type. 4816 * @param string $mime_type 5252 * @param string $mime_type The mime type prior to sanitization. 4817 5253 */ 4818 5254 return apply_filters( 'sanitize_mime_type', $sani_mime_type, $mime_type ); 4819 5255 } … … 4824 5260 * @since 3.4.0 4825 5261 * 4826 5262 * @param string $to_ping Space or carriage return separated URLs 5263 * 4827 5264 * @return string URLs starting with the http or https protocol, separated by a carriage return. 4828 5265 */ 4829 5266 function sanitize_trackback_urls( $to_ping ) { 4830 $urls_to_ping = preg_split( '/[\r\n\t ]/', trim( $to_ping ), - 1, PREG_SPLIT_NO_EMPTY );5267 $urls_to_ping = preg_split( '/[\r\n\t ]/', trim( $to_ping ), - 1, PREG_SPLIT_NO_EMPTY ); 4831 5268 foreach ( $urls_to_ping as $k => $url ) { 4832 if ( !preg_match( '#^https?://.#i', $url ) ) 4833 unset( $urls_to_ping[$k] ); 5269 if ( ! preg_match( '#^https?://.#i', $url ) ) { 5270 unset( $urls_to_ping[ $k ] ); 5271 } 4834 5272 } 4835 5273 $urls_to_ping = array_map( 'esc_url_raw', $urls_to_ping ); 4836 5274 $urls_to_ping = implode( "\n", $urls_to_ping ); 5275 4837 5276 /** 4838 5277 * Filters a list of trackback URLs following sanitization. 4839 5278 * … … 4843 5282 * @since 3.4.0 4844 5283 * 4845 5284 * @param string $urls_to_ping Sanitized space or carriage return separated URLs. 4846 * @param string $to_ping 5285 * @param string $to_ping Space or carriage return separated URLs before sanitization. 4847 5286 */ 4848 5287 return apply_filters( 'sanitize_trackback_urls', $urls_to_ping, $to_ping ); 4849 5288 } … … 4857 5296 * @since 3.6.0 4858 5297 * 4859 5298 * @param string|array $value String or array of strings to slash. 5299 * 4860 5300 * @return string|array Slashed $value 4861 5301 */ 4862 5302 function wp_slash( $value ) { 4863 5303 if ( is_array( $value ) ) { 4864 5304 foreach ( $value as $k => $v ) { 4865 5305 if ( is_array( $v ) ) { 4866 $value[ $k] = wp_slash( $v );5306 $value[ $k ] = wp_slash( $v ); 4867 5307 } else { 4868 $value[ $k] = addslashes( $v );5308 $value[ $k ] = addslashes( $v ); 4869 5309 } 4870 5310 } 4871 5311 } else { … … 4884 5324 * @since 3.6.0 4885 5325 * 4886 5326 * @param string|array $value String or array of strings to unslash. 5327 * 4887 5328 * @return string|array Unslashed $value 4888 5329 */ 4889 5330 function wp_unslash( $value ) { … … 4896 5337 * @since 3.6.0 4897 5338 * 4898 5339 * @param string $content A string which might contain a URL. 5340 * 4899 5341 * @return string|false The found URL. 4900 5342 */ 4901 5343 function get_url_in_content( $content ) { … … 4960 5402 } 4961 5403 4962 5404 $printed = true; 4963 ?>4964 <style type="text/css">4965 img.wp-smiley,4966 img.emoji {4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 }4977 </style>4978 <?php5405 ?> 5406 <style type="text/css"> 5407 img.wp-smiley, 5408 img.emoji { 5409 display: inline !important; 5410 border: none !important; 5411 box-shadow: none !important; 5412 height: 1em !important; 5413 width: 1em !important; 5414 margin: 0 .07em !important; 5415 vertical-align: -0.1em !important; 5416 background: none !important; 5417 padding: 0 !important; 5418 } 5419 </style> 5420 <?php 4979 5421 } 4980 5422 4981 5423 /** … … 5021 5463 * 5022 5464 * @param string The emoji extension for png files. Default .png. 5023 5465 */ 5024 'ext' => apply_filters( 'emoji_ext', '.png' ),5466 'ext' => apply_filters( 'emoji_ext', '.png' ), 5025 5467 5026 5468 /** 5027 5469 * Filters the URL where emoji SVG images are hosted. … … 5030 5472 * 5031 5473 * @param string The emoji base URL for svg images. 5032 5474 */ 5033 'svgUrl' => apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/2.2.1/svg/' ),5475 'svgUrl' => apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/2.2.1/svg/' ), 5034 5476 5035 5477 /** 5036 5478 * Filters the extension of the emoji SVG files. … … 5039 5481 * 5040 5482 * @param string The emoji extension for svg files. Default .svg. 5041 5483 */ 5042 'svgExt' => apply_filters( 'emoji_svg_ext', '.svg' ),5484 'svgExt' => apply_filters( 'emoji_svg_ext', '.svg' ), 5043 5485 ); 5044 5486 5045 5487 $version = 'ver=' . get_bloginfo( 'version' ); … … 5053 5495 ); 5054 5496 5055 5497 ?> 5056 5057 5498 <script type="text/javascript"> 5499 window._wpemojiSettings = <?php echo wp_json_encode( $settings ); ?>; 5058 5500 <?php readfile( ABSPATH . WPINC . "/js/wp-emoji-loader.js" ); ?> 5059 5501 </script> 5060 5502 <?php 5061 5503 } else { 5062 5504 $settings['source'] = array( … … 5075 5517 * and edit wp-emoji-loader.js directly. 5076 5518 */ 5077 5519 ?> 5078 <script type="text/javascript"> 5079 window._wpemojiSettings = <?php echo wp_json_encode( $settings ); ?>; 5080 !function(a,b,c){function d(a){var b,c,d,e,f=String.fromCharCode;if(!k||!k.fillText)return!1;switch(k.clearRect(0,0,j.width,j.height),k.textBaseline="top",k.font="600 32px Arial",a){case"flag":return k.fillText(f(55356,56826,55356,56819),0,0),!(j.toDataURL().length<3e3)&&(k.clearRect(0,0,j.width,j.height),k.fillText(f(55356,57331,65039,8205,55356,57096),0,0),b=j.toDataURL(),k.clearRect(0,0,j.width,j.height),k.fillText(f(55356,57331,55356,57096),0,0),c=j.toDataURL(),b!==c);case"emoji4":return k.fillText(f(55357,56425,55356,57341,8205,55357,56507),0,0),d=j.toDataURL(),k.clearRect(0,0,j.width,j.height),k.fillText(f(55357,56425,55356,57341,55357,56507),0,0),e=j.toDataURL(),d!==e}return!1}function e(a){var c=b.createElement("script");c.src=a,c.defer=c.type="text/javascript",b.getElementsByTagName("head")[0].appendChild(c)}var f,g,h,i,j=b.createElement("canvas"),k=j.getContext&&j.getContext("2d");for(i=Array("flag","emoji4"),c.supports={everything:!0,everythingExceptFlag:!0},h=0;h<i.length;h++)c.supports[i[h]]=d(i[h]),c.supports.everything=c.supports.everything&&c.supports[i[h]],"flag"!==i[h]&&(c.supports.everythingExceptFlag=c.supports.everythingExceptFlag&&c.supports[i[h]]);c.supports.everythingExceptFlag=c.supports.everythingExceptFlag&&!c.supports.flag,c.DOMReady=!1,c.readyCallback=function(){c.DOMReady=!0},c.supports.everything||(g=function(){c.readyCallback()},b.addEventListener?(b.addEventListener("DOMContentLoaded",g,!1),a.addEventListener("load",g,!1)):(a.attachEvent("onload",g),b.attachEvent("onreadystatechange",function(){"complete"===b.readyState&&c.readyCallback()})),f=c.source||{},f.concatemoji?e(f.concatemoji):f.wpemoji&&f.twemoji&&(e(f.twemoji),e(f.wpemoji)))}(window,document,window._wpemojiSettings); 5081 </script> 5520 <script type="text/javascript"> 5521 window._wpemojiSettings = <?php echo wp_json_encode( $settings ); ?>; 5522 !function (a, b, c) { 5523 function d(a) { 5524 var b, c, d, e, f = String.fromCharCode; 5525 if (!k || !k.fillText)return !1; 5526 switch (k.clearRect(0, 0, j.width, j.height), k.textBaseline = "top", k.font = "600 32px Arial", a) { 5527 case"flag": 5528 return k.fillText(f(55356, 56826, 55356, 56819), 0, 0), !(j.toDataURL().length < 3e3) && (k.clearRect(0, 0, j.width, j.height), k.fillText(f(55356, 57331, 65039, 8205, 55356, 57096), 0, 0), b = j.toDataURL(), k.clearRect(0, 0, j.width, j.height), k.fillText(f(55356, 57331, 55356, 57096), 0, 0), c = j.toDataURL(), b !== c); 5529 case"emoji4": 5530 return k.fillText(f(55357, 56425, 55356, 57341, 8205, 55357, 56507), 0, 0), d = j.toDataURL(), k.clearRect(0, 0, j.width, j.height), k.fillText(f(55357, 56425, 55356, 57341, 55357, 56507), 0, 0), e = j.toDataURL(), d !== e 5531 } 5532 return !1 5533 } 5534 5535 function e(a) { 5536 var c = b.createElement("script"); 5537 c.src = a, c.defer = c.type = "text/javascript", b.getElementsByTagName("head")[0].appendChild(c) 5538 } 5539 5540 var f, g, h, i, j = b.createElement("canvas"), k = j.getContext && j.getContext("2d"); 5541 for (i = Array("flag", "emoji4"), c.supports = { 5542 everything: !0, 5543 everythingExceptFlag: !0 5544 }, h = 0; h < i.length; h++)c.supports[i[h]] = d(i[h]), c.supports.everything = c.supports.everything && c.supports[i[h]], "flag" !== i[h] && (c.supports.everythingExceptFlag = c.supports.everythingExceptFlag && c.supports[i[h]]); 5545 c.supports.everythingExceptFlag = c.supports.everythingExceptFlag && !c.supports.flag, c.DOMReady = !1, c.readyCallback = function () { 5546 c.DOMReady = !0 5547 }, c.supports.everything || (g = function () { 5548 c.readyCallback() 5549 }, b.addEventListener ? (b.addEventListener("DOMContentLoaded", g, !1), a.addEventListener("load", g, !1)) : (a.attachEvent("onload", g), b.attachEvent("onreadystatechange", function () { 5550 "complete" === b.readyState && c.readyCallback() 5551 })), f = c.source || {}, f.concatemoji ? e(f.concatemoji) : f.wpemoji && f.twemoji && (e(f.twemoji), e(f.wpemoji))) 5552 }(window, document, window._wpemojiSettings); 5553 </script> 5082 5554 <?php 5083 5555 } 5084 5556 } … … 5094 5566 * @since 4.2.0 5095 5567 * 5096 5568 * @param string $content The content to encode. 5569 * 5097 5570 * @return string The encoded content. 5098 5571 */ 5099 5572 function wp_encode_emoji( $content ) { … … 5119 5592 */ 5120 5593 $unpacked = unpack( 'H*', mb_convert_encoding( $emoji, 'UTF-32', 'UTF-8' ) ); 5121 5594 if ( isset( $unpacked[1] ) ) { 5122 $entity = '&#x' . ltrim( $unpacked[1], '0' ) . ';';5595 $entity = '&#x' . ltrim( $unpacked[1], '0' ) . ';'; 5123 5596 $content = str_replace( $emoji, $entity, $content ); 5124 5597 } 5125 5598 } … … 5136 5609 * @since 4.2.0 5137 5610 * 5138 5611 * @param string $text The content to encode. 5612 * 5139 5613 * @return string The encoded content. 5140 5614 */ 5141 5615 function wp_staticize_emoji( $text ) { … … 5154 5628 * 5155 5629 * First, capture the tags as well as in between. 5156 5630 */ 5157 $textarr = preg_split( '/(<.*>)/U', $text, - 1, PREG_SPLIT_DELIM_CAPTURE );5158 $stop = count( $textarr );5631 $textarr = preg_split( '/(<.*>)/U', $text, - 1, PREG_SPLIT_DELIM_CAPTURE ); 5632 $stop = count( $textarr ); 5159 5633 5160 5634 // Ignore processing of specific tags. 5161 $tags_to_ignore = 'code|pre|style|script|textarea';5635 $tags_to_ignore = 'code|pre|style|script|textarea'; 5162 5636 $ignore_block_element = ''; 5163 5637 5164 for ( $i = 0; $i < $stop; $i ++ ) {5165 $content = $textarr[ $i];5638 for ( $i = 0; $i < $stop; $i ++ ) { 5639 $content = $textarr[ $i ]; 5166 5640 5167 5641 // If we're in an ignore block, wait until we find its closing tag. 5168 if ( '' == $ignore_block_element && preg_match( '/^<(' . $tags_to_ignore . ')>/', $content, $matches ) ) 5642 if ( '' == $ignore_block_element && preg_match( '/^<(' . $tags_to_ignore . ')>/', $content, $matches ) ) { 5169 5643 $ignore_block_element = $matches[1]; 5170 5644 } 5171 5645 5172 5646 // If it's not a tag and not in ignore block. 5173 if ( '' == 5647 if ( '' == $ignore_block_element && strlen( $content ) > 0 && '<' != $content[0] ) { 5174 5648 $matches = array(); 5175 5649 if ( preg_match_all( '/(DZ(e[6-9a-f]|f[0-9a-f]);){2}/', $content, $matches ) ) { 5176 5650 if ( ! empty( $matches[0] ) ) { 5177 5651 foreach ( $matches[0] as $flag ) { 5178 $chars = str_replace( array( '&#x', ';' ), '', $flag );5652 $chars = str_replace( array( '&#x', ';' ), '', $flag ); 5179 5653 5180 5654 list( $char1, $char2 ) = str_split( $chars, 5 ); 5181 5655 $entity = sprintf( '<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', $cdn_url . $char1 . '-' . $char2 . $ext, html_entity_decode( $flag ) ); … … 5192 5666 if ( preg_match_all( $regex, $content, $matches ) ) { 5193 5667 if ( ! empty( $matches[1] ) ) { 5194 5668 foreach ( $matches[1] as $emoji ) { 5195 $char = str_replace( array( '&#x', ';'), '', $emoji );5669 $char = str_replace( array( '&#x', ';' ), '', $emoji ); 5196 5670 $entity = sprintf( '<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', $cdn_url . $char . $ext, html_entity_decode( $emoji ) ); 5197 5671 5198 5672 $content = str_replace( $emoji, $entity, $content ); … … 5202 5676 } 5203 5677 5204 5678 // Did we exit ignore block. 5205 if ( '' != $ignore_block_element && '</' . $ignore_block_element . '>' == $content ) 5679 if ( '' != $ignore_block_element && '</' . $ignore_block_element . '>' == $content ) { 5206 5680 $ignore_block_element = ''; 5207 5681 } 5208 5682 … … 5218 5692 * @since 4.2.0 5219 5693 * 5220 5694 * @param array $mail The email data array. 5695 * 5221 5696 * @return array The email data array, with emoji in the message staticized. 5222 5697 */ 5223 5698 function wp_staticize_emoji_for_email( $mail ) { … … 5242 5717 } 5243 5718 5244 5719 foreach ( $headers as $header ) { 5245 if ( strpos( $header, ':') === false ) {5720 if ( strpos( $header, ':' ) === false ) { 5246 5721 continue; 5247 5722 } 5248 5723 … … 5250 5725 list( $name, $content ) = explode( ':', trim( $header ), 2 ); 5251 5726 5252 5727 // Cleanup crew. 5253 $name = trim( $name 5728 $name = trim( $name ); 5254 5729 $content = trim( $content ); 5255 5730 5256 5731 if ( 'content-type' === strtolower( $name ) ) { … … 5285 5760 * @since 1.2.0 5286 5761 * @since 4.4.0 Moved to wp-includes/formatting.php from wp-admin/includes/misc.php and added $length param. 5287 5762 * 5288 * @param string $url URL to shorten. 5289 * @param int $length Optional. Maximum length of the shortened URL. Default 35 characters. 5763 * @param string $url URL to shorten. 5764 * @param int $length Optional. Maximum length of the shortened URL. Default 35 characters. 5765 * 5290 5766 * @return string Shortened URL. 5291 5767 */ 5292 5768 function url_shorten( $url, $length = 35 ) { 5293 $stripped = str_replace( array( 'https://', 'http://', 'www.' ), '', $url );5769 $stripped = str_replace( array( 'https://', 'http://', 'www.' ), '', $url ); 5294 5770 $short_url = untrailingslashit( $stripped ); 5295 5771 5296 5772 if ( strlen( $short_url ) > $length ) { 5297 5773 $short_url = substr( $short_url, 0, $length - 3 ) . '…'; 5298 5774 } 5775 5299 5776 return $short_url; 5300 5777 } 5301 5778 … … 5308 5785 * @since 3.4.0 5309 5786 * 5310 5787 * @param string $color 5788 * 5311 5789 * @return string|void 5312 5790 */ 5313 5791 function sanitize_hex_color( $color ) { … … 5316 5794 } 5317 5795 5318 5796 // 3 or 6 hex digits, or the empty string. 5319 if ( preg_match( '|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) ) {5797 if ( preg_match( '|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) ) { 5320 5798 return $color; 5321 5799 } 5322 5800 } … … 5333 5811 * @since 3.4.0 5334 5812 * 5335 5813 * @param string $color 5814 * 5336 5815 * @return string|null 5337 5816 */ 5338 5817 function sanitize_hex_color_no_hash( $color ) { … … 5354 5833 * @since 3.4.0 5355 5834 * 5356 5835 * @param string $color 5836 * 5357 5837 * @return string 5358 5838 */ 5359 5839 function maybe_hash_hex_color( $color ) {