| 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 | */ |
| 497 | function 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 | /** |