Make WordPress Core

Opened 3 years ago

Last modified 3 years ago

#53771 new enhancement

What about an equivalent of `is_active_widget()` for Widget Blocks ?

Reported by: imath's profile imath Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 5.8
Component: Widgets Keywords: has-patch needs-unit-tests
Focuses: Cc:

Description

This doesn't seem to exist in WordPress Core and I haven't found a ticket asking about this. (I hope I haven't missed one, sorry if I did).

is_active_widget() can't be used because all Block are added into the same Widget: WP_Widget_Block.

For BuddyPress when migrating our Legacy Widgets to Widget Blocks, I had 2 cases where some output wasn't made if a widget was active into a sidebar (Sitewide notice, and BP Primary Nav). To satisfy our need we are using this function to check if a block or a widget is active into a Sidebar Widgets.

I thought maybe it can be interested to have an equivalent of is_active_widget() into WordPress. I quickly put up a patch about it.

Attachments (1)

53771.patch (1.6 KB) - added by imath 3 years ago.

Download all attachments as: .zip

Change History (3)

@imath
3 years ago

#1 @TimothyBlynJacobs
3 years ago

  • Keywords needs-unit-tests added
  • Milestone changed from Awaiting Review to Future Release
  • Version set to 5.8

This makes a lot of sense to me to add. We'll need unit tests for this.

I think I would switch the function name around a bit to wp_widget_has_block or maybe something like is_active_widget_block for more parity with the existing is_active_widget.

#2 @birgire
3 years ago

Sounds useful, what about the additional orphaned_widgets sidebar check in is_active_widget(), would that be relevant here too?

https://core.trac.wordpress.org/browser/tags/5.8/src/wp-includes/widgets.php#L900

Version 0, edited 3 years ago by birgire (next)
Note: See TracTickets for help on using tickets.