[wp-hackers] global $wp_registered_widgets of the main blog

Mike Schinkel mikeschinkel at newclarity.net
Fri Jun 10 08:11:07 UTC 2011

On Jun 10, 2011, at 3:42 AM, Rocio Valdivia wrote:
> I'm creating a plugin for WP multisite and I need to access to the value of
> the global variable $wp_registered_widgets of the blog_id = 1, that is,
> wherever I am, for example, in the index of blog_id = 2 or 3, etc. I need
> the value of that variable of the main blog.
> I have tried the following code to do this:
> global $switched;
> switch_to_blog(1);
> global $wp_registered_widgets;
> restore_current_blog();
> but it doesn't work because the function switch_to_blog only works if you
> call to another functions, not for global variables.
> Any ideas?, because I have not found a function in /wp-includes/widgets.php
> that retrieves that value. So I prefer to ask you before to query the info
> of each register widget and to merge it into an array.

I'm not sure because I don't have time to test it, but try calling wp_widgets_init() like so:

global $switched;
global $wp_registered_widgets;

(Note I assume your code is incomplete pseudo code and that you'll actually use more code than you listed.) 

Hope this helps.


More information about the wp-hackers mailing list