I need an alternative function to use with textareas in meta boxes instead of esc_textarea.
The problem is that when I use this function with textarea’s it removes line breaks and paragraphs. Is there an alternative function that will keep the line breaks and paragraphs.
I have tried the validation reference page in the Codex but had no luck finding a function.
esc_textarea
shouldn’t strip out newlines — It’s just a thin wrapper aroundhtmlspecialchars
: http://core.trac.wordpress.org/browser/tags/3.3.2/wp-includes/formatting.php#L2536That said, there are lots of options. What do you want your users to do have the ability to post?
esc_html
will escape all special characters (just likeesc_textarea
).esc_attr(strip_tags($stuff));
is a favorite combination of mine.You should also have a look at the data validation page in the codex.
Sorry for the delay but this was the solution I used. Thanks for the feedback.
I think you can use
wpautop
beforeesc_textarea
, like this:Try this:
For me, the output is (but the content-type is
text/plain
):I suggest to you to set your content-type with ‘text/plain’ before.
If the content type is by default set to ‘text/html’, the result will be: