esc_js

Definition:
function esc_js( $text ) {}

Escape single quotes, htmlspecialchar " < > &, and fix line endings.
Escapes text strings for echoing in JS. It is intended to be used for inline JS (in a tag attribute, for example onclick="…"). Note that the strings have to be in single quotes. The filter ‘js_escape’ is also applied here.

Parameters

  • string $text: The text to be escaped.

Return values

returns:Escaped text.

Defined filters

  • js_escape
    apply_filters( 'js_escape', $safe_text, $text )

Source code

function esc_js( $text ) {

	$safe_text = wp_check_invalid_utf8( $text );

	$safe_text = _wp_specialchars( $safe_text, ENT_COMPAT );

	$safe_text = preg_replace( '/&#(x)?0*(?(1)27|39);?/i', "'", stripslashes( $safe_text ) );

	$safe_text = str_replace( "\r", '', $safe_text );

	$safe_text = str_replace( "\n", '\\n', addslashes( $safe_text ) );

	return apply_filters( 'js_escape', $safe_text, $text );

}

1036

About these ads

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

Follow

Get every new post delivered to your Inbox.

Join 196 other followers

%d bloggers like this: