Save wp_editor() content as option

I’m having some troubles with a extra feature i’m writing for my theme.

The admin should be able to make some special posts, those posts are stored as an option. The options are atored as an array and WP makes it’s own json for arrays.

Read More

So, the user has a wp_editor(), and the array stored looks something like this:

array(
    'title' => 'My title',
    'content' => 'Look at my cat! <img src="mycat.jpg" />', //Generated by wp-editor
    'signature' => 'My name'
);

The thing is, when an image is added to this content, the image string is quite badly escaped. When i’m trying to get this content i get it as

<img src=""mycat.jpg"" />

instead of

<img src="mycat.jpg" />

How can i store content like this in the wp-options table so i can get it right when i try to get the content?

Related posts

1 comment

  1. If you just want to get rid of the characters in the string that’s returned, you can use PHP’s stripslashes():

    $content = stripslashes( $content );
    

    I’d recommend doing this on output rather than on input; WordPress adds the slashes as it sanitizes your data on insert, per update_option()‘s Codex page,

    The $option (option name) value is escaped with $wpdb->escape before the INSERT statement.

    See Data Validation for way more information.

Comments are closed.