How save JavaScript and HTML in option without it being auto-escaped?
Posted
by bobsoap
on Stack Overflow
See other posts from Stack Overflow
or by bobsoap
Published on 2010-05-28T19:48:54Z
Indexed on
2010/05/28
19:52 UTC
Read the original article
Hit count: 173
Wordpress
And there I thought I knew Wordpress well. It now seems that update_option() auto-escapes code. If I want to save some Javascript or HTML code in an option, this behavior renders the code unusable.
I refuse to do a str_replace on the returned value to filter out every backslash. There has to be a better way.
Here's the PHP for the text box to enter some code:
$option = unserialize(get_option('option'));
<textarea name="option[box]"><?php echo $option['box']; ?></textarea>
This is what happens after submitting the form (in essence):
update_option('option', serialize($_POST));
Any ideas?
© Stack Overflow or respective owner