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

Rocio Valdivia rocio at mecus.es
Fri Jun 10 09:01:38 UTC 2011


Ok, I have used add_blog_option() and get_blog_option() to keep the value of
it and to be able of retrieving everywhere ;)

Thanks anyway :D

Rocío Valdivia --- Web: http://mecus.es --- Twitter: @_DorsVenabili

El 10 de junio de 2011 10:21, Rocío Valdivia <rocvaltor at gmail.com> escribió:

> Thanks Mike, of course, it was incomplete pseudo code ;). I have tried
> using wp_widgets_init(); but the global variable $wp_registered_widgets
> still retrieving the value of the current blog, not of the main one :(
>
>
> Rocío Valdivia --- Web: http://mecus.es --- Twitter: @_DorsVenabili
>
> 2011/6/10 Mike Schinkel <mikeschinkel at newclarity.net>
>
>> 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;
>> switch_to_blog(1);
>> wp_widgets_init();
>> global $wp_registered_widgets;
>> restore_current_blog();
>> wp_widgets_init();
>>
>> (Note I assume your code is incomplete pseudo code and that you'll
>> actually use more code than you listed.)
>>
>> Hope this helps.
>>
>> -Mike
>>
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
>
>


More information about the wp-hackers mailing list