Suppose you have a widget that depends on a metabox being added to, say, your Posts. An easy way to do this is to simply add the add_meta_boxes
action to your Widget's constructor and off you go. When that widget is registered with register_widget()
function, your metaboxes are added and off you go.
The problem with this approach is that, well, if the user hasn't actually dragged that widget into one of his sidebars, we still add the metaboxes. And, if for some reason we register two different versions of this widget (say we extend the widget), then we're uselessly running the function twice.
wp_register_sidebar_widget
is called when the widget is registered, but that means it runs regardless of whether the widget actually appears in a sidebar or not.
Is there a corresponding action that is run when a widget is actually loaded into a sidebar? So in other words an action that will only run for each widget that is actually added to a sidebar? Or do we have to dig through a list of widgets gotten through wp_get_sidebars_widgets()
?