WordPress.org

Make WordPress Core

Ticket #19855: 19855-2.patch

File 19855-2.patch, 4.6 KB (added by azaozz, 6 years ago)
  • wp-includes/deprecated.php

     
    29762976                return $theme;
    29772977
    29782978        return wp_get_theme()->get('Name');
    2979 }
    2980  No newline at end of file
     2979}
     2980
     2981/**
     2982 * Accepts matches array from preg_replace_callback in wpautop() or a string.
     2983 *
     2984 * Ensures that the contents of a <<pre>>...<</pre>> HTML block are not
     2985 * converted into paragraphs or line-breaks.
     2986 *
     2987 * @since 1.2.0
     2988 * @deprecated 3.4.0
     2989 *
     2990 * @param array|string $matches The array or string
     2991 * @return string The pre block without paragraph/line-break conversion.
     2992 */
     2993function clean_pre($matches) {
     2994        _deprecated_function( __FUNCTION__, '3.4' );
     2995       
     2996        if ( is_array($matches) )
     2997                $text = $matches[1] . $matches[2] . "</pre>";
     2998        else
     2999                $text = $matches;
     3000
     3001        $text = str_replace('<br />', '', $text);
     3002        $text = str_replace('<p>', "\n", $text);
     3003        $text = str_replace('</p>', '', $text);
     3004
     3005        return $text;
     3006}
     3007
  • wp-includes/formatting.php

     
    173173}
    174174
    175175/**
    176  * Accepts matches array from preg_replace_callback in wpautop() or a string.
    177  *
    178  * Ensures that the contents of a <<pre>>...<</pre>> HTML block are not
    179  * converted into paragraphs or line-breaks.
    180  *
    181  * @since 1.2.0
    182  *
    183  * @param array|string $matches The array or string
    184  * @return string The pre block without paragraph/line-break conversion.
    185  */
    186 function clean_pre($matches) {
    187         if ( is_array($matches) )
    188                 $text = $matches[1] . $matches[2] . "</pre>";
    189         else
    190                 $text = $matches;
    191 
    192         $text = str_replace('<br />', '', $text);
    193         $text = str_replace('<p>', "\n", $text);
    194         $text = str_replace('</p>', '', $text);
    195 
    196         return $text;
    197 }
    198 
    199 /**
    200176 * Replaces double line-breaks with paragraph elements.
    201177 *
    202178 * A group of regex replaces used to identify text formatted with newlines and
     
    207183 * @since 0.71
    208184 *
    209185 * @param string $pee The text which has to be formatted.
    210  * @param int|bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
     186 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
    211187 * @return string Text which has been converted into correct paragraph tags.
    212188 */
    213 function wpautop($pee, $br = 1) {
     189function wpautop($pee, $br = true) {
     190        $has_pre = false;
    214191
    215192        if ( trim($pee) === '' )
    216193                return '';
     194
    217195        $pee = $pee . "\n"; // just to make things a little easier, pad the end
     196
     197        if ( strpos($pee, '<pre') !== false ) {
     198                $has_pre = true;
     199                $pee_parts = explode( '</pre>', $pee );
     200                $last_pee = array_pop($pee_parts);
     201                $pee = '';
     202
     203                foreach ( $pee_parts as $pee_part ) {
     204                        $pee .= preg_replace_callback('/<pre(?: [^>]+)*>.+/s', '_autop_newline_preservation_helper', $pee_part) . '</pre>';
     205                }
     206
     207                $pee .= $last_pee;
     208        }
     209
    218210        $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    219211        // Space things out a little
    220212        $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|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)';
     
    239231        $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    240232        $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "$1", $pee);
    241233        $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee);
    242         if ($br) {
     234        if ( $br ) {
    243235                $pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', '_autop_newline_preservation_helper', $pee);
    244236                $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee); // optionally make line breaks
    245                 $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    246237        }
    247238        $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "$1", $pee);
    248239        $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    249         if (strpos($pee, '<pre') !== false)
    250                 $pee = preg_replace_callback('!(<pre[^>]*>)(.*?)</pre>!is', 'clean_pre', $pee );
    251240        $pee = preg_replace( "|\n</p>$|", '</p>', $pee );
    252241
     242        if ( $br || $has_pre )
     243                $pee = str_replace('<autop newline>', "\n", $pee);
     244
    253245        return $pee;
    254246}
    255247
     
    262254 * @returns string
    263255 */
    264256function _autop_newline_preservation_helper( $matches ) {
    265         return str_replace("\n", "<WPPreserveNewline />", $matches[0]);
     257        return str_replace( array("\r\n", "\r", "\n"), '<autop newline>', $matches[0] );
    266258}
    267259
    268260/**