[wp-hackers] shortcode API > $content > TINY MCE filters

Xavier Faraudo i Gener wordpress at web-warlocks.net
Wed May 14 22:43:19 UTC 2014


Hello,

The filters for content are tricky, specially wptexturize and wpautop. 
(Which, if I don't remember it wrong, sets single line breaks to br tag, 
and doubles to p tag.) Removing them is IMHO a very bad idea, but 
setting them to another priority may be useful in some cases. You're 
risking conflicts with other author's plugins and shortcodes, though.

I've been toying with shortcode system for a bit now (doing things like 
the BBCode syntax of [code=value /] or nesting the very same shortcode, 
for instance, which actually are pretty easy things to do once you look 
at how shortcode atts are parsed). For your issue with "structured data" 
into shortcodes, I'd suggest to structure the params in a semantically 
meaningful way, using shortcodes for params in a similar way to object 
and param HTML tags, like this:

[complex_shortcode]
[complex_shortcode_param_1]value 1[/complex_shortcode_param_1]
[complex_shortcode_param_2]value 2[/complex_shortcode_param_2]
[/complex_shortcode]

Use then the param shortcodes to parse and *properly sanitize* values, 
store them in a global var (prefix it with underscore _ to show it's a 
private use var), and retrieve the values from the complex_shortcode 
function. Just make sure to do_shortcode *before* trying to access the 
global vars (otherwise, they won't be properly populated).

All this, yes, is a bit like saying that if you don't like how WP 
filters your values (something totally legit, BTW), filter them yourself 
with your favo(u)rite flavo(u)r :). That's what I do and works fine for 
me, but "your mileage may vary" :)

Note that using the params-shortcode technique, you are no longer 
constrained by order of params, may have empty/null params, &c. Which 
works great in combination with options to set defaults.

Also, please note that:

> (snip)
> When my shortcode $content has the above red text, it appears in the DB as
> follows;
> (/snip)

…are of little help when we're reading this list as plain text: we're 
effectively HTML color blind.


Best,

Xavier


-- 
Xavier Faraudo i Gener (the WordPress Web Warlock)


More information about the wp-hackers mailing list