shortcode_parse_atts

Retrieve all attributes from the shortcodes tag.

Description

(array|string) shortcode_parse_atts( (string) $text ); 

The attributes list has the attribute name as the key and the value of the attribute as the value in the key/value pair. This allows for easier retrieval of the attributes, since all attributes have to be known.

Returns (array|string)

List of attribute values. Returns empty array if trim( $text ) == '""'. Returns empty string if trim( $text ) == ''. All other matches are checked for not empty().

Parameters (1)

0. $text (string)
The text.

Usage

  1. if ( !function_exists( 'shortcode_parse_atts' ) ) { 
  2. require_once ABSPATH . WPINC . '/shortcodes.php'; 
  3.  
  4. // The text. 
  5. $text = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = shortcode_parse_atts($text); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/shortcodes.php  
  1. function shortcode_parse_atts($text) { 
  2. $atts = array(); 
  3. $pattern = get_shortcode_atts_regex(); 
  4. $text = preg_replace("/[\x{00a0}\x{200b}]+/u", " ", $text); 
  5. if ( preg_match_all($pattern, $text, $match, PREG_SET_ORDER) ) { 
  6. foreach ($match as $m) { 
  7. if (!empty($m[1])) 
  8. $atts[strtolower($m[1])] = stripcslashes($m[2]); 
  9. elseif (!empty($m[3])) 
  10. $atts[strtolower($m[3])] = stripcslashes($m[4]); 
  11. elseif (!empty($m[5])) 
  12. $atts[strtolower($m[5])] = stripcslashes($m[6]); 
  13. elseif (isset($m[7]) && strlen($m[7])) 
  14. $atts[] = stripcslashes($m[7]); 
  15. elseif (isset($m[8])) 
  16. $atts[] = stripcslashes($m[8]); 
  17.  
  18. // Reject any unclosed HTML elements 
  19. foreach( $atts as &$value ) { 
  20. if ( false !== strpos( $value, '<' ) ) { 
  21. if ( 1 !== preg_match( '/^[^<]*+(?:<[^>]*+>[^<]*+)*+$/', $value ) ) { 
  22. $value = ''; 
  23. } else { 
  24. $atts = ltrim($text); 
  25. return $atts;