From 2f3f5b351fd86bf2e1a12d445b0de57392c0a0fa Mon Sep 17 00:00:00 2001 From: wpmuguru Date: Thu, 21 Jan 2010 17:20:23 +0000 Subject: [PATCH] allow www installs to enable multisite, see #11945 git-svn-id: http://svn.automattic.com/wordpress/trunk@12787 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/options-network.php | 37 ++++---------------- wp-includes/ms-load.php | 2 +- wp-includes/ms-settings.php | 66 ++++++++++++++++++++++-------------- 3 files changed, 47 insertions(+), 58 deletions(-) diff --git a/wp-admin/options-network.php b/wp-admin/options-network.php index 00a7c5d1ee..fa9033d8ee 100644 --- a/wp-admin/options-network.php +++ b/wp-admin/options-network.php @@ -129,9 +129,9 @@ function step1() { function printstep1form( $rewrite_enabled = false ) { $weblog_title = ucfirst( get_option( 'blogname' ) ) . ' Sites'; $email = get_option( 'admin_email' ); - $hostname = $_SERVER[ 'HTTP_HOST' ]; - if( substr( $_SERVER[ 'HTTP_HOST' ], 0, 4 ) == 'www.' ) - $hostname = str_replace( "www.", "", $_SERVER[ 'HTTP_HOST' ] ); + $hostname = get_clean_basedomain(); + if( substr( $hostname, 0, 4 ) == 'www.' ) + $nowww = substr( $hostname, 4 ); wp_nonce_field( 'install-network-1' ); ?> @@ -147,6 +147,9 @@ function printstep1form( $rewrite_enabled = false ) {

Server Address

+ +

We recommend you change your siteurl to before enabling the network feature. It will still be possible to visit your site using the "www" prefix with an address like but any links will not have the "www" prefix.

