WP_Icons_Registry::sanitize_icon_contentprotectedWP 1.0

Sanitizes the icon SVG content.

Logic borrowed from twentytwenty.

Method of the class: WP_Icons_Registry{}

No Hooks.

Returns

String. The sanitized icon SVG content.

Usage

// protected - for code of main (parent) or child class
$result = $this->sanitize_icon_content( $icon_content );
$icon_content(string) (required)
The icon SVG content to sanitize.

Notes

  • See: twentytwenty_get_theme_svg

WP_Icons_Registry::sanitize_icon_content() code WP 7.0

protected function sanitize_icon_content( $icon_content ) {
	$allowed_tags = array(
		'svg'     => array(
			'class'       => true,
			'xmlns'       => true,
			'width'       => true,
			'height'      => true,
			'viewbox'     => true,
			'aria-hidden' => true,
			'role'        => true,
			'focusable'   => true,
		),
		'path'    => array(
			'fill'      => true,
			'fill-rule' => true,
			'd'         => true,
			'transform' => true,
		),
		'polygon' => array(
			'fill'      => true,
			'fill-rule' => true,
			'points'    => true,
			'transform' => true,
			'focusable' => true,
		),
	);
	return wp_kses( $icon_content, $allowed_tags );
}