Advertisements

sanitize_html_class

Definition:
function sanitize_html_class( $class, $fallback = '' ) {}

Santizes a html classname to ensure it only contains valid characters
Strips the string down to A-Z,a-z,0-9,_,-. If this results in an empty string then it will return the alternative value supplied.

Parameters

  • string $class: The classname to be sanitized
  • string $fallback: Optional. The value to return if the sanitization end’s up as an empty string. Defaults to an empty string.

Return values

returns:The sanitized value

Defined filters

  • sanitize_html_class
    apply_filters( 'sanitize_html_class', $sanitized, $class, $fallback )

Source code

function sanitize_html_class( $class, $fallback = '' ) {

	//Strip out any % encoded octets

	$sanitized = preg_replace( '|%[a-fA-F0-9][a-fA-F0-9]|', '', $class );



	//Limit to A-Z,a-z,0-9,_,-

	$sanitized = preg_replace( '/[^A-Za-z0-9_-]/', '', $sanitized );



	if ( '' == $sanitized )

		$sanitized = $fallback;



	return apply_filters( 'sanitize_html_class', $sanitized, $class, $fallback );

}

2773

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: