Make WordPress Core


Ignore:
Timestamp:
01/21/2010 05:20:23 PM (15 years ago)
Author:
wpmuguru
Message:

allow www installs to enable multisite, see #11945

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/ms-settings.php

    r12760 r12787  
    2222
    2323$domain = addslashes( $_SERVER['HTTP_HOST'] );
    24 if ( substr( $domain, 0, 4 ) == 'www.' )
    25     $domain = substr( $domain, 4 );
    2624if ( strpos( $domain, ':' ) ) {
    2725    if ( substr( $domain, -3 ) == ':80' ) {
     
    3937    $domain = substr( $domain, 0, -1 );
    4038
     39if ( substr( $domain, 0, 4 ) == 'www.' )
     40    $cookie_domain = substr( $domain, 4 );
     41else
     42    $cookie_domain = $domain;
     43
    4144$path = preg_replace( '|([a-z0-9-]+.php.*)|', '', $_SERVER['REQUEST_URI'] );
    4245$path = str_replace ( '/wp-admin/', '/', $path );
     
    5659
    5760function wpmu_current_site() {
    58     global $wpdb, $current_site, $domain, $path, $sites;
     61    global $wpdb, $current_site, $domain, $path, $sites, $cookie_domain;
    5962    if ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) ) {
    6063        $current_site->id = (defined( 'SITE_ID_CURRENT_SITE' ) ? constant('SITE_ID_CURRENT_SITE') : 1);
     
    6366        if ( defined( 'BLOGID_CURRENT_SITE' ) )
    6467            $current_site->blog_id = BLOGID_CURRENT_SITE;
     68        if ( DOMAIN_CURRENT_SITE == $domain )
     69            $current_site->cookie_domain = $cookie_domain;
     70        elseif ( substr( $current_site->domain, 0, 4 ) == 'www.' )
     71            $current_site->cookie_domain = substr( $current_site->domain, 4 );
     72        else
     73            $current_site->cookie_domain = $current_site->domain;
     74           
    6575        return $current_site;
    6676    }
     
    7787        $current_site->blog_id = $wpdb->get_var( "SELECT blog_id FROM {$wpdb->blogs} WHERE domain='{$current_site->domain}' AND path='{$current_site->path}'" );
    7888        $current_site = get_current_site_name( $current_site );
     89        if ( substr( $current_site->domain, 0, 4 ) == 'www.' )
     90            $current_site->cookie_domain = substr( $current_site->domain, 4 );
    7991        wp_cache_set( "current_site", $current_site, "site-options" );
    8092        return $current_site;
    8193    }
    8294    $path = substr( $_SERVER[ 'REQUEST_URI' ], 0, 1 + strpos( $_SERVER[ 'REQUEST_URI' ], '/', 1 ) );
    83     if ( is_subdomain_install() ) {
    84         $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $domain, $path) );
    85         if ( $current_site != null )
    86             return $current_site;
    87         $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $domain) );
    88         if ( $current_site != null ) {
    89             $path = '/';
    90             return $current_site;
    91         }
    92 
     95
     96    if ( $domain == $cookie_domain )
     97        $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $domain, $path ) );
     98    else
     99        $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain IN ( %s, %s ) AND path = %s ORDER BY CHAR_LENGTH( domain ) DESC LIMIT 1", $domain, $cookie_domain, $path ) );
     100    if ( $current_site == null ) {
     101        if ( $domain == $cookie_domain )
     102            $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $domain ) );
     103        else
     104            $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain IN ( %s, %s ) AND path = '/' ORDER BY CHAR_LENGTH( domain ) DESC LIMIT 1", $domain, $cookie_domain, $path ) );
     105    }
     106    if ( $current_site != null ) {
     107        $path = $current_site->path;
     108        $current_site->cookie_domain = $cookie_domain;
     109        return $current_site;
     110    } elseif ( is_subdomain_install() ) {
    93111        $sitedomain = substr( $domain, 1 + strpos( $domain, '.' ) );
    94112        $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path) );
    95         if ( $current_site != null )
     113        if ( $current_site != null ) {
     114            $current_site->cookie_domain = $current_site->domain;
    96115            return $current_site;
     116        }
    97117        $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $sitedomain) );
    98118        if ( $current_site == null && defined( "WP_INSTALLING" ) == false ) {
     
    106126            $path = '/';
    107127        }
     128    } elseif ( defined( "WP_INSTALLING" ) == false ) {
     129        if ( count( $sites ) == 1 ) {
     130            $current_site = $sites[0];
     131            die( "That blog does not exist. Please try <a href='http://{$current_site->domain}{$current_site->path}'>http://{$current_site->domain}{$current_site->path}</a>" );
     132        } else {
     133            die( "No WPMU site defined on this host. If you are the owner of this site, please check <a href='http://codex.wordpress.org/Debugging_WPMU'>Debugging WPMU</a> for further assistance." );
     134        }
    108135    } else {
    109         $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $domain, $path) );
    110         if ( $current_site != null )
    111             return $current_site;
    112         $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $domain) );
    113         if ( $current_site == null && defined( "WP_INSTALLING" ) == false ) {
    114             if ( count( $sites ) == 1 ) {
    115                 $current_site = $sites[0];
    116                 die( "That blog does not exist. Please try <a href='http://{$current_site->domain}{$current_site->path}'>http://{$current_site->domain}{$current_site->path}</a>" );
    117             } else {
    118                 die( "No WPMU site defined on this host. If you are the owner of this site, please check <a href='http://codex.wordpress.org/Debugging_WPMU'>Debugging WPMU</a> for further assistance." );
    119             }
    120         } else {
    121             $path = '/';
    122         }
     136        $path = '/';
    123137    }
    124138    return $current_site;
Note: See TracChangeset for help on using the changeset viewer.