Best way to get the root site ID in MultiSite

272 views
Skip to first unread message

Nick Ciske

unread,
Jul 25, 2013, 12:29:21 PM7/25/13
to mpls-stpau...@googlegroups.com
We had a question come up at WP Wed regarding getting the root site ID in Multisite.

I had been using a magic number*:

switch_to_blog( 1 ); // 1 is a magic number

Then I switched to using the semi-obtuse constant in wp-config.php as that seems safer (in the rare case that would change):

switch_to_blog( SITE_ID_CURRENT_SITE ); // current root site, not current site user is browsing

Then Justin Foell ran across some code using a function I'd never seen before:

get_dashboard_blog(); // Huh?


Which returns the blog details for a blog that may or may not be the current site, and apparently may or may not be the root site either. It checks an option called dashboard_blog, but there doesn’t seem to be anywhere that can be modified (it appears nowhere else in the core code from what I can tell).

It gets a mention in the help tab but has no field on the Network Settings page:

Dashboard Site is an option to give a site to users who do not have a site on the system. Their default role is Subscriber, but that default can be changed.

Seems like the constant is the right way to go, and the dashboard_blog is a 3+ year old vestige of WPMU that may has not been fully removed or deprecated.

This Trac ticket backs this conclusion up:

That was a fun spelunking adventure into core!

And I just opened my first Trac ticket as a result:


_________________________
Nick Ciske
@nciske

Toby C

unread,
Jul 25, 2013, 4:33:23 PM7/25/13
to mpls-stpau...@googlegroups.com
Nick,
Wonderful deep dive there!  Thanks for sharing, and congrats on your first Trac ticket!

Toby

--
You received this message because you are subscribed to the Google Groups "Minneapolis St. Paul WordPress User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mpls-stpaul-word...@googlegroups.com.
To post to this group, send email to mpls-stpau...@googlegroups.com.
Visit this group at http://groups.google.com/group/mpls-stpaul-wordpress.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

JustinF

unread,
Aug 5, 2013, 2:53:45 PM8/5/13
to mpls-stpau...@googlegroups.com
I meant to respond to this much earlier... thanks for following up on our strange conversation Nick! And just like that, you've got a patch going into WordPress 3.7, W00t!
Reply all
Reply to author
Forward
0 new messages