wp_kses_split2

Callback for wp_kses_split for fixing malformed HTML tags.

Description

(string) wp_kses_split2( (string) $string, (array) $allowed_html, (array) $allowed_protocols ); 

This function does a lot of work. It rejects some very malformed things like <:::>. It returns an empty string, if the element isn't allowed (look ma, no strip_tags()!). Otherwise it splits the tag into an element and an attribute list.

After the tag is split into an element and an attribute list, it is run through another filter which will remove illegal attributes and once that is completed, will be returned.

Returns (string)

Fixed HTML element

Parameters (3)

0. $string (string)
Content to filter
1. $allowed_html (array)
Allowed HTML elements
2. $allowed_protocols (array)
Allowed protocols to keep

Usage

  1. if ( !function_exists( 'wp_kses_split2' ) ) { 
  2. require_once ABSPATH . WPINC . '/kses.php'; 
  3.  
  4. // Content to filter 
  5. $string = ''; 
  6.  
  7. // Allowed HTML elements 
  8. $allowed_html = array(); 
  9.  
  10. // Allowed protocols to keep 
  11. $allowed_protocols = array(); 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = wp_kses_split2($string, $allowed_html, $allowed_protocols); 
  15.  

Defined (1)

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

/wp-includes/kses.php  
  1. function wp_kses_split( $string, $allowed_html, $allowed_protocols ) { 
  2. global $pass_allowed_html, $pass_allowed_protocols; 
  3. $pass_allowed_html = $allowed_html; 
  4. $pass_allowed_protocols = $allowed_protocols; 
  5. return preg_replace_callback( '%(<!--.*?(-->|$))|(<[^>]*(>|$)|>)%', '_wp_kses_split_callback', $string ); 
  6.  
  7. /** 
  8. * Callback for wp_kses_split. 
  9. * @since 3.1.0 
  10. * @access private 
  11. * @global array $pass_allowed_html 
  12. * @global array $pass_allowed_protocols 
  13. * @return string 
  14. */ 
  15. function _wp_kses_split_callback( $match ) { 
  16. global $pass_allowed_html, $pass_allowed_protocols; 
  17. return wp_kses_split2( $match[0], $pass_allowed_html, $pass_allowed_protocols ); 
  18.  
  19. /** 
  20. * Callback for wp_kses_split for fixing malformed HTML tags. 
  21. * This function does a lot of work. It rejects some very malformed things like 
  22. * <:::>. It returns an empty string, if the element isn't allowed (look ma, no 
  23. * strip_tags()!). Otherwise it splits the tag into an element and an attribute 
  24. * list. 
  25. * After the tag is split into an element and an attribute list, it is run 
  26. * through another filter which will remove illegal attributes and once that is 
  27. * completed, will be returned. 
  28. * @access private 
  29. * @since 1.0.0 
  30. * @param string $string Content to filter 
  31. * @param array $allowed_html Allowed HTML elements 
  32. * @param array $allowed_protocols Allowed protocols to keep 
  33. * @return string Fixed HTML element