Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support shortcode expansion in the HTML code widget #83

Closed
bobbingwide opened this issue Jul 21, 2017 · 1 comment
Closed

Support shortcode expansion in the HTML code widget #83

bobbingwide opened this issue Jul 21, 2017 · 1 comment
Assignees

Comments

@bobbingwide
Copy link
Owner

bobbingwide commented Jul 21, 2017

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
Copy link
Owner Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant