Changeset 42343 for trunk/src/wp-includes/shortcodes.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/shortcodes.php
r42249 r42343 89 89 * @param string $tag Shortcode tag to remove hook for. 90 90 */ 91 function remove_shortcode( $tag) {92 global $shortcode_tags; 93 94 unset( $shortcode_tags[$tag]);91 function remove_shortcode( $tag ) { 92 global $shortcode_tags; 93 94 unset( $shortcode_tags[ $tag ] ); 95 95 } 96 96 … … 145 145 if ( shortcode_exists( $tag ) ) { 146 146 preg_match_all( '/' . get_shortcode_regex() . '/', $content, $matches, PREG_SET_ORDER ); 147 if ( empty( $matches ) ) 147 if ( empty( $matches ) ) { 148 148 return false; 149 } 149 150 150 151 foreach ( $matches as $shortcode ) { … … 181 182 } 182 183 183 if ( empty($shortcode_tags) || !is_array($shortcode_tags))184 if ( empty( $shortcode_tags ) || ! is_array( $shortcode_tags ) ) { 184 185 return $content; 186 } 185 187 186 188 // Find all registered tag names in $content. … … 232 234 $tagnames = array_keys( $shortcode_tags ); 233 235 } 234 $tagregexp = join( '|', array_map( 'preg_quote', $tagnames) );236 $tagregexp = join( '|', array_map( 'preg_quote', $tagnames ) ); 235 237 236 238 // WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcode_tag() … … 272 274 /** 273 275 * Regular Expression callable for do_shortcode() for calling shortcode hook. 276 * 274 277 * @see get_shortcode_regex for details of the match array contents. 275 278 * … … 287 290 // allow [[foo]] syntax for escaping a tag 288 291 if ( $m[1] == '[' && $m[6] == ']' ) { 289 return substr( $m[0], 1, -1);290 } 291 292 $tag = $m[2];292 return substr( $m[0], 1, -1 ); 293 } 294 295 $tag = $m[2]; 293 296 $attr = shortcode_parse_atts( $m[3] ); 294 297 … … 352 355 function do_shortcodes_in_html_tags( $content, $ignore_html, $tagnames ) { 353 356 // Normalize entities in unfiltered HTML before adding placeholders. 354 $trans = array( '[' => '[', ']' => ']' ); 357 $trans = array( 358 '[' => '[', 359 ']' => ']', 360 ); 355 361 $content = strtr( $content, $trans ); 356 $trans = array( '[' => '[', ']' => ']' ); 362 $trans = array( 363 '[' => '[', 364 ']' => ']', 365 ); 357 366 358 367 $pattern = get_shortcode_regex( $tagnames ); … … 364 373 } 365 374 366 $noopen = false === strpos( $element, '[' );375 $noopen = false === strpos( $element, '[' ); 367 376 $noclose = false === strpos( $element, ']' ); 368 377 if ( $noopen || $noclose ) { … … 394 403 395 404 // Get element name 396 $front = array_shift( $attributes );397 $back = array_pop( $attributes );405 $front = array_shift( $attributes ); 406 $back = array_pop( $attributes ); 398 407 $matches = array(); 399 preg_match( '%[a-zA-Z0-9]+%', $front, $matches);408 preg_match( '%[a-zA-Z0-9]+%', $front, $matches ); 400 409 $elname = $matches[0]; 401 410 402 411 // Look for shortcodes in each attribute separately. 403 412 foreach ( $attributes as &$attr ) { 404 $open = strpos( $attr, '[' );413 $open = strpos( $attr, '[' ); 405 414 $close = strpos( $attr, ']' ); 406 415 if ( false === $open || false === $close ) { … … 418 427 // $attr like 'name = "[shortcode]"' or "name = '[shortcode]'" 419 428 // We do not know if $content was unfiltered. Assume KSES ran before shortcodes. 420 $count = 0;429 $count = 0; 421 430 $new_attr = preg_replace_callback( "/$pattern/", 'do_shortcode_tag', $attr, -1, $count ); 422 431 if ( $count > 0 ) { … … 450 459 */ 451 460 function unescape_invalid_shortcodes( $content ) { 452 // Clean up entire string, avoids re-parsing HTML. 453 $trans = array( '[' => '[', ']' => ']' ); 454 $content = strtr( $content, $trans ); 455 456 return $content; 461 // Clean up entire string, avoids re-parsing HTML. 462 $trans = array( 463 '[' => '[', 464 ']' => ']', 465 ); 466 $content = strtr( $content, $trans ); 467 468 return $content; 457 469 } 458 470 … … 483 495 * All other matches are checked for not empty(). 484 496 */ 485 function shortcode_parse_atts( $text) {486 $atts = array();497 function shortcode_parse_atts( $text ) { 498 $atts = array(); 487 499 $pattern = get_shortcode_atts_regex(); 488 $text = preg_replace("/[\x{00a0}\x{200b}]+/u", " ", $text); 489 if ( preg_match_all($pattern, $text, $match, PREG_SET_ORDER) ) { 490 foreach ($match as $m) { 491 if (!empty($m[1])) 492 $atts[strtolower($m[1])] = stripcslashes($m[2]); 493 elseif (!empty($m[3])) 494 $atts[strtolower($m[3])] = stripcslashes($m[4]); 495 elseif (!empty($m[5])) 496 $atts[strtolower($m[5])] = stripcslashes($m[6]); 497 elseif (isset($m[7]) && strlen($m[7])) 498 $atts[] = stripcslashes($m[7]); 499 elseif (isset($m[8]) && strlen($m[8])) 500 $atts[] = stripcslashes($m[8]); 501 elseif (isset($m[9])) 502 $atts[] = stripcslashes($m[9]); 500 $text = preg_replace( "/[\x{00a0}\x{200b}]+/u", ' ', $text ); 501 if ( preg_match_all( $pattern, $text, $match, PREG_SET_ORDER ) ) { 502 foreach ( $match as $m ) { 503 if ( ! empty( $m[1] ) ) { 504 $atts[ strtolower( $m[1] ) ] = stripcslashes( $m[2] ); 505 } elseif ( ! empty( $m[3] ) ) { 506 $atts[ strtolower( $m[3] ) ] = stripcslashes( $m[4] ); 507 } elseif ( ! empty( $m[5] ) ) { 508 $atts[ strtolower( $m[5] ) ] = stripcslashes( $m[6] ); 509 } elseif ( isset( $m[7] ) && strlen( $m[7] ) ) { 510 $atts[] = stripcslashes( $m[7] ); 511 } elseif ( isset( $m[8] ) && strlen( $m[8] ) ) { 512 $atts[] = stripcslashes( $m[8] ); 513 } elseif ( isset( $m[9] ) ) { 514 $atts[] = stripcslashes( $m[9] ); 515 } 503 516 } 504 517 505 518 // Reject any unclosed HTML elements 506 foreach ( $atts as &$value ) {519 foreach ( $atts as &$value ) { 507 520 if ( false !== strpos( $value, '<' ) ) { 508 521 if ( 1 !== preg_match( '/^[^<]*+(?:<[^>]*+>[^<]*+)*+$/', $value ) ) { … … 512 525 } 513 526 } else { 514 $atts = ltrim( $text);527 $atts = ltrim( $text ); 515 528 } 516 529 return $atts; … … 535 548 */ 536 549 function shortcode_atts( $pairs, $atts, $shortcode = '' ) { 537 $atts = (array)$atts; 538 $out = array(); 539 foreach ($pairs as $name => $default) { 540 if ( array_key_exists($name, $atts) ) 541 $out[$name] = $atts[$name]; 542 else 543 $out[$name] = $default; 550 $atts = (array) $atts; 551 $out = array(); 552 foreach ( $pairs as $name => $default ) { 553 if ( array_key_exists( $name, $atts ) ) { 554 $out[ $name ] = $atts[ $name ]; 555 } else { 556 $out[ $name ] = $default; 557 } 544 558 } 545 559 /** … … 581 595 } 582 596 583 if ( empty($shortcode_tags) || !is_array($shortcode_tags))597 if ( empty( $shortcode_tags ) || ! is_array( $shortcode_tags ) ) { 584 598 return $content; 599 } 585 600 586 601 // Find all registered tag names in $content. … … 627 642 // allow [[foo]] syntax for escaping a tag 628 643 if ( $m[1] == '[' && $m[6] == ']' ) { 629 return substr( $m[0], 1, -1);644 return substr( $m[0], 1, -1 ); 630 645 } 631 646
Note: See TracChangeset
for help on using the changeset viewer.