I'm trying to find a way to show a widget only if a given sidebar is empty. I'm using Widget Logic to control some widgets, but I'm having trouble figuring out how to use it in this case. I've tried to hook on to widget_logic_eval_override
which seems like the way to go, but I'm not sure how to determine if the sidebar will be empty from inside that function.
Unfortunately, the widget I want to use is from a 3rd party plugin, and I'd rather not rewrite it. So, I can't easily accomplish this in the source for the widget.
Update: After looking at the answers and thinking about this more, I have a better understanding of the issue. There's no way to know whether or not a sidebar will be empty until after all of the widgets assigned to that sidebar have been "executed." So, while we are looping through widgets, we can't know if a fallback widget needs to be shown or not.
What could work would be to specify a given widget as a fallback. Then, when we're looping through widgets we don't display the fallback, but we save a reference to it in some global variable. Then, when we output the sidebar, if nothing is output, we access our global variable and show the fallback widget. Does that make sense? It seems like a really convoluted solution, so I'm wondering if there's a simpler way.