WordPress.org

Make WordPress Core

Ticket #10490: shortcodes_wpautop_patch_2009_07_26.diff

File shortcodes_wpautop_patch_2009_07_26.diff, 2.2 KB (added by alanjohndix, 9 years ago)

suggested patch

  • wp-includes/shortcodes.php

     
    175175        $tagnames = array_keys($shortcode_tags);
    176176        $tagregexp = join( '|', array_map('preg_quote', $tagnames) );
    177177
    178         return '(.?)\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?(.?)';
     178        return '(.?)\[('.$tagregexp.')\b([^\]]*?)(?:(\/))?\](?:(.+?)\[\/\2\])?(.?)';
    179179}
    180180
    181181/**
     182 * Retrieve the shortcode regular expression for searching for start tag only.
     183 *
     184 * @uses $shortcode_tags
     185 *
     186 * @return string The shortcode start tag search regular expression
     187 */
     188function get_shortcode_start_regex() {
     189        global $shortcode_tags;
     190        $tagnames = array_keys($shortcode_tags);
     191        $tagregexp = join( '|', array_map('preg_quote', $tagnames) );
     192       
     193        return '\[('.$tagregexp.')\b([^\]]*?)(?:(\/))?\]';
     194}
     195
     196/**
     197 * Retrieve the shortcode regular expression for searching for end tag only.
     198 *
     199 * @uses $shortcode_tags
     200 *
     201 * @return string The shortcode end tag search regular expression
     202 */
     203function get_shortcode_end_regex() {
     204        global $shortcode_tags;
     205        $tagnames = array_keys($shortcode_tags);
     206        $tagregexp = join( '|', array_map('preg_quote', $tagnames) );
     207       
     208        return '\[\/('.$tagregexp.')\]';
     209}
     210
     211/**
    182212 * Regular Expression callable for do_shortcode() for calling shortcode hook.
    183213 * @see get_shortcode_regex for details of the match array contents.
    184214 *
  • wp-includes/formatting.php

     
    170170        if (strpos($pee, '<pre') !== false)
    171171                $pee = preg_replace_callback('!(<pre[^>]*>)(.*?)</pre>!is', 'clean_pre', $pee );
    172172        $pee = preg_replace( "|\n</p>$|", '</p>', $pee );
    173         $pee = preg_replace('/<p>\s*?(' . get_shortcode_regex() . ')\s*<\/p>/s', '$1', $pee); // don't auto-p wrap shortcodes that stand alone
     173        $pee = preg_replace('/<p>\s*?(' . get_shortcode_start_regex() . ')\s*<\/p>/s', '$1', $pee); // don't auto-p wrap shortcodes that stand alone
     174        $pee = preg_replace('/<p>\s*?(' . get_shortcode_end_regex() . ')\s*<\/p>/s', '$1', $pee);   // check both start and end tags
    174175
    175176        return $pee;
    176177}