Created
October 29, 2016 20:48
-
-
Save ivorpad/6f229e85fcee53beca7acf8480b1c3d6 to your computer and use it in GitHub Desktop.
Grab all attributes for a given shortcode in a text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Grab all attributes for a given shortcode in a text | |
* | |
* @uses get_shortcode_regex() | |
* @uses shortcode_parse_atts() | |
* @param string $tag Shortcode tag | |
* @param string $text Text containing shortcodes | |
* @return array $out Array of attributes | |
*/ | |
// This function is to get attributes from [shortcode attr="val"] | |
// Usage: $get_title = inoic_get_child_sc_attr('shortcode tag', $content); | |
function prefix_get_child_sc_attr( $tag, $text ) { | |
preg_match_all( '/' . get_shortcode_regex() . '/s', $text, $matches ); | |
$out = array(); | |
if( isset( $matches[2] ) ) | |
{ | |
foreach( (array) $matches[2] as $key => $value ) | |
{ | |
if( $tag === $value ) | |
$out[] = shortcode_parse_atts( $matches[3][$key] ); | |
} | |
} | |
return $out; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment