wp_kses_hair_parse

Builds an attribute list from string containing attributes.

Description

(array|bool) wp_kses_hair_parse( (string) $attr ); 

Does not modify input. May return evil output. In case of unexpected input, returns false instead of stripping things.

Based on wp_kses_hair() but does not return a multi-dimensional array.

Returns (array|bool)

List of attributes found in $attr. Returns false on failure.

Parameters (1)

0. $attr (string)
Attribute list from HTML element to closing HTML element tag

Usage

  1. if ( !function_exists( 'wp_kses_hair_parse' ) ) { 
  2. require_once ABSPATH . WPINC . '/kses.php'; 
  3.  
  4. // Attribute list from HTML element to closing HTML element tag 
  5. $attr = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_kses_hair_parse($attr); 
  9.  

Defined (1)

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

/wp-includes/kses.php  
  1. function wp_kses_hair_parse( $attr ) { 
  2. if ( '' === $attr ) { 
  3. return array(); 
  4.  
  5. $regex = 
  6. '(?:' 
  7. . '[-a-zA-Z:]+' // Attribute name. 
  8. . '|' 
  9. . '\[\[?[^\[\]]+\]\]?' // Shortcode in the name position implies unfiltered_html. 
  10. . ')' 
  11. . '(?:' // Attribute value. 
  12. . '\s*=\s*' // All values begin with '=' 
  13. . '(?:' 
  14. . '"[^"]*"' // Double-quoted 
  15. . '|' 
  16. . "'[^']*'" // Single-quoted 
  17. . '|' 
  18. . '[^\s"\']+' // Non-quoted 
  19. . '(?:\s|$)' // Must have a space 
  20. . ')' 
  21. . '|' 
  22. . '(?:\s|$)' // If attribute has no value, space is required. 
  23. . ')' 
  24. . '\s*'; // Trailing space is optional except as mentioned above. 
  25.  
  26. // Although it is possible to reduce this procedure to a single regexp,  
  27. // we must run that regexp twice to get exactly the expected result. 
  28.  
  29. $validation = "%^($regex)+$%"; 
  30. $extraction = "%$regex%"; 
  31.  
  32. if ( 1 === preg_match( $validation, $attr ) ) { 
  33. preg_match_all( $extraction, $attr, $attrarr ); 
  34. return $attrarr[0]; 
  35. } else { 
  36. return false;