[wp-hackers] WP 2.2 Widgets Issue / Fix
Otto
otto at ottodestruct.com
Thu May 31 16:31:54 GMT 2007
I wrote this little bit of code to test for the case where the user
had sidebars but no active widgets in them (for somebody on trac,
actually):
function exist_active_widgets()
$sidebars_widgets = wp_get_sidebars_widgets();
foreach ($sidebars_widgets as $sidebar)
if (!empty($sidebar)) return true;
return false;
}
if (!exist_active_widgets())
echo "User has no active widgets in any sidebar.";
The problem seems to be that:
a) You want to check if the theme is "widgets enabled" instead, and
b) You want to do this in a plugin.
Now, part A means that you want to know if the theme has registered
any sidebars. This is easy enough...
function is_theme_widget_enabled() {
global $wp_registered_sidebars;
if (count($wp_registered_sidebars) == 0) return false;
else return true;
}
The problem lies with part B. The theme registers sidebars in its
functions.php file, which is not loaded until well after the plugins
are loaded. So you have to delay whatever check you're talking about
until after that point. You can do this by hooking the init action
hook for onto whatever function you're using to do your initialization
and creation of your menu stuffs.
On 5/31/07, Martin Fitzpatrick <martin.fitzpatrick at gmail.com> wrote:
> Is there a simple way to tell, from a plugin, whether the current
> theme supports Widgets? I think that would be the equivalent
> functionality I was looking for.
More information about the wp-hackers
mailing list