Automattic\WooCommerce\Internal\Utilities

HtmlSanitizer::sanitize()publicWC 1.0

Sanitizes the HTML according to the provided rules.

{} Это метод класса: HtmlSanitizer{}

Хуков нет.

Возвращает

Строку.

Использование

$HtmlSanitizer = new HtmlSanitizer();
$HtmlSanitizer->sanitize( $html, $sanitizer_rules ): string;
$html(строка) (обязательный)
HTML string to be sanitized.
$sanitizer_rules(массив)

Optional and defaults to self::TRIMMED_BALANCED_LOW_HTML_NO_LINKS. Otherwise, one or more of the following keys should be set.

По умолчанию: self::LOW_HTML_BALANCED_TAGS_NO_LINKS

  • pre_processors(массив)
    Callbacks to run before invoking wp_kses().

  • wp_kses_rules(массив)
    Element names and attributes to allow, per wp_kses().

Заметки

Код HtmlSanitizer::sanitize() WC 6.6.1

public function sanitize( string $html, array $sanitizer_rules = self::LOW_HTML_BALANCED_TAGS_NO_LINKS ): string {
	if ( isset( $sanitizer_rules['pre_processors'] ) && is_array( $sanitizer_rules['pre_processors'] ) ) {
		$html = $this->apply_string_callbacks( $sanitizer_rules['pre_processors'], $html );
	}

	// If no KSES rules are specified, assume all HTML should be stripped.
	$kses_rules = isset( $sanitizer_rules['wp_kses_rules'] ) && is_array( $sanitizer_rules['wp_kses_rules'] )
		? $sanitizer_rules['wp_kses_rules']
		: array();

	return wp_kses( $html, $kses_rules );
}