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。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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;
}
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; }
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
檢視更多 >