Why is wp_editor in Wordpress passing line breaks as "\n" not as "<br>" or "<p>"?
I'm writing a plugin that uses its own database tables (created and managed with dbDelta and wpdb). One of the fields is a rich-text area field. I am using wp_editor to create it. I create the following:
- Hit "bold" and type "First Line"
- Hit return (to move to next line) and type "Second line"
This appears correctly inside the textarea (it's correct after I type it, it's incorrect when I reload after saving). However, when I save it, it shows in the database as:
<strong>First Line</strong> Second Line
But it should be:
<strong>First Line</strong><br>Second Line
Why is it doing this? How do I make it pass my code line breaks as HTML line breaks?
I instantiate it like this:
wp_editor( $myContent, "myField", array( "media_buttons" => false, "textarea_rows" => 5, "quicktags" => false ) );
This is default behavior.
p and br tags are not added to the editor. They are used with the visual editor (for display), but when you save or switch to text, they are replaced with regular line breaks.
Single line breaks become a br, double line breaks will start a p.
Linebreak to element conversion is done when the content is displayed, using the_content filter (more specifically, with wpautop).