WordPress.org

Make WordPress Core

Ticket #18558: 18558.diff

File 18558.diff, 3.4 KB (added by aaroncampbell, 10 years ago)
  • wp-includes/media.php

     
    10611061         * @return string Content with shortcode parsed
    10621062         */
    10631063        function run_shortcode( $content ) {
    1064                 global $shortcode_tags;
    1065 
    1066                 // Back up current registered shortcodes and clear them all out
    1067                 $orig_shortcode_tags = $shortcode_tags;
    1068                 remove_all_shortcodes();
    1069 
    10701064                add_shortcode( 'embed', array(&$this, 'shortcode') );
    10711065
    10721066                // Do the shortcode (only the [embed] one is registered)
    1073                 $content = do_shortcode( $content );
     1067                $content = do_shortcode( $content, 'embed' );
    10741068
    1075                 // Put the original shortcodes back
    1076                 $shortcode_tags = $orig_shortcode_tags;
    1077 
    10781069                return $content;
    10791070        }
    10801071
     
    14381429        return apply_filters( 'embed_googlevideo', '<embed type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docid=' . esc_attr($matches[2]) . '&amp;hl=en&amp;fs=true" style="width:' . esc_attr($width) . 'px;height:' . esc_attr($height) . 'px" allowFullScreen="true" allowScriptAccess="always" />', $matches, $attr, $url, $rawattr );
    14391430}
    14401431
    1441 ?>
    1442  No newline at end of file
     1432?>
  • wp-includes/shortcodes.php

     
    141141 * @param string $content Content to search for shortcodes
    142142 * @return string Content with shortcodes filtered out.
    143143 */
    144 function do_shortcode($content) {
     144function do_shortcode($content, $tag = null) {
    145145        global $shortcode_tags;
    146146
    147147        if (empty($shortcode_tags) || !is_array($shortcode_tags))
    148148                return $content;
    149149
    150         $pattern = get_shortcode_regex();
     150        $pattern = get_shortcode_regex( $tag );
    151151        return preg_replace_callback('/'.$pattern.'/s', 'do_shortcode_tag', $content);
    152152}
    153153
     
    168168 * @since 2.5
    169169 * @uses $shortcode_tags
    170170 *
     171 * @param string $tag Specify a single tag to process
     172 *
    171173 * @return string The shortcode search regular expression
    172174 */
    173 function get_shortcode_regex() {
    174         global $shortcode_tags;
    175         $tagnames = array_keys($shortcode_tags);
    176         $tagregexp = join( '|', array_map('preg_quote', $tagnames) );
     175function get_shortcode_regex( $tag = null ) {
     176        if ( empty( $tag ) )
     177                $tag = '[^\s\]]+';
     178        else
     179                $tag = preg_quote( $tag );
    177180
    178181        // WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcodes()
    179         return '(.?)\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?(.?)';
     182        return '(.?)\[(' . $tag . ')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?(.?)';
    180183}
    181184
    182185/**
     
    201204        $tag = $m[2];
    202205        $attr = shortcode_parse_atts( $m[3] );
    203206
     207        if ( empty( $shortcode_tags[$tag] ) || ! is_callable( $shortcode_tags[$tag] ) )
     208                $shortcode_tags[$tag] = 'unregistered_shortcode';
     209
    204210        if ( isset( $m[5] ) ) {
    205211                // enclosing tag - extra parameter
    206212                return $m[1] . call_user_func( $shortcode_tags[$tag], $attr, $m[5], $tag ) . $m[6];
     
    295301
    296302add_filter('the_content', 'do_shortcode', 11); // AFTER wpautop()
    297303
    298 ?>
    299  No newline at end of file
     304/**
     305 * Function used to process any unregistered shortcodes
     306 *
     307 * @param array $atts Attributes from shortcode - Unused
     308 * @param string $content Content of shortcode
     309 *
     310 * @return string Content of shortcode
     311 */
     312function unregistered_shortcode( $atts = null, $content = null ) {
     313        return (string) $content;
     314}
     315?>