WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What is the file and line where WordPress determines which multi-site the user is on from the URL?

I've been looking through the code all afternoon and can't figure out where it turns mysite.com/blogbase/myblog into 2 (the ID). There's a get_id_from_blogname() function, but it doesn't seem to be called on load?

share|improve this question

Took a little while to run through, but this is where we end up.

On line 85 of wp-settings.php, it checks if the MULTISITE constant has been defined. If so, it loads the multisite files that handle things like figuring out which blog you are on.

One of those files is /wp-includes/ms-settings.php. I believe it decides which blog you are on at line 50.

$current_site->blog_id = $wpdb->get_var( .... 'SELECT blog_id FROM ... WHERE path = ...' );

Basically, $current_site is a global stdClass that gets returned from wpmu_current_site(). In ms-settings.php it overwrites it if it hasn't already been forced via config settings.

Also check out /wp-includes/ms-load.php for info on wpmu_current_site

share|improve this answer
I'm not sure what wpmu_current_site() is actually doing, but the $current_site variable it returns always has the same $current_site->domain and $current_site->path, regardless of which blog I'm on. It's always [path] => /wordpress/ [blog_id] => 1. Later in wpmu_current_site() it sets $path from $_SERVER[ 'REQUEST_URI' ], but that code never seems to run since the function always returns before that. The constants being used are coming from wp-config.php. So I'm still not sure where it's getting the path from the URL at... – Nick Dec 1 '12 at 4:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.