WordPress.org

Make WordPress Core

Ticket #12760: shortcodes.2.diff

File shortcodes.2.diff, 2.5 KB (added by azram19, 7 years ago)
  • wp-includes/shortcodes.php

     
    133133 * If there are no shortcode tags defined, then the content will be returned
    134134 * without any filtering. This might cause issues when plugins are disabled but
    135135 * the shortcode will still show up in the post or content.
     136 * @see get_shortcode_regex for details of the pattern.
    136137 *
    137138 * @since 2.5
    138139 * @uses $shortcode_tags
    139  * @uses get_shortcode_regex() Gets the search pattern for searching shortcodes.
    140140 *
    141141 * @param string $content Content to search for shortcodes
    142142 * @return string Content with shortcodes filtered out.
     
    147147        if (empty($shortcode_tags) || !is_array($shortcode_tags))
    148148                return $content;
    149149
    150         $pattern = get_shortcode_regex();
    151         return preg_replace_callback('/'.$pattern.'/s', 'do_shortcode_tag', $content);
     150        $pattern = '(.?)\[(\w+?)\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?(.?)';
     151        return preg_replace_callback('/'.$pattern.'/s', 'escape_shortcode', $content);
    152152}
    153153
    154154/**
     155 * Escapes shortcodes.
     156 *
     157 * Because of the way 'embed' is implemented, shortcodes are escaped only during
     158 * the second pass when all shortcodes are added to the shortcode_tags array.
     159 *
     160 * If a shortcode is not active its hook is not called.
     161 * @see get_shortcode_regex for details of the match array contents.
     162 *
     163 * @since 3.1
     164 * @uses $shortcode_tags
     165 *
     166 * @param array $m Regular expression match array.
     167 * @return string The shortcode either escaped, unchanged or modified by its hook.
     168 */
     169function escape_shortcode($m){
     170        global $shortcode_tags;
     171
     172        if( '[' == $m[1]  && ']' == $m[6] ){
     173                //HACK! If this is the first pass of the do_shortcode() does not escape.
     174                if( ! empty( $shortcode_tags['gallery'] ) )
     175                        return substr( $m[0], 1, -1 );
     176                else
     177                        return $m[0];
     178        }
     179
     180        if( ! empty( $shortcode_tags[$m[2]] ) )
     181                return do_shortcode_tag($m);
     182        else
     183                return $m[0];   
     184}
     185
     186/**
    155187 * Retrieve the shortcode regular expression for searching.
    156188 *
    157189 * The regular expression combines the shortcode tags in the regular expression
     
    193225function do_shortcode_tag( $m ) {
    194226        global $shortcode_tags;
    195227
    196         // allow [[foo]] syntax for escaping a tag
    197         if ( $m[1] == '[' && $m[6] == ']' ) {
    198                 return substr($m[0], 1, -1);
    199         }
    200 
    201228        $tag = $m[2];
    202229        $attr = shortcode_parse_atts( $m[3] );
    203230
     
    295322
    296323add_filter('the_content', 'do_shortcode', 11); // AFTER wpautop()
    297324
    298 ?>
    299  No newline at end of file
     325?>