#19411 closed defect (bug) (duplicate)
do_shortcode() runs before wpautop() in the text widget
Reported by: | nacin | Owned by: | |
---|---|---|---|
Milestone: | Priority: | high | |
Severity: | major | Version: | 3.3 |
Component: | General | Keywords: | has-patch dev-feedback |
Focuses: | Cc: |
Description
Follow-up from #10457, where do_shortcode was added to widget_text.
wpautop() is conditionally run against widget text after the widget_text filter fires. This means that do_shortcode() will run before wpautop(), and it's possible for shortcode_unautop() to run when wpautop() isn't run at all.
Coming up with a patch with a suggested solution.
Attachments (5)
Change History (11)
#2
@
13 years ago
I don't think this will work after the first text widget with filters disabled because as far as I remember we process filters in the order they were added and therefore the following happens:
- First widget with filters enabled - wpautop, shortcode_unautop, do_shortcode
- Second widget with filters disabled - do_shortcode
- Third widget with filters enabled - do_shortcode, wpautop, shortcode_unautop
This is because when we re-add the filters they will end up behind do_shortcode in ordering.
Alternative solutions to address this:
- Run wpautop before the widget_text filter - screws over anyone that was expecting it to run afterwards
- Also do the add remove dance with the do_shortcode filtering in the post widget_text add_filter second - so remove it, add the other two back and then add it again.
#3
@
13 years ago
Couldn't we just use a has_filter check to see if we want to add do_shortcode, then add it to priority 11?
if ( ! has_filter( 'widget_text', 'do_shortcode' ) ) add_filter( 'widget_text', 'do_shortcode', 11 );
Then we're not undoing something that a plugin or theme is already doing, we're not running do_shortcode twice, and we're always running it after wpautop.
#4
@
13 years ago
westi: Ah, yes, that was the same mess I was trying to avoid.
I like aaroncampbell's ideas. There's also the opportunity to do a maybe_wpautop callback that accepts 2 parameters, thus receiving $instance, and thus being able to determine whether wpautop should be applied.
Example incoming.
@
13 years ago
Alternative also wraps shortcode_unautop(). Not sure if shortcode_unautop() can/should run without wpautop() in the picture.
#5
@
13 years ago
- Milestone 3.3 deleted
- Resolution set to duplicate
- Status changed from new to closed
Had an IRC discussion with westi. Too many problems with shortcodes in widgets. Closing this as a duplicate of #10457 and re-opening for a revert. Will summarize further problems there.
https://irclogs.wordpress.org/chanlog.php?channel=wordpress-dev&day=2011-12-02&sort=asc#m341059
19411.diff is based on two things I noticed while creating this patch:
In light of that, it seems like the best approach.