Opened 10 years ago
Closed 7 years ago
#34226 closed enhancement (fixed)
Add 'widget_display_callback' filter to the_widget()
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 5.3 | Priority: | normal |
| Severity: | normal | Version: | 4.3.1 |
| Component: | Widgets | Keywords: | has-patch |
| Focuses: | template | Cc: |
Description
When a widget is output through a registered sidebar it passes through the 'widget_display_callback' filter (see 'display_callback' in 'wp-includes/widgets.php', allowing for short-circuiting. This is not the case when 'the_widget' is called, however. This patch simply adds the same feature to that function.
The reason I came across this is because I am using the Display Widgets plugin to hide widgets under certain circumstances. It hooks into 'widget_display_callback', runs some logic, and returns false if it should not appear. Using 'the_widget' in a template file, I noticed that the widget still appeared.
It seems logical to me that any time a widget is displayed, it should go through this filter.
Thanks for the ticket and welcome!
This seems like a good idea to me - my only hesitation would be backwards compat. Getting some unit tests on this to confirm that the patch doesn't break anything would go a long way.
The 2nd $widget_obj in the patch doesn't match the doc block as well.