Changeset 34747 for trunk/src/wp-includes/shortcodes.php
- Timestamp:
- 10/01/2015 06:04:13 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/shortcodes.php
r34745 r34747 209 209 return $content; 210 210 211 $tagnames = array_keys($shortcode_tags); 212 $tagregexp = join( '|', array_map('preg_quote', $tagnames) ); 213 $pattern = "/\\[($tagregexp)/s"; 214 215 if ( 1 !== preg_match( $pattern, $content ) ) { 216 // Avoids parsing HTML when there are no shortcodes or embeds anyway. 211 // Find all registered tag names in $content. 212 preg_match_all( '@\[([^<>&/\[\]\x00-\x20]++)@', $content, $matches ); 213 $tagnames = array_intersect( array_keys( $shortcode_tags ), $matches[1] ); 214 215 if ( empty( $tagnames ) ) { 217 216 return $content; 218 217 } 219 218 220 $content = do_shortcodes_in_html_tags( $content, $ignore_html );221 222 $pattern = get_shortcode_regex( );219 $content = do_shortcodes_in_html_tags( $content, $ignore_html, $tagnames ); 220 221 $pattern = get_shortcode_regex( $tagnames ); 223 222 $content = preg_replace_callback( "/$pattern/s", 'do_shortcode_tag', $content ); 224 223 … … 248 247 * @global array $shortcode_tags 249 248 * 249 * @param array $tagnames List of shortcodes to find. Optional. Defaults to all registered shortcodes. 250 250 * @return string The shortcode search regular expression 251 251 */ 252 function get_shortcode_regex() { 253 global $shortcode_tags; 254 $tagnames = array_keys($shortcode_tags); 252 function get_shortcode_regex( $tagnames = null ) { 253 global $shortcode_tags; 254 255 if ( empty( $tagnames ) ) { 256 $tagnames = array_keys( $shortcode_tags ); 257 } 255 258 $tagregexp = join( '|', array_map('preg_quote', $tagnames) ); 256 259 … … 338 341 * @param string $content Content to search for shortcodes 339 342 * @param bool $ignore_html When true, all square braces inside elements will be encoded. 343 * @param array $tagnames List of shortcodes to find. 340 344 * @return string Content with shortcodes filtered out. 341 345 */ 342 function do_shortcodes_in_html_tags( $content, $ignore_html ) {346 function do_shortcodes_in_html_tags( $content, $ignore_html, $tagnames ) { 343 347 // Normalize entities in unfiltered HTML before adding placeholders. 344 348 $trans = array( '[' => '[', ']' => ']' ); … … 346 350 $trans = array( '[' => '[', ']' => ']' ); 347 351 348 $pattern = get_shortcode_regex( );352 $pattern = get_shortcode_regex( $tagnames ); 349 353 $textarr = wp_html_split( $content ); 350 354 … … 558 562 return $content; 559 563 560 $content = do_shortcodes_in_html_tags( $content, true ); 561 562 $pattern = get_shortcode_regex(); 564 // Find all registered tag names in $content. 565 preg_match_all( '@\[([^<>&/\[\]\x00-\x20]++)@', $content, $matches ); 566 $tagnames = array_intersect( array_keys( $shortcode_tags ), $matches[1] ); 567 568 if ( empty( $tagnames ) ) { 569 return $content; 570 } 571 572 $content = do_shortcodes_in_html_tags( $content, true, $tagnames ); 573 574 $pattern = get_shortcode_regex( $tagnames ); 563 575 $content = preg_replace_callback( "/$pattern/s", 'strip_shortcode_tag', $content ); 564 576
Note: See TracChangeset
for help on using the changeset viewer.