Last active
September 17, 2018 13:57
-
-
Save richardblondet/e0e99621b5cf06e83bf884509d7b0b6b to your computer and use it in GitHub Desktop.
Takes a shortcode and content and returns an array of the parsed attributes of given shortcode
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
/** | |
* Takes a shortcode and content and returns an array of the partsed attributes of given shortcode | |
* @param string $shortcode the shortcode in context | |
* @param string $content the content where shortcode is found | |
* @return bool|array FALSE if the given conditions are not met|ARRAY of key-values for the shortcode | |
* @author Richard Blondet <http://richardblondet.com/> | |
*/ | |
function parse_shortcodes_attributes( $shortcode, $content = '' ) { | |
if( empty( $content ) ) return FALSE; | |
$shortcode_atts = FALSE; | |
$pattern = get_shortcode_regex(); | |
if ( preg_match( "/$pattern/s", $content , $matches ) && array_key_exists( 2, $matches ) && in_array( $shortcode, $matches ) ) { | |
$shortcode_atts = shortcode_parse_atts( $matches[ 3 ] ); | |
} | |
return $shortcode_atts; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment