Make WordPress Core

Opened 14 months ago

Last modified 6 months ago

#55595 new enhancement

Consider only registering widgets on themes that supports widgets

Reported by: spacedmonkey's profile spacedmonkey Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Widgets Keywords: needs-patch
Focuses: performance Cc:


The wp_widgets_init function is run all init and is run on every request. This is wasteful for a number of reasons. Register a widget can result in a get_option lookup. Also, if the theme does not support widgets, then this is wasteful. Consider adding a simple check at the start of wp_widgets_init to check if the current theme supports widgets, before registering.

This is specially good, considering that more and more themes are now block based and do not use widgets at all.

Change History (4)

#2 @spacedmonkey
14 months ago

@joyously That feel super edge casey. But we could add a check in the_widget to force registery if not already registered.

#3 @joyously
14 months ago

There could also be actions triggered, that would no longer be triggered.
The SEO plugins have remove_all_actions( 'widgets_init' ); and all the plugins that register a widget do it on the 'widget_init' action which is in the wp_widgets_init() function.

I didn't look at all 18705 matches, but I do know there is a widget block, so you don't need the theme to declare support for widgets to be using all those legacy widgets, which won't work without the action at which the widget is registered.

#4 @pbearne
6 months ago

#57202 was marked as a duplicate.

Note: See TracTickets for help on using tickets.