diff -r 3d4e9c994f10 -r a86126ab1dd4 wp/wp-includes/formatting.php --- a/wp/wp-includes/formatting.php Tue Oct 22 16:11:46 2019 +0200 +++ b/wp/wp-includes/formatting.php Tue Dec 15 13:49:49 2020 +0100 @@ -8,7 +8,10 @@ */ /** - * Replaces common plain text characters into formatted entities + * Replaces common plain text characters with formatted entities. + * + * Returns given text with transformations of quotes into smart quotes, apostrophes, + * dashes, ellipses, the trademark symbol, and the multiplication symbol. * * As an example, * @@ -18,35 +21,18 @@ * * ’cause today’s effort makes it worth tomorrow’s “holiday” … * - * Code within certain html blocks are skipped. + * Code within certain HTML blocks are skipped. * * Do not use this function before the {@see 'init'} action hook; everything will break. * * @since 0.71 * - * @global array $wp_cockneyreplace Array of formatted entities for certain common phrases + * @global array $wp_cockneyreplace Array of formatted entities for certain common phrases. * @global array $shortcode_tags - * @staticvar array $static_characters - * @staticvar array $static_replacements - * @staticvar array $dynamic_characters - * @staticvar array $dynamic_replacements - * @staticvar array $default_no_texturize_tags - * @staticvar array $default_no_texturize_shortcodes - * @staticvar bool $run_texturize - * @staticvar string $apos - * @staticvar string $prime - * @staticvar string $double_prime - * @staticvar string $opening_quote - * @staticvar string $closing_quote - * @staticvar string $opening_single_quote - * @staticvar string $closing_single_quote - * @staticvar string $open_q_flag - * @staticvar string $open_sq_flag - * @staticvar string $apos_flag - * - * @param string $text The text to be formatted + * + * @param string $text The text to be formatted. * @param bool $reset Set to true for unit testing. Translated patterns will reset. - * @return string The string replaced with html entities + * @return string The string replaced with HTML entities. */ function wptexturize( $text, $reset = false ) { global $wp_cockneyreplace, $shortcode_tags; @@ -78,8 +64,8 @@ /** * Filters whether to skip running wptexturize(). * - * Passing false to the filter will effectively short-circuit wptexturize(). - * returning the original text passed to the function instead. + * Returning false from the filter will effectively short-circuit wptexturize() + * and return the original text passed to the function instead. * * The filter runs only once, the first time wptexturize() is called. * @@ -94,39 +80,40 @@ return $text; } - /* translators: opening curly double quote */ + /* translators: Opening curly double quote. */ $opening_quote = _x( '“', 'opening curly double quote' ); - /* translators: closing curly double quote */ + /* translators: Closing curly double quote. */ $closing_quote = _x( '”', 'closing curly double quote' ); - /* translators: apostrophe, for example in 'cause or can't */ + /* translators: Apostrophe, for example in 'cause or can't. */ $apos = _x( '’', 'apostrophe' ); - /* translators: prime, for example in 9' (nine feet) */ + /* translators: Prime, for example in 9' (nine feet). */ $prime = _x( '′', 'prime' ); - /* translators: double prime, for example in 9" (nine inches) */ + /* translators: Double prime, for example in 9" (nine inches). */ $double_prime = _x( '″', 'double prime' ); - /* translators: opening curly single quote */ + /* translators: Opening curly single quote. */ $opening_single_quote = _x( '‘', 'opening curly single quote' ); - /* translators: closing curly single quote */ + /* translators: Closing curly single quote. */ $closing_single_quote = _x( '’', 'closing curly single quote' ); - /* translators: en dash */ + /* translators: En dash. */ $en_dash = _x( '–', 'en dash' ); - /* translators: em dash */ + /* translators: Em dash. */ $em_dash = _x( '—', 'em dash' ); $default_no_texturize_tags = array( 'pre', 'code', 'kbd', 'style', 'script', 'tt' ); $default_no_texturize_shortcodes = array( 'code' ); - // if a plugin has provided an autocorrect array, use it + // If a plugin has provided an autocorrect array, use it. if ( isset( $wp_cockneyreplace ) ) { $cockney = array_keys( $wp_cockneyreplace ); $cockneyreplace = array_values( $wp_cockneyreplace ); } else { - /* translators: This is a comma-separated list of words that defy the syntax of quotations in normal use, - * for example... 'We do not have enough words yet' ... is a typical quoted phrase. But when we write + /* + * translators: This is a comma-separated list of words that defy the syntax of quotations in normal use, + * for example... 'We do not have enough words yet'... is a typical quoted phrase. But when we write * lines of code 'til we have enough of 'em, then we need to insert apostrophes instead of quotes. */ $cockney = explode( @@ -177,7 +164,7 @@ $dynamic['/\'(?=\d\d(?:\Z|(?![%\d]|[.,]\d)))/'] = $apos_flag; } - // Quoted Numbers like '0.42' + // Quoted numbers like '0.42'. if ( "'" !== $opening_single_quote && "'" !== $closing_single_quote ) { $dynamic[ '/(?<=\A|' . $spaces . ')\'(\d[.,\d]*)\'/' ] = $open_sq_flag . '$1' . $closing_single_quote; } @@ -187,7 +174,7 @@ $dynamic[ '/(?<=\A|[([{"\-]|<|' . $spaces . ')\'/' ] = $open_sq_flag; } - // Apostrophe in a word. No spaces, double apostrophes, or other punctuation. + // Apostrophe in a word. No spaces, double apostrophes, or other punctuation. if ( "'" !== $apos ) { $dynamic[ '/(? 1 ) { - // This sentence appears to have multiple closing quotes. Attempt Vulcan logic. + // This sentence appears to have multiple closing quotes. Attempt Vulcan logic. $sentence = preg_replace( $flag_no_digit, $close_quote, $sentence, -1, $count2 ); if ( 0 === $count2 ) { // Try looking for a quote followed by a period. @@ -368,14 +355,14 @@ $sentence = str_replace( $flag, $close_quote, $sentence ); $sentence = preg_replace( $prime_pattern, $prime, $sentence ); } else { - // No closing quotes found. Just run primes pattern. + // No closing quotes found. Just run primes pattern. $sentence = preg_replace( $prime_pattern, $prime, $sentence ); } } else { $sentence = preg_replace( $prime_pattern, $prime, $sentence ); $sentence = preg_replace( $quote_pattern, $close_quote, $sentence ); } - if ( '"' == $needle && false !== strpos( $sentence, '"' ) ) { + if ( '"' === $needle && false !== strpos( $sentence, '"' ) ) { $sentence = str_replace( '"', $close_quote, $sentence ); } } @@ -393,16 +380,16 @@ * @since 2.9.0 * @access private * - * @param string $text Text to check. Must be a tag like `` or `[shortcode]`. - * @param array $stack List of open tag elements. - * @param array $disabled_elements The tag names to match against. Spaces are not allowed in tag names. + * @param string $text Text to check. Must be a tag like `` or `[shortcode]`. + * @param string[] $stack Array of open tag elements. + * @param string[] $disabled_elements Array of tag names to match against. Spaces are not allowed in tag names. */ function _wptexturize_pushpop_element( $text, &$stack, $disabled_elements ) { // Is it an opening tag or closing tag? if ( isset( $text[1] ) && '/' !== $text[1] ) { $opening_tag = true; $name_offset = 1; - } elseif ( 0 == count( $stack ) ) { + } elseif ( 0 === count( $stack ) ) { // Stack is empty. Just stop. return; } else { @@ -420,14 +407,14 @@ $tag = substr( $text, $name_offset, $space ); // Handle disabled tags. - if ( in_array( $tag, $disabled_elements ) ) { + if ( in_array( $tag, $disabled_elements, true ) ) { if ( $opening_tag ) { /* * This disables texturize until we find a closing tag of our type - * (e.g.
) even if there was invalid nesting before that
+			 * (e.g. 
) even if there was invalid nesting before that.
 			 *
 			 * Example: in the case 
sadsadasd"baba"
- * "baba" won't be texturize + * "baba" won't be texturized. */ array_push( $stack, $tag ); @@ -438,17 +425,18 @@ } /** - * Replaces double line-breaks with paragraph elements. + * Replaces double line breaks with paragraph elements. * * A group of regex replaces used to identify text formatted with newlines and - * replace double line-breaks with HTML paragraph tags. The remaining line-breaks + * replace double line breaks with HTML paragraph tags. The remaining line breaks * after conversion become <
> tags, unless $br is set to '0' or 'false'. * * @since 0.71 * * @param string $pee The text which has to be formatted. - * @param bool $br Optional. If set, this will convert all remaining line-breaks - * after paragraphing. Default true. + * @param bool $br Optional. If set, this will convert all remaining line breaks + * after paragraphing. Line breaks within `