wp_kses_split() WordPress Function

The wp_kses_split() function is used to split a string of HTML into an array of elements. This function is useful for making sure that only valid HTML elements are included in a string.

wp_kses_split( string $string, array[]|string $allowed_html, string[] $allowed_protocols ) #

Searches for HTML tags, no matter how malformed.


Description

It also matches stray > characters.


Top ↑

Parameters

$string

(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.


Top ↑

Return

(string) Content with fixed HTML tags


Top ↑

Source

File: wp-includes/kses.php

function wp_kses_split( $string, $allowed_html, $allowed_protocols ) {
	global $pass_allowed_html, $pass_allowed_protocols;

	$pass_allowed_html      = $allowed_html;
	$pass_allowed_protocols = $allowed_protocols;

	return preg_replace_callback( '%(<!--.*?(-->|$))|(<[^>]*(>|$)|>)%', '_wp_kses_split_callback', $string );
}


Top ↑

Changelog

Changelog
VersionDescription
1.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.