+ @@ -263,43 +266,15 @@ function step2_config() { function get_clean_basedomain() { global $wpdb; $domain = preg_replace( '|https?://|', '', get_option( 'siteurl') ); - //@todo: address no www in multisite code - if( substr( $domain, 0, 4 ) == 'www.' ) - $domain = substr( $domain, 4 ); if( strpos( $domain, '/' ) ) $domain = substr( $domain, 0, strpos( $domain, '/' ) ); return $domain; } -function nowww() { - $nowww = str_replace( 'www.', '', $_POST[ 'basedomain' ] ); - ?> -

No-www

-

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 but any links will not have the "www" prefix. They will instead point at .

-

The preferred method of hosting sites is without the "www" prefix as it's more compact and simple.

-

You can still use "" and URLs like "www.blog1." to address your site and blogs after installation but internal links will use the format.

- -

www. is depreciated has a lot more information on why 'www.' isn't needed any more.

-

- - ' /> - ' /> - ' /> - - - -

- domain); + define('COOKIE_DOMAIN', '.' . $current_site->cookie_domain); } ?> diff --git a/wp-includes/ms-settings.php b/wp-includes/ms-settings.php index 9c2512b2b7..fd7afcda7d 100644 --- a/wp-includes/ms-settings.php +++ b/wp-includes/ms-settings.php @@ -21,8 +21,6 @@ if ( isset( $current_site ) && isset( $current_blog ) ) $wpmuBaseTablePrefix = $table_prefix; $domain = addslashes( $_SERVER['HTTP_HOST'] ); -if ( substr( $domain, 0, 4 ) == 'www.' ) - $domain = substr( $domain, 4 ); if ( strpos( $domain, ':' ) ) { if ( substr( $domain, -3 ) == ':80' ) { $domain = substr( $domain, 0, -3 ); @@ -38,6 +36,11 @@ $domain = preg_replace('/:.*$/', '', $domain); // Strip ports if ( substr( $domain, -1 ) == '.' ) $domain = substr( $domain, 0, -1 ); +if ( substr( $domain, 0, 4 ) == 'www.' ) + $cookie_domain = substr( $domain, 4 ); +else + $cookie_domain = $domain; + $path = preg_replace( '|([a-z0-9-]+.php.*)|', '', $_SERVER['REQUEST_URI'] ); $path = str_replace ( '/wp-admin/', '/', $path ); $path = preg_replace( '|(/[a-z0-9-]+?/).*|', '$1', $path ); @@ -55,13 +58,20 @@ function get_current_site_name( $current_site ) { } function wpmu_current_site() { - global $wpdb, $current_site, $domain, $path, $sites; + global $wpdb, $current_site, $domain, $path, $sites, $cookie_domain; if ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) ) { $current_site->id = (defined( 'SITE_ID_CURRENT_SITE' ) ? constant('SITE_ID_CURRENT_SITE') : 1); $current_site->domain = DOMAIN_CURRENT_SITE; $current_site->path = $path = PATH_CURRENT_SITE; if ( defined( 'BLOGID_CURRENT_SITE' ) ) $current_site->blog_id = BLOGID_CURRENT_SITE; + if ( DOMAIN_CURRENT_SITE == $domain ) + $current_site->cookie_domain = $cookie_domain; + elseif ( substr( $current_site->domain, 0, 4 ) == 'www.' ) + $current_site->cookie_domain = substr( $current_site->domain, 4 ); + else + $current_site->cookie_domain = $current_site->domain; + return $current_site; } @@ -76,24 +86,34 @@ function wpmu_current_site() { $path = $current_site->path; $current_site->blog_id = $wpdb->get_var( "SELECT blog_id FROM {$wpdb->blogs} WHERE domain='{$current_site->domain}' AND path='{$current_site->path}'" ); $current_site = get_current_site_name( $current_site ); + if ( substr( $current_site->domain, 0, 4 ) == 'www.' ) + $current_site->cookie_domain = substr( $current_site->domain, 4 ); wp_cache_set( "current_site", $current_site, "site-options" ); return $current_site; } $path = substr( $_SERVER[ 'REQUEST_URI' ], 0, 1 + strpos( $_SERVER[ 'REQUEST_URI' ], '/', 1 ) ); - if ( is_subdomain_install() ) { - $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $domain, $path) ); - if ( $current_site != null ) - return $current_site; - $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $domain) ); - if ( $current_site != null ) { - $path = '/'; - return $current_site; - } + if ( $domain == $cookie_domain ) + $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $domain, $path ) ); + else + $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 ) ); + if ( $current_site == null ) { + if ( $domain == $cookie_domain ) + $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $domain ) ); + else + $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 ) ); + } + if ( $current_site != null ) { + $path = $current_site->path; + $current_site->cookie_domain = $cookie_domain; + return $current_site; + } elseif ( is_subdomain_install() ) { $sitedomain = substr( $domain, 1 + strpos( $domain, '.' ) ); $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path) ); - if ( $current_site != null ) + if ( $current_site != null ) { + $current_site->cookie_domain = $current_site->domain; return $current_site; + } $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $sitedomain) ); if ( $current_site == null && defined( "WP_INSTALLING" ) == false ) { if ( count( $sites ) == 1 ) { @@ -105,21 +125,15 @@ function wpmu_current_site() { } else { $path = '/'; } - } else { - $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $domain, $path) ); - if ( $current_site != null ) - return $current_site; - $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $domain) ); - if ( $current_site == null && defined( "WP_INSTALLING" ) == false ) { - if ( count( $sites ) == 1 ) { - $current_site = $sites[0]; - die( "That blog does not exist. Please try http://{$current_site->domain}{$current_site->path}" ); - } else { - die( "No WPMU site defined on this host. If you are the owner of this site, please check Debugging WPMU for further assistance." ); - } + } elseif ( defined( "WP_INSTALLING" ) == false ) { + if ( count( $sites ) == 1 ) { + $current_site = $sites[0]; + die( "That blog does not exist. Please try http://{$current_site->domain}{$current_site->path}" ); } else { - $path = '/'; + die( "No WPMU site defined on this host. If you are the owner of this site, please check Debugging WPMU for further assistance." ); } + } else { + $path = '/'; } return $current_site; }
Server Address