I have a wp_editor(); on my plugin settings page.

I also have enabled the "Font Size" drop down in TinyMCE.

After highlighting text in the wp_editor(); and selecting a font size from the editor's drop down menu, the font size is adjusted appropriately (directly in the editor).

However, after saving my plugin settings using update_option(); and the plugin settings page reloads... The <span style="font-size: 18px;">highlighted text</span> is removed, leaving me with only "highlighted text" without span tags wrapping it to adjust the font size.

I tried investigating the wp_editor(); code, along with the add_option(); / update_option(); code, to see if maybe there was some sort of stripping/sanitization going on.

Any clue why a wp_editor(); span tag would be removed while saving it's contents to an option?

Side note: It seems like only the span tags are being stripped for some reason. I just tried using underline, and that was removed as well.


The Problem

This turned out to be a common case of needing to use stripslashes();.

How did I figure this out?

I logged into phpMyAdmin, navigated to the options table, found my option name, and edited it.

Here's what I discovered...

s:11:"description";s:90:"<span style=\"text-decoration: underline;\">This is supposed to be underlined text.</span>";

So obviously my plugin is working. It's saving stuff properly. The text I entered into the wp_editor(); is there, and the appropriate HTML is wrapping my text as well.

Notice the slashes that have been added automatically. This is what was causing the problem when outputting the contents from the wp_editor(); which were saved in my plugin option.

Simple Solution

  1. Use stripslashes(); after retrieving your option data before you output it.
  2. This should be done on output and not on input.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.