* 'cause today's effort makes it worth tomorrow's "holiday"... * * Becomes: * * ’cause today’s effort makes it worth tomorrow’s “holiday”… * * Code within certain html blocks are skipped. * * @since 0.71 * @uses $wp_cockneyreplace Array of formatted entities for certain common phrases * * @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 */ function wptexturize($text, $reset = false) { global $wp_cockneyreplace; static $static_characters, $static_replacements, $dynamic_characters, $dynamic_replacements, $default_no_texturize_tags, $default_no_texturize_shortcodes, $run_texturize = true; // If there's nothing to do, just stop. if ( empty( $text ) || false === $run_texturize ) { return $text; } // Set up static variables. Run once only. if ( $reset || ! isset( $static_characters ) ) { /** * Filter whether to skip running `wptexturize()`. * * Passing false to the filter will effectively short-circuit `wptexturize()`. * returning the original text passed to the function instead. * * The filter runs only once, the first time `wptexturize()` is called. * * @since 4.0.0 * * @param bool $run_texturize Whether to short-circuit `wptexturize()`. */ $run_texturize = apply_filters( 'run_wptexturize', $run_texturize ); if ( false === $run_texturize ) { return $text; } /* translators: opening curly double quote */ $opening_quote = _x( '“', 'opening curly double quote' ); /* translators: closing curly double quote */ $closing_quote = _x( '”', 'closing curly double quote' ); /* translators: apostrophe, for example in 'cause or can't */ $apos = _x( '’', 'apostrophe' ); /* translators: prime, for example in 9' (nine feet) */ $prime = _x( '′', 'prime' ); /* translators: double prime, for example in 9" (nine inches) */ $double_prime = _x( '″', 'double prime' ); /* translators: opening curly single quote */ $opening_single_quote = _x( '‘', 'opening curly single quote' ); /* translators: closing curly single quote */ $closing_single_quote = _x( '’', 'closing curly single quote' ); /* translators: en dash */ $en_dash = _x( '–', 'en 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 ( isset($wp_cockneyreplace) ) { $cockney = array_keys($wp_cockneyreplace); $cockneyreplace = array_values($wp_cockneyreplace); } elseif ( "'" != $apos ) { // Only bother if we're doing a replacement. $cockney = array( "'tain't", "'twere", "'twas", "'tis", "'twill", "'til", "'bout", "'nuff", "'round", "'cause" ); $cockneyreplace = array( $apos . "tain" . $apos . "t", $apos . "twere", $apos . "twas", $apos . "tis", $apos . "twill", $apos . "til", $apos . "bout", $apos . "nuff", $apos . "round", $apos . "cause" ); } else { $cockney = $cockneyreplace = array(); } $static_characters = array_merge( array( '...', '``', '\'\'', ' (tm)' ), $cockney ); $static_replacements = array_merge( array( '…', $opening_quote, $closing_quote, ' ™' ), $cockneyreplace ); $spaces = wp_spaces_regexp(); // Pattern-based replacements of characters. $dynamic = array(); // '99' and '99" are ambiguous among other patterns; assume it's an abbreviated year at the end of a quotation. if ( "'" !== $apos || "'" !== $closing_single_quote ) { $dynamic[ '/\'(\d\d)\'(?=\Z|[.,)}>\-\]]|' . $spaces . ')/' ] = $apos . '$1' . $closing_single_quote; } if ( "'" !== $apos || '"' !== $closing_quote ) { $dynamic[ '/\'(\d\d)"(?=\Z|[.,)}>\-\]]|' . $spaces . ')/' ] = $apos . '$1' . $closing_quote; } // '99 '99s '99's (apostrophe) But never '9 or '99% or '999 or '99.0. if ( "'" !== $apos ) { $dynamic[ '/\'(?=\d\d(?:\Z|(?![%\d]|[.,]\d)))/' ] = $apos; } // Quoted Numbers like "42" or '42.00' if ( '"' !== $opening_quote && '"' !== $closing_quote ) { $dynamic[ '/(?<=\A|' . $spaces . ')"(\d[.,\d]*)"/' ] = $opening_quote . '$1' . $closing_quote; } if ( "'" !== $opening_single_quote && "'" !== $closing_single_quote ) { $dynamic[ '/(?<=\A|' . $spaces . ')\'(\d[.,\d]*)\'/' ] = $opening_single_quote . '$1' . $closing_single_quote; } // Single quote at start, or preceded by (, {, <, [, ", -, or spaces. if ( "'" !== $opening_single_quote ) { $dynamic[ '/(?<=\A|[([{<"\-]|' . $spaces . ')\'/' ] = $opening_single_quote; } // Apostrophe in a word. No spaces, double apostrophes, or other punctuation. if ( "'" !== $apos ) { $dynamic[ '/(?[\]\-]|' . $spaces . ')/' ] = $apos; } // 9" (double prime) if ( '"' !== $double_prime ) { $dynamic[ '/(?<=\d)"/' ] = $double_prime; } // 9' (prime) if ( "'" !== $prime ) { $dynamic[ '/(?<=\d)\'/' ] = $prime; } // Double quote at start, or preceded by (, {, <, [, -, or spaces, and not followed by spaces. if ( '"' !== $opening_quote ) { $dynamic[ '/(?<=\A|[([{<\-]|' . $spaces . ')"(?!' . $spaces . ')/' ] = $opening_quote; } // Any remaining double quotes. if ( '"' !== $closing_quote ) { $dynamic[ '/"/' ] = $closing_quote; } // Single quotes followed by spaces or ending punctuation. if ( "'" !== $closing_single_quote ) { $dynamic[ '/\'(?=\Z|[.,)}>\-\]]|' . $spaces . ')/' ] = $closing_single_quote; } // Dashes and spaces $dynamic[ '/---/' ] = $em_dash; $dynamic[ '/(?<=' . $spaces . ')--(?=' . $spaces . ')/' ] = $em_dash; $dynamic[ '/(?' // Find end of comment . '|' . '.+?>' // Find end of element . ')' . '|' . '\[' // Find start of shortcode. . '\[?' // Shortcodes may begin with [[ . '(?:' . '[^\[\]<>]' // Shortcodes do not contain other shortcodes. . '|' . '<.+?>' // HTML elements permitted. Prevents matching ] before >. . ')+' . '\]' // Find end of shortcode. . '\]?' // Shortcodes may end with ]] . ')/s'; $textarr = preg_split( $regex, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY ); foreach ( $textarr as &$curl ) { // Only call _wptexturize_pushpop_element if $curl is a delimeter. $first = $curl[0]; if ( '<' === $first && '>' === substr( $curl, -1 ) ) { // This is an HTML delimeter. if ( '