How to save JavaScript and HTML in options without auto escaping?

And I thought I knew Wordpress well. Now it seems that update_option () automatically resets the code. If I want to save some Javascript or HTML code in options, this behavior makes the code unusable.

I refuse to do str_replace on the return value in order to filter out every backslash. There must 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 the form is submitted (essentially):

update_option('option', serialize($_POST));

Any ideas?

: , PHP stripslashes(), script, htmlentities (stripslashes()) , , , , .

+3
2

, update_option() .

. , 750 wp-settings.php, WP add_magic_quotes().

, , !

- WordPress , stripslashes GET POST ..

+2

@TheDeadMedic stripslashes, :

echo stripslashes(get_option( 'option' ));
+2

Source: https://habr.com/ru/post/1747611/


All Articles