I have written my first plugin, a shortcode plugin. I have read about wp_specialchars
and wp_specialchars_decode
but I’m not sure how to use them.
The plugin read a shortcode allowing some parameters and it inserts a script in the page html code. For example, [MYSHORTCODE TITLE="a short title"]
yields the following script code lines:
$html ="<script type="text/javascript">n"
$html.="var text="" . $par['title'] . "";n"
I’m not sure if here I need to write:
$html.="var text="" . wp_specialchars_decode($par['title']) . "";n"
or
$html.="var text="" . wp_specialchars($par['title']) . "";n"
or neither one nor the other.
The Codex description of these two functions:
According to
http://codex.wordpress.org/Function_Reference/wp_specialchars
You don’t want to have special characters in your html output, so you would rather not use
wp_specialchars_decode
for that.There is a special function called
esc_js()
that you should considerhttp://codex.wordpress.org/Function_Reference/esc_js
The source code for this function can be found here:
http://core.trac.wordpress.org/browser/tags/3.5.1/wp-includes/formatting.php#L2641
Here is a good data validation overview:
http://codex.wordpress.org/Data_Validation