WordPress.org

Ready to get started?Download WordPress

Forums

allow multisite to match bare URL (4 posts)

  1. fuentez
    Member
    Posted 1 year ago #

    Using a multisite setup I ran into the following problem:

    The blogs table was set up during development with:
    developurl.com/site-a-nl
    developurl.com/site-a-en
    developurl.com/site-a-ru
    developurl.com/site-b-nl
    developurl.com/site-b-en
    developurl.com/site-b-ru

    This needed to be converted to production as follows:

    site-a.com/ <-- nl
    site-a.com/en <-- en
    site-a.com/ru <-- ru
    site-b.com/ <-- nl
    site-b.com/en <-- en
    site-b.com/ru <-- ru

    I'm probably stating something well known, but this does not work; the "/" will not get matched to a blog with the current core code. I fixed that using an extra match in ms-settings.php:

    The first check:

    $current_blog = get_blog_details( array( 'domain' => $domain, 'path' => $path ), false );

    And I add:

    $current_blog = get_blog_details( array( 'domain' => $domain, 'path' => '/' ), false );

    (Patch below)

    Index: wp-includes/ms-settings.php
    ===================================================================
    --- wp-includes/ms-settings.php (revision 23450)
    +++ wp-includes/ms-settings.php (working copy)
    @@ -74,6 +74,11 @@
    $current_blog = wp_cache_get( 'current_blog_' . $domain . $path, 'site-options' );
    if ( ! $current_blog ) {
    $current_blog = get_blog_details( array( 'domain' => $domain, 'path' => $path ), false );
    +
    + if ( ! $current_blog ) {
    + $current_blog = get_blog_details( array( 'domain' => $domain, 'path' => '/' ), false );
    + }
    +
    if ( $current_blog )
    wp_cache_set( 'current_blog_' . $domain . $path, $current_blog, 'site-options' );
    }
    `

  2. Patrick Johanneson
    Member
    Posted 1 year ago #

    Could you not do something like this:

    global $blog_id;
    if( 1 == $blog_id ) {
       // this is the '/' blog
    }else{
       // this is one of the sub-sites
    }

    ...instead of modifying core code?

  3. fuentez
    Member
    Posted 1 year ago #

    The problem here is that there are two "/" blogs on separate domains. (in the real project there are three, perhaps more to come)

    As I understand it now I should be using the sunrise plugin plus mu-domainmapping plugin to reach te same result. I did not wish to modify core code, and I placed my modification in de "hacks" forum for a reason ;-)

  4. Patrick Johanneson
    Member
    Posted 1 year ago #

    Ah yes, I suppose there can only be one site with a $blog_id of 1. (I've got a multisite install going, but only one domain, so I should probably be cautious of assuming that site #1 = '/' .)

Topic Closed

This topic has been closed to new replies.

About this Topic