Is it possible to remove the filter from 4.8 text widget?

The new rich text widget that came with the 4.8 update seems to add a filter to widget’s content before outputting the data (probably the_content).

I just noticed that if i use a shortcode in the new text widget, it will mess the entire thing ( for example, it will replace the X letter with &#215; which is the HTML entity equivalent for × mark, add random <p>, etc.). The filter is added to the wp_options table under widget_text, like this:

a:2:{
    i:2;
    a:3:{
        s:5:"title";
        s:6:"Sample";
        s:4:"text";
        s:14:"[shortcode-here]";
        s:6:"filter";
        s:7:"content";
    }
    s:12:"_multiwidget";
    i:1;
}

Now if i replace the 5th and 6th values with this:

    s:1:" ";
    s:1:" ";

The filter is applied no more. If you already have a text widget added before updating to 4.8, there won’t be a problem. But the moment you click Save on the widget after you update to 4.8, the problem appears.

I don’t want to disable the filter entirely, since there might be other text widgets on the page.

Is it possible to detect the shortcodes and turn off the filter for them?

1 Answer
1

We now have a new filter widget_text_content introduced in 4.8 src, with the following default callbacks:

add_filter( 'widget_text_content', 'capital_P_dangit', 11 );
add_filter( 'widget_text_content', 'wptexturize'          );
add_filter( 'widget_text_content', 'convert_smilies',  20 );
add_filter( 'widget_text_content', 'wpautop'              );

that are applied if the filter settings, for the widget instance, is set to 'content'.

When you remove the filter settings by hand from the wp_options table, it seems to be reset during the update method src.

See trac ticket #35243 for more info.

Leave a Comment