filter_block_content

函数
filter_block_content ( $text, $allowed_html = 'post', $allowed_protocols = array() )
参数
  • (string) $text Text that may contain block content.
    Required:
  • (array[]|string) $allowed_html Optional. 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. Default 'post'.
    Required:
    Default: 'post'
  • (string[]) $allowed_protocols Optional. Array of allowed URL protocols. Defaults to the result of wp_allowed_protocols().
    Required:
    Default: array()
返回值
  • (string) The filtered and sanitized content result.
定义位置
相关方法
filter_block_ksesregister_block_core_post_contentregister_block_core_patternregister_block_typewp_filter_out_block_nodes
引入
5.3.1
弃用
-

filter_block_content – 这个过滤器用于在渲染前修改一个块的内容。它接受块的内容和块的类型作为其参数。

过滤和净化区块内容,从解析的区块属性值中删除不允许的HTML。

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

常见问题

FAQs
查看更多 >