always call set_blog_id after blog lookup, See #11644
git-svn-id: http://svn.automattic.com/wordpress/trunk@13421 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
c7aa32c0ac
commit
4dc6a43f96
|
@ -16,106 +16,105 @@ require( ABSPATH . WPINC . '/ms-default-constants.php' );
|
||||||
if ( defined( 'SUNRISE' ) )
|
if ( defined( 'SUNRISE' ) )
|
||||||
include_once( WP_CONTENT_DIR . '/sunrise.php' );
|
include_once( WP_CONTENT_DIR . '/sunrise.php' );
|
||||||
|
|
||||||
if ( isset( $current_site ) && isset( $current_blog ) )
|
if ( !isset( $current_site ) || !isset( $current_blog ) ) {
|
||||||
return;
|
|
||||||
|
|
||||||
$domain = addslashes( $_SERVER['HTTP_HOST'] );
|
$domain = addslashes( $_SERVER['HTTP_HOST'] );
|
||||||
if ( false !== strpos( $domain, ':' ) ) {
|
if ( false !== strpos( $domain, ':' ) ) {
|
||||||
if ( substr( $domain, -3 ) == ':80' ) {
|
if ( substr( $domain, -3 ) == ':80' ) {
|
||||||
$domain = substr( $domain, 0, -3 );
|
$domain = substr( $domain, 0, -3 );
|
||||||
$_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -3 );
|
$_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -3 );
|
||||||
} elseif ( substr( $domain, -4 ) == ':443' ) {
|
} elseif ( substr( $domain, -4 ) == ':443' ) {
|
||||||
$domain = substr( $domain, 0, -4 );
|
$domain = substr( $domain, 0, -4 );
|
||||||
$_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -4 );
|
$_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -4 );
|
||||||
} else {
|
} else {
|
||||||
wp_die( 'Multisite only works without the port number in the URL.' );
|
wp_die( 'Multisite only works without the port number in the URL.' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$domain = rtrim( $domain, '.' );
|
$domain = rtrim( $domain, '.' );
|
||||||
$cookie_domain = $domain;
|
$cookie_domain = $domain;
|
||||||
if ( substr( $cookie_domain, 0, 4 ) == 'www.' )
|
if ( substr( $cookie_domain, 0, 4 ) == 'www.' )
|
||||||
$cookie_domain = substr( $cookie_domain, 4 );
|
$cookie_domain = substr( $cookie_domain, 4 );
|
||||||
|
|
||||||
$path = preg_replace( '|([a-z0-9-]+.php.*)|', '', $_SERVER['REQUEST_URI'] );
|
$path = preg_replace( '|([a-z0-9-]+.php.*)|', '', $_SERVER['REQUEST_URI'] );
|
||||||
$path = str_replace ( '/wp-admin/', '/', $path );
|
$path = str_replace ( '/wp-admin/', '/', $path );
|
||||||
$path = preg_replace( '|(/[a-z0-9-]+?/).*|', '$1', $path );
|
$path = preg_replace( '|(/[a-z0-9-]+?/).*|', '$1', $path );
|
||||||
|
|
||||||
$current_site = wpmu_current_site();
|
$current_site = wpmu_current_site();
|
||||||
if ( ! isset( $current_site->blog_id ) )
|
if ( ! isset( $current_site->blog_id ) )
|
||||||
$current_site->blog_id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s", $current_site->domain, $current_site->path ) );
|
$current_site->blog_id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s", $current_site->domain, $current_site->path ) );
|
||||||
|
|
||||||
if ( is_subdomain_install() ) {
|
if ( is_subdomain_install() ) {
|
||||||
$current_blog = wp_cache_get( 'current_blog_' . $domain, 'site-options' );
|
$current_blog = wp_cache_get( 'current_blog_' . $domain, 'site-options' );
|
||||||
if ( !$current_blog ) {
|
if ( !$current_blog ) {
|
||||||
$current_blog = get_blog_details( array( 'domain' => $domain ), false );
|
$current_blog = get_blog_details( array( 'domain' => $domain ), false );
|
||||||
if ( $current_blog )
|
if ( $current_blog )
|
||||||
wp_cache_set( 'current_blog_' . $domain, $current_blog, 'site-options' );
|
wp_cache_set( 'current_blog_' . $domain, $current_blog, 'site-options' );
|
||||||
}
|
}
|
||||||
if ( $current_blog && $current_blog->site_id != $current_site->id )
|
if ( $current_blog && $current_blog->site_id != $current_site->id )
|
||||||
$current_site = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->site WHERE id = %d", $current_blog->site_id ) );
|
$current_site = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->site WHERE id = %d", $current_blog->site_id ) );
|
||||||
else
|
else
|
||||||
$blogname = substr( $domain, 0, strpos( $domain, '.' ) );
|
$blogname = substr( $domain, 0, strpos( $domain, '.' ) );
|
||||||
} else {
|
} else {
|
||||||
$blogname = htmlspecialchars( substr( $_SERVER[ 'REQUEST_URI' ], strlen( $path ) ) );
|
$blogname = htmlspecialchars( substr( $_SERVER[ 'REQUEST_URI' ], strlen( $path ) ) );
|
||||||
if ( false !== strpos( $blogname, '/' ) )
|
if ( false !== strpos( $blogname, '/' ) )
|
||||||
$blogname = substr( $blogname, 0, strpos( $blogname, '/' ) );
|
$blogname = substr( $blogname, 0, strpos( $blogname, '/' ) );
|
||||||
if ( false !== strpos( $blogname, '?' ) )
|
if ( false !== strpos( $blogname, '?' ) )
|
||||||
$blogname = substr( $blogname, 0, strpos( $blogname, '?' ) );
|
$blogname = substr( $blogname, 0, strpos( $blogname, '?' ) );
|
||||||
$reserved_blognames = array( 'page', 'comments', 'blog', 'wp-admin', 'wp-includes', 'wp-content', 'files', 'feed' );
|
$reserved_blognames = array( 'page', 'comments', 'blog', 'wp-admin', 'wp-includes', 'wp-content', 'files', 'feed' );
|
||||||
if ( $blogname != '' && ! in_array( $blogname, $reserved_blognames ) && ! is_file( $blogname ) )
|
if ( $blogname != '' && ! in_array( $blogname, $reserved_blognames ) && ! is_file( $blogname ) )
|
||||||
$path .= $blogname . '/';
|
$path .= $blogname . '/';
|
||||||
$current_blog = wp_cache_get( 'current_blog_' . $domain . $path, 'site-options' );
|
$current_blog = wp_cache_get( 'current_blog_' . $domain . $path, 'site-options' );
|
||||||
if ( ! $current_blog ) {
|
if ( ! $current_blog ) {
|
||||||
$current_blog = get_blog_details( array( 'domain' => $domain, 'path' => $path ), false );
|
$current_blog = get_blog_details( array( 'domain' => $domain, 'path' => $path ), false );
|
||||||
if ( $current_blog )
|
if ( $current_blog )
|
||||||
wp_cache_set( 'current_blog_' . $domain . $path, $current_blog, 'site-options' );
|
wp_cache_set( 'current_blog_' . $domain . $path, $current_blog, 'site-options' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! defined( 'WP_INSTALLING' ) && is_subdomain_install() && ! is_object( $current_blog ) ) {
|
if ( ! defined( 'WP_INSTALLING' ) && is_subdomain_install() && ! is_object( $current_blog ) ) {
|
||||||
if ( defined( 'NOBLOGREDIRECT' ) ) {
|
if ( defined( 'NOBLOGREDIRECT' ) ) {
|
||||||
$destination = NOBLOGREDIRECT;
|
$destination = NOBLOGREDIRECT;
|
||||||
if ( '%siteurl%' == $destination )
|
if ( '%siteurl%' == $destination )
|
||||||
$destination = "http://" . $current_site->domain . $current_site->path;
|
$destination = "http://" . $current_site->domain . $current_site->path;
|
||||||
} else {
|
} else {
|
||||||
$destination = 'http://' . $current_site->domain . $current_site->path . 'wp-signup.php?new=' . str_replace( '.' . $current_site->domain, '', $domain );
|
$destination = 'http://' . $current_site->domain . $current_site->path . 'wp-signup.php?new=' . str_replace( '.' . $current_site->domain, '', $domain );
|
||||||
}
|
}
|
||||||
header( 'Location: ' . $destination );
|
header( 'Location: ' . $destination );
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! defined( 'WP_INSTALLING' ) ) {
|
if ( ! defined( 'WP_INSTALLING' ) ) {
|
||||||
if ( $current_site && ! $current_blog ) {
|
if ( $current_site && ! $current_blog ) {
|
||||||
if ( $current_site->domain != $_SERVER[ 'HTTP_HOST' ] ) {
|
if ( $current_site->domain != $_SERVER[ 'HTTP_HOST' ] ) {
|
||||||
header( 'Location: http://' . $current_site->domain . $current_site->path );
|
header( 'Location: http://' . $current_site->domain . $current_site->path );
|
||||||
exit;
|
exit;
|
||||||
|
}
|
||||||
|
$current_blog = get_blog_details( array( 'domain' => $current_site->domain, 'path' => $current_site->path ), false );
|
||||||
|
}
|
||||||
|
if ( ! $current_blog || ! $current_site )
|
||||||
|
ms_not_installed();
|
||||||
|
}
|
||||||
|
|
||||||
|
$blog_id = $current_blog->blog_id;
|
||||||
|
$public = $current_blog->public;
|
||||||
|
|
||||||
|
if ( empty( $current_blog->site_id ) )
|
||||||
|
$current_blog->site_id = 1;
|
||||||
|
$site_id = $current_blog->site_id;
|
||||||
|
|
||||||
|
$current_site = get_current_site_name( $current_site );
|
||||||
|
|
||||||
|
if ( ! $blog_id ) {
|
||||||
|
if ( defined( 'WP_INSTALLING' ) ) {
|
||||||
|
$current_blog->blog_id = $blog_id = 1;
|
||||||
|
} else {
|
||||||
|
$msg = ! $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->site'" ) ? ' ' . __( 'Database tables are missing.' ) : '';
|
||||||
|
wp_die( __( 'No blog by that name on this system.' ) . $msg );
|
||||||
}
|
}
|
||||||
$current_blog = get_blog_details( array( 'domain' => $current_site->domain, 'path' => $current_site->path ), false );
|
|
||||||
}
|
}
|
||||||
if ( ! $current_blog || ! $current_site )
|
|
||||||
ms_not_installed();
|
|
||||||
}
|
}
|
||||||
|
$wpdb->set_prefix( $table_prefix, false ); // $table_prefix can be set in sunrise.php
|
||||||
$blog_id = $current_blog->blog_id;
|
|
||||||
$public = $current_blog->public;
|
|
||||||
|
|
||||||
if ( empty( $current_blog->site_id ) )
|
|
||||||
$current_blog->site_id = 1;
|
|
||||||
$site_id = $current_blog->site_id;
|
|
||||||
|
|
||||||
$current_site = get_current_site_name( $current_site );
|
|
||||||
|
|
||||||
if ( ! $blog_id ) {
|
|
||||||
if ( defined( 'WP_INSTALLING' ) ) {
|
|
||||||
$current_blog->blog_id = $blog_id = 1;
|
|
||||||
} else {
|
|
||||||
$msg = ! $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->site'" ) ? ' ' . __( 'Database tables are missing.' ) : '';
|
|
||||||
wp_die( __( 'No blog by that name on this system.' ) . $msg );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$wpdb->set_prefix( $table_prefix, false ); // set DB table prefix
|
|
||||||
$wpdb->set_blog_id( $current_blog->blog_id, $current_blog->site_id );
|
$wpdb->set_blog_id( $current_blog->blog_id, $current_blog->site_id );
|
||||||
$table_prefix = $wpdb->get_blog_prefix();
|
$table_prefix = $wpdb->get_blog_prefix();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue