filter_block_content()

最后更新于:2021-11-26 04:06:22

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.

参数

$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()

响应

(string) The filtered and sanitized content result.

源文件

文件: gc-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;
}