Home / Widgets / Cusdtom WP escape
Duplicate Snippet

Embed Snippet on Your Site

Cusdtom WP escape

One major difficulty with passing WordPress org security reviews is escaping late. This function may help.

Code Preview
php
<?php
function my_plugin_kses( $html ) {        
        $kses_defaults = wp_kses_allowed_html( 'post' );
	$svg_args = array(
		'svg'    => array(
			'class'           => true,
			'aria-hidden'     => true,
			'aria-labelledby' => true,
			'role'            => true,
			'xmlns'           => true,
			'fill'            => true,
			'width'           => true,
			'height'          => true,
			'viewbox'         => true // <= Must be lower case!
		),
		'g'      => array( 'fill' => true ),
		'title'  => array( 'title' => true ),
		'path'   => array(
			'd'    => true,
			'fill' => true,
		),
		'form'   => array(
			'class' => true,
			'action' => true,
			'method' => true,
			'enctype' => true,
			'id' => true,
		),
		'input' =>
			array(
				'class' => true,
				'name'  => true,
				'type'  => true,
				'value' => true,
                                'selected' => true,
                                'required' => true,
			),
		'select' =>
			array(
				'class' => true,
				'name'  => true,
			),
		'option' =>
			array(
				'class' => true,
				'value' => true,
                                'selected' => true,
			),
	);
	$allowed_tags = array_merge( $kses_defaults, $svg_args );
	return wp_kses( $html, $allowed_tags );
}

Comments

Add a Comment