Ticket #33517: 33517.patch
| File 33517.patch, 3.3 KB (added by , 10 years ago) |
|---|
-
src/wp-includes/shortcodes.php
195 195 if (empty($shortcode_tags) || !is_array($shortcode_tags)) 196 196 return $content; 197 197 198 $tagnames = array_keys($shortcode_tags);199 $tagregexp = join( '|', array_map('preg_quote', $tagnames));200 $ pattern = "/\\[($tagregexp)/s";198 // Find all registered tag names in $content. 199 preg_match_all( '@\[([^\s\[\]/]++)@', $content, $matches ); 200 $tagnames = array_intersect( array_keys( $shortcode_tags ), $matches[1] ); 201 201 202 if ( 1 !== preg_match( $pattern, $content ) ) { 203 // Avoids parsing HTML when there are no shortcodes or embeds anyway. 202 if ( empty( $tagnames ) ) { 204 203 return $content; 205 204 } 206 205 207 $content = do_shortcodes_in_html_tags( $content, $ignore_html );206 $content = do_shortcodes_in_html_tags( $content, $ignore_html, $tagnames ); 208 207 209 $pattern = get_shortcode_regex( );208 $pattern = get_shortcode_regex( $tagnames ); 210 209 $content = preg_replace_callback( "/$pattern/s", 'do_shortcode_tag', $content ); 211 210 212 211 // Always restore square braces so we don't break things like <!--[if IE ]> … … 234 233 * 235 234 * @global array $shortcode_tags 236 235 * 236 * @param array $tagnames List of shortcodes to find. Optional. Defaults to all registered shortcodes. 237 237 * @return string The shortcode search regular expression 238 238 */ 239 function get_shortcode_regex( ) {239 function get_shortcode_regex( $tagnames = null ) { 240 240 global $shortcode_tags; 241 $tagnames = array_keys($shortcode_tags); 241 242 if ( empty( $tagnames ) ) { 243 $tagnames = array_keys( $shortcode_tags ); 244 } 242 245 $tagregexp = join( '|', array_map('preg_quote', $tagnames) ); 243 246 244 247 // WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcode_tag() … … 324 327 * 325 328 * @param string $content Content to search for shortcodes 326 329 * @param bool $ignore_html When true, all square braces inside elements will be encoded. 330 * @param array $tagnames List of shortcodes to find. 327 331 * @return string Content with shortcodes filtered out. 328 332 */ 329 function do_shortcodes_in_html_tags( $content, $ignore_html ) {333 function do_shortcodes_in_html_tags( $content, $ignore_html, $tagnames ) { 330 334 // Normalize entities in unfiltered HTML before adding placeholders. 331 335 $trans = array( '[' => '[', ']' => ']' ); 332 336 $content = strtr( $content, $trans ); 333 337 $trans = array( '[' => '[', ']' => ']' ); 334 338 335 $pattern = get_shortcode_regex( );339 $pattern = get_shortcode_regex( $tagnames ); 336 340 $textarr = wp_html_split( $content ); 337 341 338 342 foreach ( $textarr as &$element ) { … … 532 536 if (empty($shortcode_tags) || !is_array($shortcode_tags)) 533 537 return $content; 534 538 535 $content = do_shortcodes_in_html_tags( $content, true ); 539 // Find all registered tag names in $content. 540 preg_match_all( '@\[([^\s\[\]/]++)@', $content, $matches ); 541 $tagnames = array_intersect( array_keys( $shortcode_tags ), $matches[1] ); 536 542 537 $pattern = get_shortcode_regex(); 543 if ( empty( $tagnames ) ) { 544 return $content; 545 } 546 547 $content = do_shortcodes_in_html_tags( $content, true, $tagnames ); 548 549 $pattern = get_shortcode_regex( $tagnames ); 538 550 $content = preg_replace_callback( "/$pattern/s", 'strip_shortcode_tag', $content ); 539 551 540 552 // Always restore square braces so we don't break things like <!--[if IE ]>