Make WordPress Core

Ticket #34092: 34092.2.diff

File 34092.2.diff, 2.1 KB (added by miqrogroove, 9 years ago)

Skip enclosure parsing with a strpos check for only one enclosure.

  • src/wp-includes/shortcodes.php

     
    305305
    306306        if ( isset( $m[5] ) ) {
    307307                // enclosing tag - extra parameter
    308                 return $m[1] . call_user_func( $shortcode_tags[$tag], $attr, $m[5], $tag ) . $m[6];
     308                if ( false === strpos( $m[5], "=]" ) ) {
     309                        $content = $m[5];
     310                } else {
     311                        $encl = shortcode_parse_enclosures( $m[5], $tag );
     312                        $content = array_shift( $encl );
     313                        $attr = array_merge( $attr, $encl );
     314                }
    309315        } else {
    310316                // self-closing tag
    311                 return $m[1] . call_user_func( $shortcode_tags[$tag], $attr, null,  $tag ) . $m[6];
     317                $content = null;
    312318        }
     319
     320        return $m[1] . call_user_func( $shortcode_tags[$tag], $attr, $content, $tag ) . $m[6];
    313321}
    314322
    315323/**
     
    478486}
    479487
    480488/**
     489 * Split up multiple enclosures into a list of attributes.
     490 *
     491 * @since 4.4.0
     492 *
     493 * @param string $input The enclosed content, including any attribute delimiters.
     494 * @param string $tag The name of the parent shortcode.
     495 * @return array List of attributes and their value, where the first item is the primary content.
     496 */
     497function shortcode_parse_enclosures( $input, $tag ) {
     498        $tag = preg_quote( $tag );
     499
     500        // Regex group arranged so that we split on the delimiters, but then only capture the name portion. :)
     501        $textarr = preg_split( "/\[$tag:([^=]*)=\]/", $input, -1, PREG_SPLIT_DELIM_CAPTURE );
     502       
     503        // Check for multiple enclosures.
     504        $c = count( $textarr );
     505        if ( 1 == $c ) {
     506                return $textarr;
     507        }
     508       
     509        // List multiple enclosures, starting with the primary content.
     510        $encl = array( $textarr[0] );
     511        for ( $i = 1; $i < $c; $i += 2 ) {
     512                // Now $i is the name's index and $i+1 is the value's index.
     513                if ( ! empty( $textarr[ $i ] ) ) {
     514                        $encl[ strtolower( $textarr[ $i ] ) ] = $textarr[ $i + 1 ];
     515                } else {
     516                        $encl[] = $textarr[ $i + 1 ];
     517                }
     518        }
     519        return $encl;
     520}
     521
     522/**
    481523 * Combine user attributes with known attributes and fill in defaults when needed.
    482524 *
    483525 * The pairs should be considered to be all of the attributes which are