Opened 14 months ago
Last modified 6 months ago
#55595 new enhancement
Consider only registering widgets on themes that supports widgets
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | Widgets | Keywords: | needs-patch |
Focuses: | performance | Cc: |
Description
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
@
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
@
14 months ago
There could also be actions triggered, that would no longer be triggered.
See https://wpdirectory.net/search/01G144AV0DYES8C17J92YSRS8Z
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.
What about plugins using
the_widget()
?https://developer.wordpress.org/reference/functions/the_widget/