WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#42547 closed defect (bug) (fixed)

Widgets: Nullify $post global in Custom HTML widget

Reported by: westonruter Owned by: westonruter
Milestone: 4.9 Priority: normal
Severity: normal Version: 4.9
Component: Widgets Keywords: has-patch commit dev-reviewed
Focuses: Cc:
PR Number:

Description

Handling of shortcodes was added to the Text widget in #10457. When shortcodes are processed in the Text widget, the global $post is nullified so that the shortcodes run in a consistent non-post context, since a widget can appear on any template even 404.

The Custom HTML widget was introduced in 4.8.1 as a replacement for legacy use of the Text widget as a place to paste arbitrary HTML. Plugins also added shortcode support on the widget_text filter, which the Custom HTML widget also applies for backwards compatibility. However, the $post nullification logic from the Text widget was not also implemented in the Custom HTML widget, so there's currently a situation where if you try using a shortcode in the Custom HTML widget it could get rendered whereas it wouldn't in the Text widget.

Change History (7)

#1 @westonruter
2 years ago

  • Keywords has-patch dev-feedback commit added; needs-patch removed

See patch on #10457, which will resolve this ticket as well.

This ticket was mentioned in Slack in #core by westonruter. View the logs.


2 years ago

This ticket was mentioned in Slack in #core by westonruter. View the logs.


2 years ago

#4 @joemcgill
2 years ago

  • Keywords dev-reviewed added; dev-feedback removed

Reiterating my +1 from #42548.

#5 @westonruter
2 years ago

  • Owner set to westonruter
  • Resolution set to fixed
  • Status changed from new to closed

In 42185:

Widgets: Set global $post to current queried object instead of nullifying when is_singular() while applying filters (and shortcodes) in Text widget and (via plugin) Custom HTML widget.

Also prevent [gallery] shortcode from dumping out every attachment on the site when a containing Text widget is shown on an archive template.

Props westonruter, bobbingwide, joemcgill for testing.
See #10457.
Fixes #42548, #42547 for trunk.

#6 @westonruter
2 years ago

In 42186:

Widgets: Set global $post to current queried object instead of nullifying when is_singular() while applying filters (and shortcodes) in Text widget and (via plugin) Custom HTML widget.

Also prevent [gallery] shortcode from dumping out every attachment on the site when a containing Text widget is shown on an archive template.

Props westonruter, bobbingwide, joemcgill for testing.
See #10457.
Fixes #42548, #42547 for 4.9.

#7 @johnbillion
2 years ago

  • Milestone changed from 4.9.1 to 4.9
Note: See TracTickets for help on using tickets.