Automattic\WooCommerce\Internal\Utilities

HtmlSanitizer::sanitize()publicWC 1.0

Sanitizes the HTML according to the provided rules.

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

No Hooks.

Return

String.

Usage

$HtmlSanitizer = new HtmlSanitizer();
$HtmlSanitizer->sanitize( $html, $sanitizer_rules ): string;
$html(string) (required)
HTML string to be sanitized.
$sanitizer_rules(array)

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

Default: self::LOW_HTML_BALANCED_TAGS_NO_LINKS

  • pre_processors(array)
    Callbacks to run before invoking wp_kses().

  • wp_kses_rules(array)
    Element names and attributes to allow, per wp_kses().

Notes

Code of HtmlSanitizer::sanitize() WC 7.1.0

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