filter_block_kses_value()WP 5.3.1

Filters and sanitizes a parsed block attribute value to remove non-allowable HTML.

No Hooks.

Return

String[]|String. The filtered and sanitized result.

Usage

filter_block_kses_value( $value, $allowed_html, $allowed_protocols );
$value(string[]|string) (required)
The attribute value 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[])
Array of allowed URL protocols.
Default: result of wp_allowed_protocols()

Changelog

Since 5.3.1 Introduced.

filter_block_kses_value() code WP 6.5.2

function filter_block_kses_value( $value, $allowed_html, $allowed_protocols = array() ) {
	if ( is_array( $value ) ) {
		foreach ( $value as $key => $inner_value ) {
			$filtered_key   = filter_block_kses_value( $key, $allowed_html, $allowed_protocols );
			$filtered_value = filter_block_kses_value( $inner_value, $allowed_html, $allowed_protocols );

			if ( $filtered_key !== $key ) {
				unset( $value[ $key ] );
			}

			$value[ $filtered_key ] = $filtered_value;
		}
	} elseif ( is_string( $value ) ) {
		return wp_kses( $value, $allowed_html, $allowed_protocols );
	}

	return $value;
}