Changeset 54927
- Timestamp:
- 12/02/2022 06:51:56 PM (22 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/formatting.php
r54813 r54927 919 919 * @access private 920 920 * 921 * @param string $ stringThe text which is to be encoded.921 * @param string $text The text which is to be encoded. 922 922 * @param int|string $quote_style Optional. Converts double quotes if set to ENT_COMPAT, 923 923 * both single and double if set to ENT_QUOTES or none if set to ENT_NOQUOTES. … … 932 932 * @return string The encoded text with HTML entities. 933 933 */ 934 function _wp_specialchars( $ string, $quote_style = ENT_NOQUOTES, $charset = false, $double_encode = false ) {935 $ string = (string) $string;936 937 if ( 0 === strlen( $ string) ) {934 function _wp_specialchars( $text, $quote_style = ENT_NOQUOTES, $charset = false, $double_encode = false ) { 935 $text = (string) $text; 936 937 if ( 0 === strlen( $text ) ) { 938 938 return ''; 939 939 } 940 940 941 941 // Don't bother if there are no specialchars - saves some processing. 942 if ( ! preg_match( '/[&<>"\']/', $ string) ) {943 return $ string;942 if ( ! preg_match( '/[&<>"\']/', $text ) ) { 943 return $text; 944 944 } 945 945 … … 979 979 // Guarantee every &entity; is valid, convert &garbage; into &garbage; 980 980 // This is required for PHP < 5.4.0 because ENT_HTML401 flag is unavailable. 981 $ string = wp_kses_normalize_entities( $string, ( $quote_style & ENT_XML1 ) ? 'xml' : 'html' );982 } 983 984 $ string = htmlspecialchars( $string, $quote_style, $charset, $double_encode );981 $text = wp_kses_normalize_entities( $text, ( $quote_style & ENT_XML1 ) ? 'xml' : 'html' ); 982 } 983 984 $text = htmlspecialchars( $text, $quote_style, $charset, $double_encode ); 985 985 986 986 // Back-compat. 987 987 if ( 'single' === $_quote_style ) { 988 $ string = str_replace( "'", ''', $string);989 } 990 991 return $ string;988 $text = str_replace( "'", ''', $text ); 989 } 990 991 return $text; 992 992 } 993 993 … … 1002 1002 * @since 2.8.0 1003 1003 * 1004 * @param string $ stringThe text which is to be decoded.1004 * @param string $text The text which is to be decoded. 1005 1005 * @param string|int $quote_style Optional. Converts double quotes if set to ENT_COMPAT, 1006 1006 * both single and double if set to ENT_QUOTES or … … 1012 1012 * @return string The decoded text without HTML entities. 1013 1013 */ 1014 function wp_specialchars_decode( $ string, $quote_style = ENT_NOQUOTES ) {1015 $ string = (string) $string;1016 1017 if ( 0 === strlen( $ string) ) {1014 function wp_specialchars_decode( $text, $quote_style = ENT_NOQUOTES ) { 1015 $text = (string) $text; 1016 1017 if ( 0 === strlen( $text ) ) { 1018 1018 return ''; 1019 1019 } 1020 1020 1021 1021 // Don't bother if there are no entities - saves a lot of processing. 1022 if ( strpos( $ string, '&' ) === false ) {1023 return $ string;1022 if ( strpos( $text, '&' ) === false ) { 1023 return $text; 1024 1024 } 1025 1025 … … 1080 1080 1081 1081 // Remove zero padding on numeric entities. 1082 $ string = preg_replace( array_keys( $translation_preg ), array_values( $translation_preg ), $string);1082 $text = preg_replace( array_keys( $translation_preg ), array_values( $translation_preg ), $text ); 1083 1083 1084 1084 // Replace characters according to translation table. 1085 return strtr( $ string, $translation );1085 return strtr( $text, $translation ); 1086 1086 } 1087 1087 … … 1091 1091 * @since 2.8.0 1092 1092 * 1093 * @param string $ stringThe text which is to be checked.1093 * @param string $text The text which is to be checked. 1094 1094 * @param bool $strip Optional. Whether to attempt to strip out invalid UTF8. Default false. 1095 1095 * @return string The checked text. 1096 1096 */ 1097 function wp_check_invalid_utf8( $ string, $strip = false ) {1098 $ string = (string) $string;1099 1100 if ( 0 === strlen( $ string) ) {1097 function wp_check_invalid_utf8( $text, $strip = false ) { 1098 $text = (string) $text; 1099 1100 if ( 0 === strlen( $text ) ) { 1101 1101 return ''; 1102 1102 } … … 1108 1108 } 1109 1109 if ( ! $is_utf8 ) { 1110 return $ string;1110 return $text; 1111 1111 } 1112 1112 … … 1119 1119 // We can't demand utf8 in the PCRE installation, so just return the string in those cases. 1120 1120 if ( ! $utf8_pcre ) { 1121 return $ string;1122 } 1123 1124 // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- preg_match fails when it encounters invalid UTF8 in $ string.1125 if ( 1 === @preg_match( '/^./us', $ string) ) {1126 return $ string;1121 return $text; 1122 } 1123 1124 // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- preg_match fails when it encounters invalid UTF8 in $text. 1125 if ( 1 === @preg_match( '/^./us', $text ) ) { 1126 return $text; 1127 1127 } 1128 1128 1129 1129 // Attempt to strip the bad chars if requested (not recommended). 1130 1130 if ( $strip && function_exists( 'iconv' ) ) { 1131 return iconv( 'utf-8', 'utf-8', $ string);1131 return iconv( 'utf-8', 'utf-8', $text ); 1132 1132 } 1133 1133 … … 1587 1587 * @since 6.1.0 Added Unicode NFC encoding normalization support. 1588 1588 * 1589 * @param string $ stringText that might have accent characters.1589 * @param string $text Text that might have accent characters. 1590 1590 * @param string $locale Optional. The locale to use for accent removal. Some character 1591 1591 * replacements depend on the locale being used (e.g. 'de_DE'). … … 1593 1593 * @return string Filtered string with replaced "nice" characters. 1594 1594 */ 1595 function remove_accents( $ string, $locale = '' ) {1596 if ( ! preg_match( '/[\x80-\xff]/', $ string) ) {1597 return $ string;1598 } 1599 1600 if ( seems_utf8( $ string) ) {1595 function remove_accents( $text, $locale = '' ) { 1596 if ( ! preg_match( '/[\x80-\xff]/', $text ) ) { 1597 return $text; 1598 } 1599 1600 if ( seems_utf8( $text ) ) { 1601 1601 1602 1602 // Unicode sequence normalization from NFD (Normalization Form Decomposed) … … 1605 1605 && function_exists( 'normalizer_normalize' ) 1606 1606 ) { 1607 if ( ! normalizer_is_normalized( $ string) ) {1608 $ string = normalizer_normalize( $string);1607 if ( ! normalizer_is_normalized( $text ) ) { 1608 $text = normalizer_normalize( $text ); 1609 1609 } 1610 1610 } … … 1971 1971 } 1972 1972 1973 $ string = strtr( $string, $chars );1973 $text = strtr( $text, $chars ); 1974 1974 } else { 1975 1975 $chars = array(); … … 1988 1988 $chars['out'] = 'EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy'; 1989 1989 1990 $ string = strtr( $string, $chars['in'], $chars['out'] );1990 $text = strtr( $text, $chars['in'], $chars['out'] ); 1991 1991 $double_chars = array(); 1992 1992 $double_chars['in'] = array( "\x8c", "\x9c", "\xc6", "\xd0", "\xde", "\xdf", "\xe6", "\xf0", "\xfe" ); 1993 1993 $double_chars['out'] = array( 'OE', 'oe', 'AE', 'DH', 'TH', 'ss', 'ae', 'dh', 'th' ); 1994 $ string = str_replace( $double_chars['in'], $double_chars['out'], $string);1995 } 1996 1997 return $ string;1994 $text = str_replace( $double_chars['in'], $double_chars['out'], $text ); 1995 } 1996 1997 return $text; 1998 1998 } 1999 1999 … … 2743 2743 * @since 0.71 2744 2744 * 2745 * @param string $ stringValue to which backslashes will be added.2745 * @param string $value Value to which backslashes will be added. 2746 2746 * @return string String with backslashes inserted. 2747 2747 */ 2748 function backslashit( $ string) {2749 if ( isset( $ string[0] ) && $string[0] >= '0' && $string[0] <= '9' ) {2750 $ string = '\\\\' . $string;2751 } 2752 return addcslashes( $ string, 'A..Za..z' );2748 function backslashit( $value ) { 2749 if ( isset( $value[0] ) && $value[0] >= '0' && $value[0] <= '9' ) { 2750 $value = '\\\\' . $value; 2751 } 2752 return addcslashes( $value, 'A..Za..z' ); 2753 2753 } 2754 2754 … … 2764 2764 * @since 1.2.0 2765 2765 * 2766 * @param string $ string What to add the trailing slash to.2766 * @param string $value Value to which trailing slash will be added. 2767 2767 * @return string String with trailing slash added. 2768 2768 */ 2769 function trailingslashit( $ string) {2770 return untrailingslashit( $ string) . '/';2769 function trailingslashit( $value ) { 2770 return untrailingslashit( $value ) . '/'; 2771 2771 } 2772 2772 … … 2779 2779 * @since 2.2.0 2780 2780 * 2781 * @param string $ string What to remove the trailing slashes from.2781 * @param string $text Value from which trailing slashes will be removed. 2782 2782 * @return string String without the trailing slashes. 2783 2783 */ 2784 function untrailingslashit( $ string) {2785 return rtrim( $ string, '/\\' );2784 function untrailingslashit( $value ) { 2785 return rtrim( $value, '/\\' ); 2786 2786 } 2787 2787 … … 3085 3085 * 5 => '1234567890a ', // 12 characters: Too long, but no inner whitespace on which to split. 3086 3086 * 6 => ' 45678 ', // 11 characters: Perfect split. 3087 * 7 => '1 3 5 7 90 ', // 11 characters: End of $ string.3087 * 7 => '1 3 5 7 90 ', // 11 characters: End of $text. 3088 3088 * ); 3089 3089 * … … 3091 3091 * @access private 3092 3092 * 3093 * @param string $ stringThe string to split.3093 * @param string $text The string to split. 3094 3094 * @param int $goal The desired chunk length. 3095 3095 * @return array Numeric array of chunks. 3096 3096 */ 3097 function _split_str_by_whitespace( $ string, $goal ) {3097 function _split_str_by_whitespace( $text, $goal ) { 3098 3098 $chunks = array(); 3099 3099 3100 $string_nullspace = strtr( $ string, "\r\n\t\v\f ", "\000\000\000\000\000\000" );3100 $string_nullspace = strtr( $text, "\r\n\t\v\f ", "\000\000\000\000\000\000" ); 3101 3101 3102 3102 while ( $goal < strlen( $string_nullspace ) ) { … … 3110 3110 } 3111 3111 3112 $chunks[] = substr( $ string, 0, $pos + 1 );3113 $ string = substr( $string, $pos + 1 );3112 $chunks[] = substr( $text, 0, $pos + 1 ); 3113 $text = substr( $text, $pos + 1 ); 3114 3114 $string_nullspace = substr( $string_nullspace, $pos + 1 ); 3115 3115 } 3116 3116 3117 if ( $ string) {3118 $chunks[] = $ string;3117 if ( $text ) { 3118 $chunks[] = $text; 3119 3119 } 3120 3120 … … 3553 3553 * @since 1.2.0 3554 3554 * 3555 * @param string $s tringSubject line.3555 * @param string $subject Subject line. 3556 3556 * @return string Converted string to ASCII. 3557 3557 */ 3558 function wp_iso_descrambler( $s tring) {3558 function wp_iso_descrambler( $subject ) { 3559 3559 /* this may only work with iso-8859-1, I'm afraid */ 3560 if ( ! preg_match( '#\=\?(.+)\?Q\?(.+)\?\=#i', $s tring, $matches ) ) {3561 return $s tring;3562 } else {3563 $subject = str_replace( '_', ' ', $matches[2] ); 3564 return preg_replace_callback( '#\=([0-9a-f]{2})#i', '_wp_iso_convert', $subject);3565 }3560 if ( ! preg_match( '#\=\?(.+)\?Q\?(.+)\?\=#i', $subject, $matches ) ) { 3561 return $subject; 3562 } 3563 3564 $subject = str_replace( '_', ' ', $matches[2] ); 3565 return preg_replace_callback( '#\=([0-9a-f]{2})#i', '_wp_iso_convert', $subject ); 3566 3566 } 3567 3567 … … 3572 3572 * @access private 3573 3573 * 3574 * @param array $match The preg_replace_callback matches array.3574 * @param array $matches The preg_replace_callback matches array. 3575 3575 * @return string Converted chars. 3576 3576 */ 3577 function _wp_iso_convert( $match ) {3578 return chr( hexdec( strtolower( $match [1] ) ) );3577 function _wp_iso_convert( $matches ) { 3578 return chr( hexdec( strtolower( $matches[1] ) ) ); 3579 3579 } 3580 3580 … … 3587 3587 * @since 1.2.0 3588 3588 * 3589 * @param string $ string The date to be converted, in the timezone of the site.3590 * @param string $format The format string for the returned date. Default 'Y-m-d H:i:s'.3589 * @param string $date_string The date to be converted, in the timezone of the site. 3590 * @param string $format The format string for the returned date. Default 'Y-m-d H:i:s'. 3591 3591 * @return string Formatted version of the date, in UTC. 3592 3592 */ 3593 function get_gmt_from_date( $ string, $format = 'Y-m-d H:i:s' ) {3594 $datetime = date_create( $ string, wp_timezone() );3593 function get_gmt_from_date( $date_string, $format = 'Y-m-d H:i:s' ) { 3594 $datetime = date_create( $date_string, wp_timezone() ); 3595 3595 3596 3596 if ( false === $datetime ) { … … 3609 3609 * @since 1.2.0 3610 3610 * 3611 * @param string $ string The date to be converted, in UTC or GMT timezone.3612 * @param string $format The format string for the returned date. Default 'Y-m-d H:i:s'.3611 * @param string $date_string The date to be converted, in UTC or GMT timezone. 3612 * @param string $format The format string for the returned date. Default 'Y-m-d H:i:s'. 3613 3613 * @return string Formatted version of the date, in the site's timezone. 3614 3614 */ 3615 function get_date_from_gmt( $ string, $format = 'Y-m-d H:i:s' ) {3616 $datetime = date_create( $ string, new DateTimeZone( 'UTC' ) );3615 function get_date_from_gmt( $date_string, $format = 'Y-m-d H:i:s' ) { 3616 $datetime = date_create( $date_string, new DateTimeZone( 'UTC' ) ); 3617 3617 3618 3618 if ( false === $datetime ) { … … 5034 5034 * @since 2.2.1 5035 5035 * 5036 * @param string $ stringThe string to be parsed.5037 * @param array $ arrayVariables will be stored in this array.5038 */ 5039 function wp_parse_str( $ string, &$array) {5040 parse_str( (string) $ string, $array);5036 * @param string $input The string to be parsed. 5037 * @param array $result Variables will be stored in this array. 5038 */ 5039 function wp_parse_str( $input, &$result ) { 5040 parse_str( (string) $input, $result ); 5041 5041 5042 5042 /** … … 5045 5045 * @since 2.2.1 5046 5046 * 5047 * @param array $ arrayThe array populated with variables.5047 * @param array $result The array populated with variables. 5048 5048 */ 5049 $ array = apply_filters( 'wp_parse_str', $array);5049 $result = apply_filters( 'wp_parse_str', $result ); 5050 5050 } 5051 5051 … … 5057 5057 * @since 2.3.0 5058 5058 * 5059 * @param string $ text Text to be converted.5059 * @param string $content Text to be converted. 5060 5060 * @return string Converted text. 5061 5061 */ 5062 function wp_pre_kses_less_than( $ text ) {5063 return preg_replace_callback( '%<[^>]*?((?=<)|>|$)%', 'wp_pre_kses_less_than_callback', $ text );5062 function wp_pre_kses_less_than( $content ) { 5063 return preg_replace_callback( '%<[^>]*?((?=<)|>|$)%', 'wp_pre_kses_less_than_callback', $content ); 5064 5064 } 5065 5065 … … 5085 5085 * @since 5.3.1 5086 5086 * 5087 * @param string $ stringContent to be run through KSES.5087 * @param string $content Content to be run through KSES. 5088 5088 * @param array[]|string $allowed_html An array of allowed HTML elements 5089 5089 * and attributes, or a context name … … 5092 5092 * @return string Filtered text to run through KSES. 5093 5093 */ 5094 function wp_pre_kses_block_attributes( $ string, $allowed_html, $allowed_protocols ) {5094 function wp_pre_kses_block_attributes( $content, $allowed_html, $allowed_protocols ) { 5095 5095 /* 5096 5096 * `filter_block_content` is expected to call `wp_kses`. Temporarily remove … … 5098 5098 */ 5099 5099 remove_filter( 'pre_kses', 'wp_pre_kses_block_attributes', 10 ); 5100 $ string = filter_block_content( $string, $allowed_html, $allowed_protocols );5100 $content = filter_block_content( $content, $allowed_html, $allowed_protocols ); 5101 5101 add_filter( 'pre_kses', 'wp_pre_kses_block_attributes', 10, 3 ); 5102 5102 5103 return $ string;5103 return $content; 5104 5104 } 5105 5105 … … 5390 5390 * @since 2.9.0 5391 5391 * 5392 * @param string $ stringString containing HTML tags5392 * @param string $text String containing HTML tags 5393 5393 * @param bool $remove_breaks Optional. Whether to remove left over line breaks and white space chars 5394 5394 * @return string The processed string. 5395 5395 */ 5396 function wp_strip_all_tags( $ string, $remove_breaks = false ) {5397 $ string = preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $string);5398 $ string = strip_tags( $string);5396 function wp_strip_all_tags( $text, $remove_breaks = false ) { 5397 $text = preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $text ); 5398 $text = strip_tags( $text ); 5399 5399 5400 5400 if ( $remove_breaks ) { 5401 $ string = preg_replace( '/[\r\n\t ]+/', ' ', $string);5402 } 5403 5404 return trim( $ string);5401 $text = preg_replace( '/[\r\n\t ]+/', ' ', $text ); 5402 } 5403 5404 return trim( $text ); 5405 5405 } 5406 5406
Note: See TracChangeset
for help on using the changeset viewer.