A WordPress-centric search engine for devs and theme authors



filter_block_content ›

Since5.3.1
Deprecatedn/a
filter_block_content ( $text, $allowed_html = 'post', $allowed_protocols = array() )
Parameters: (3)
  • (string) text Text that may contain block content.
    Required: Yes
  • (array[]|string) allowed_html An array of allowed HTML elements and attributes, or a context name such as 'post'.
    Required: No
    Default: 'post'
  • (string[]) allowed_protocols Array of allowed URL protocols.
    Required: No
    Default: array()
Returns:
  • (string) The filtered and sanitized content result.
Defined at:
Codex:

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



Source

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;
}