allow www installs to enable multisite, see #11945
git-svn-id: https://develop.svn.wordpress.org/trunk@12787 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
f1494b0248
commit
7028f64e49
|
@ -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 ) {
|
|||
</p>
|
||||
|
||||
<h2>Server Address</h2>
|
||||
<?php if ( isset( $nowww ) ) { ?>
|
||||
<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>
|
||||
<?php } ?>
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th scope='row'>Server Address</th>
|
||||
|
@ -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' ] );
|
||||
?>
|
||||
<h2>No-www</h2>
|
||||
<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>
|
||||
<p>The preferred method of hosting sites is without the "www" prefix as it's more compact and simple.</p>
|
||||
<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>
|
||||
|
||||
<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>
|
||||
<p>
|
||||
<?php wp_nonce_field( 'install-network-1' ); ?>
|
||||
<input type='hidden' name='vhost' value='<?php echo $_POST[ 'vhost' ]; ?>' />
|
||||
<input type='hidden' name='weblog_title' value='<?php echo $_POST[ 'weblog_title' ]; ?>' />
|
||||
<input type='hidden' name='email' value='<?php echo $_POST[ 'email' ]; ?>' />
|
||||
<input type='hidden' name='action' value='step2' />
|
||||
<input type='hidden' name='basedomain' value='<?echo $nowww ?>' />
|
||||
<input class="button" type='submit' value='Continue' />
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
|
||||
$action = isset($_POST[ 'action' ]) ? $_POST[ 'action' ] : null;
|
||||
switch($action) {
|
||||
case "step2":
|
||||
check_admin_referer( 'install-network-1' );
|
||||
if( substr( $_POST[ 'basedomain' ], 0, 4 ) == 'www.' ) {
|
||||
nowww();
|
||||
continue;
|
||||
}
|
||||
|
||||
// Install!
|
||||
$base = stripslashes( dirname( dirname($_SERVER["SCRIPT_NAME"]) ) );
|
||||
|
|
|
@ -146,6 +146,6 @@ function ms_network_cookies() {
|
|||
* @since 2.0.0
|
||||
*/
|
||||
if ( !defined('COOKIE_DOMAIN') )
|
||||
define('COOKIE_DOMAIN', '.' . $current_site->domain);
|
||||
define('COOKIE_DOMAIN', '.' . $current_site->cookie_domain);
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -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,12 +125,7 @@ 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 ) {
|
||||
} elseif ( defined( "WP_INSTALLING" ) == false ) {
|
||||
if ( count( $sites ) == 1 ) {
|
||||
$current_site = $sites[0];
|
||||
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>" );
|
||||
|
@ -120,7 +135,6 @@ function wpmu_current_site() {
|
|||
} else {
|
||||
$path = '/';
|
||||
}
|
||||
}
|
||||
return $current_site;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue