How does WordPress determine which multisite the user is on from the URL?

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?

Related posts

Leave a Reply

1 comment

  1. 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