wpseek.com
Outil de recherche WordPress pour les développeurs et auteurs de thèmes



filter_block_content › WordPress Function

Depuis5.3.1
Dépréciéen/a
filter_block_content ( $text, $allowed_html = 'post', $allowed_protocols = array() )
Paramètres: (3)
  • (string) $text Text that may contain block content.
    Requis: Oui
  • (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'.
    Requis: Non
    Défaut: 'post'
  • (string[]) $allowed_protocols Optional. Array of allowed URL protocols. Defaults to the result of wp_allowed_protocols().
    Requis: Non
    Défaut: array()
Retourne:
  • (string) The filtered and sanitized content result.
Défini(e) dans:
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 = '';

	if ( str_contains( $text, '<!--' ) && str_contains( $text, '--->' ) ) {
		$text = preg_replace_callback( '%<!--(.*?)--->%', '_filter_block_content_callback', $text );
	}

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

	return $result;
}