Make WordPress Core

Ticket #34092: 34092.diff

File 34092.diff, 2.0 KB (added by miqrogroove, 9 years ago)
  • 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                $encl = shortcode_parse_enclosures( $m[5], $tag );
     309                $content = array_shift( $encl );
     310                $attr = array_merge( $attr, $encl );
    309311        } else {
    310312                // self-closing tag
    311                 return $m[1] . call_user_func( $shortcode_tags[$tag], $attr, null,  $tag ) . $m[6];
     313                $content = null;
    312314        }
     315
     316        return $m[1] . call_user_func( $shortcode_tags[$tag], $attr, $content, $tag ) . $m[6];
    313317}
    314318
    315319/**
     
    478482}
    479483
    480484/**
     485 * Split up multiple enclosures into a list of attributes.
     486 *
     487 * @since 4.4.0
     488 *
     489 * @param string $input The enclosed content, including any attribute delimiters.
     490 * @param string $tag The name of the parent shortcode.
     491 * @return array List of attributes and their value, where the first item is the primary content.
     492 */
     493function shortcode_parse_enclosures( $input, $tag ) {
     494        $tag = preg_quote( $tag );
     495
     496        // Regex group arranged so that we split on the delimeters, but then only capture the name portion. :)
     497        $textarr = preg_split( "/\[$tag:([^=]*)=\]/", $input, -1, PREG_SPLIT_DELIM_CAPTURE );
     498       
     499        // Check for multiple enclosures.
     500        $c = count( $textarr );
     501        if ( 1 == $c ) {
     502                return $textarr;
     503        }
     504       
     505        // List multiple enclosures, starting with the primary content.
     506        $encl = array( $textarr[0] );
     507        for ( $i = 1; $i < $c; $i += 2 ) {
     508                // Now $i is the name's index and $i+1 is the value's index.
     509                if ( ! empty( $textarr[ $i ] ) ) {
     510                        $encl[ strtolower( $textarr[ $i ] ) ] = $textarr[ $i + 1 ];
     511                } else {
     512                        $encl[] = $textarr[ $i + 1 ];
     513                }
     514        }
     515        return $encl;
     516}
     517
     518/**
    481519 * Combine user attributes with known attributes and fill in defaults when needed.
    482520 *
    483521 * The pairs should be considered to be all of the attributes which are