wp_kses_split()
Searches for HTML tags, no matter how malformed.
It also matches stray > characters.
No Hooks.
Returns
String. Content with fixed HTML tags
Usage
wp_kses_split( $content, $allowed_html, $allowed_protocols );
- $content(string) (required)
- Content to filter.
- $allowed_html(array[]|string) (required)
- An array of allowed HTML elements and attributes, or a context name such as
'post'. See wp_kses_allowed_html() for the list of accepted context names. - $allowed_protocols(string[]) (required)
- Array of allowed URL protocols.
Notes
- Global. Array[]|String.
$pass_allowed_htmlAn array of allowed HTML elements and attributes, or a context name such as'post'. - Global. String[].
$pass_allowed_protocolsArray of allowed URL protocols.
Changelog
| Since 1.0.0 | Introduced. |
| Since 6.6.0 | Recognize additional forms of invalid HTML which convert into comments. |
wp_kses_split() wp kses split code WP 7.0
function wp_kses_split( $content, $allowed_html, $allowed_protocols ) {
global $pass_allowed_html, $pass_allowed_protocols;
$pass_allowed_html = $allowed_html;
$pass_allowed_protocols = $allowed_protocols;
$token_pattern = <<<REGEX
~
( # Detect comments of various flavors before attempting to find tags.
(<!--.*?(-->|$)) # - Normative HTML comments.
|
</[^a-zA-Z][^>]*> # - Closing tags with invalid tag names.
|
<![^>]*> # - Invalid markup declaration nodes. Not all invalid nodes
# are matched so as to avoid breaking legacy behaviors.
)
|
(<[^>]*(>|$)|>) # Tag-like spans of text.
~x
REGEX;
return preg_replace_callback( $token_pattern, '_wp_kses_split_callback', $content );
}