filter_block_content( string $text, array[]|string $allowed_html = 'post', string[] $allowed_protocols = array() )

Filters and sanitizes block content to remove non-allowable HTML from parsed block attribute values.

Parameters

$text

(string) (Required) Text that may contain block content.

$allowed_html

(array[]|string) (Optional) An array of allowed HTML elements and attributes, or a context name such as 'post'.

Default value: 'post'

$allowed_protocols

(string[]) (Optional) Array of allowed URL protocols.

Default value: array()

Return

(string) The filtered and sanitized content result.

Source

File: wp-includes/blocks.php

function filter_block_content( $text, $allowed_html = 'post', $allowed_protocols = array() ) {
	$result = '';

	$blocks = parse_blocks( $text );
	foreach ( $blocks as $block ) {
		$block   = filter_block_kses( $block, $allowed_html, $allowed_protocols );
		$result .= serialize_block( $block );
	}

	return $result;
}

Changelog

Version Description
5.3.1 Introduced.

© 2003–2021 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/filter_block_content