bobbingwide / oik

OIK Information Kit
https://www.oik-plugins.com/oik-plugins/oik
GNU General Public License v2.0
2 stars 0 forks source link

Support shortcode expansion in the HTML code widget #83

Closed bobbingwide closed 4 years ago

bobbingwide commented 7 years ago

In WordPress 4.8 some changes were made to the Text widget logic to enable the Visual editor to be used. This effed up quite a few sites. A number of WordPress TRACs were raised and a number of new plugins developed to help deal with the situation. In WordPress 4.8.1, due 1st August 2017, there will be a new HTML widget. Since WordPress doesn't automatically support shortcode expansion in text widgets it seems reasonable that it might not automatically support shortcode expansion in HTML widgets.

Requirement

The requirement for oik shortcodes is that they should be expanded in HTML widgets.

Proposed solution

The current proposal ( 23 Jul 2017) for WordPress 4.8.1 is that the filters associated to widget_text be applied prior to any additional filters for widget_custom_html_content.

It should therefore NOT BE NECESSARY for the following to be added to bw_oik_add_shortcodes_loaded()

add_filter('widget_custom_html_content', 'do_shortcode' );

as this would invoke shortcode processing again.

We can make an improvement though. The balanceTags() function is only effective when the use_balanceTags option is set. Since WordPress 4.3, when the UI for this option was removed, the default for new installs is false. For installations created before 4.3, the option can still be set. There's no need to have it attached to widget_text if the option is not set so, while adjusting filter hook priorities, to ensure balanceTags is called before do_shortcode, we can test to see if it's needed at all.

remove_filter( "widget_text", "balanceTags", 10 );
if ( 1 == get_option( "use_balanceTags" ) ) {
  add_filter( 'widget_text', 'balanceTags', 8 ); 
}
add_filter( 'widget_text', 'do_shortcode' );

Testing requirement

We also need to make sure that wpautop doesn't break things.

bobbingwide commented 4 years ago

This solution works. Blocks.wp-a2z.org uses Custom HTML widgets in the footer. Footer 2 contains the [guts] shortcode - from oik-block - which shows the current WordPress and Gutenberg versions.