WordPress.org

Make WordPress Core

Changeset 12787


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

allow www installs to enable multisite, see #11945

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/options-network.php

    r12780 r12787  
    130130    $weblog_title = ucfirst( get_option( 'blogname' ) ) . ' Sites';
    131131    $email = get_option( 'admin_email' );
    132     $hostname = $_SERVER[ 'HTTP_HOST' ];
    133     if( substr( $_SERVER[ 'HTTP_HOST' ], 0, 4 ) == 'www.' )
    134         $hostname = str_replace( "www.", "", $_SERVER[ 'HTTP_HOST' ] );
     132    $hostname = get_clean_basedomain();
     133    if( substr( $hostname, 0, 4 ) == 'www.' )
     134        $nowww = substr( $hostname, 4 );
    135135
    136136    wp_nonce_field( 'install-network-1' );
     
    148148
    149149        <h2>Server Address</h2>
     150        <?php if ( isset( $nowww ) ) { ?>
     151        <h3>We recommend you change your siteurl to <code><?php echo $nowww; ?></code> before enabling the network feature. It will still be possible to visit your site using the "www" prefix with an address like <code><?php echo $hostname; ?></code> but any links will not have the "www" prefix. </h3>
     152        <?php } ?>
    150153        <table class="form-table"> 
    151154            <tr>
     
    264267    global $wpdb;
    265268    $domain = preg_replace( '|https?://|', '', get_option( 'siteurl') );
    266     //@todo: address no www in multisite code
    267     if( substr( $domain, 0, 4 ) == 'www.' )
    268         $domain = substr( $domain, 4 );
    269269    if( strpos( $domain, '/' ) )
    270270        $domain = substr( $domain, 0, strpos( $domain, '/' ) );
    271271    return $domain;
    272 }
    273 
    274 function nowww() {
    275     $nowww = str_replace( 'www.', '', $_POST[ 'basedomain' ] );
    276     ?>
    277     <h2>No-www</h2>
    278     <p>WordPress strips the string "www" from the URLs of sites using this software. It is still possible to visit your site using the "www" prefix with an address like <em><?php echo $_POST[ 'basedomain' ] ?></em> but any links will not have the "www" prefix. They will instead point at <?php echo $nowww ?>.</p>
    279     <p>The preferred method of hosting sites is without the "www" prefix as it's more compact and simple.</p>
    280     <p>You can still use "<?php echo $_POST[ 'basedomain' ] ?>" and URLs like "www.blog1.<?php echo $nowww; ?>" to address your site and blogs after installation but internal links will use the <?php echo $nowww ?> format.</p>
    281 
    282     <p><a href="http://no-www.org/">www. is depreciated</a> has a lot more information on why 'www.' isn't needed any more.</p>
    283     <p>
    284     <?php wp_nonce_field( 'install-network-1' ); ?>
    285         <input type='hidden' name='vhost' value='<?php echo $_POST[ 'vhost' ]; ?>' />
    286         <input type='hidden' name='weblog_title' value='<?php echo $_POST[ 'weblog_title' ]; ?>' />
    287         <input type='hidden' name='email' value='<?php echo $_POST[ 'email' ]; ?>' />
    288         <input type='hidden' name='action' value='step2' />
    289         <input type='hidden' name='basedomain' value='<?echo $nowww ?>' />
    290         <input class="button" type='submit' value='Continue' />
    291     </p>
    292     <?php
    293272}
    294273
     
    297276    case "step2":
    298277        check_admin_referer( 'install-network-1' );
    299         if( substr( $_POST[ 'basedomain' ], 0, 4 ) == 'www.' ) {
    300             nowww();
    301             continue;
    302         }
    303278       
    304279        // Install!
  • trunk/wp-includes/ms-load.php

    r12773 r12787  
    147147     */
    148148    if ( !defined('COOKIE_DOMAIN') )
    149             define('COOKIE_DOMAIN', '.' . $current_site->domain);
     149            define('COOKIE_DOMAIN', '.' . $current_site->cookie_domain);
    150150}
    151151?>
  • 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.