2010-01-06 08:50:12 +01:00
< ? php
2010-01-08 22:25:01 +01:00
/**
2010-03-17 05:39:50 +01:00
* Used to set up and fix common variables and include
2010-01-28 17:09:52 +01:00
* the Multisite procedural and class library .
2010-01-08 22:25:01 +01:00
*
2010-01-28 17:09:52 +01:00
* Allows for some configuration in wp - config . php ( see ms - default - constants . php )
2010-01-08 22:25:01 +01:00
*
2010-01-28 17:09:52 +01:00
* @ package WordPress
* @ subpackage Multisite
2010-04-04 15:29:35 +02:00
* @ since 3.0 . 0
2010-01-08 22:25:01 +01:00
*/
2010-01-28 17:09:52 +01:00
/** Include Multisite initialization functions */
require ( ABSPATH . WPINC . '/ms-load.php' );
require ( ABSPATH . WPINC . '/ms-default-constants.php' );
if ( defined ( 'SUNRISE' ) )
include_once ( WP_CONTENT_DIR . '/sunrise.php' );
2010-01-08 22:25:01 +01:00
2010-05-04 22:48:28 +02:00
/** Check for and define SUBDOMAIN_INSTALL and the deprecated VHOST constant. */
ms_subdomain_constants ();
2010-02-26 01:05:11 +01:00
if ( ! isset ( $current_site ) || ! isset ( $current_blog ) ) {
$domain = addslashes ( $_SERVER [ 'HTTP_HOST' ] );
if ( false !== strpos ( $domain , ':' ) ) {
if ( substr ( $domain , - 3 ) == ':80' ) {
$domain = substr ( $domain , 0 , - 3 );
$_SERVER [ 'HTTP_HOST' ] = substr ( $_SERVER [ 'HTTP_HOST' ], 0 , - 3 );
} elseif ( substr ( $domain , - 4 ) == ':443' ) {
$domain = substr ( $domain , 0 , - 4 );
$_SERVER [ 'HTTP_HOST' ] = substr ( $_SERVER [ 'HTTP_HOST' ], 0 , - 4 );
} else {
2012-01-26 21:34:27 +01:00
wp_load_translations_early ();
wp_die ( __ ( 'Multisite only works without the port number in the URL.' ) );
2010-02-26 01:05:11 +01:00
}
2010-01-06 08:50:12 +01:00
}
2010-02-26 01:05:11 +01:00
$domain = rtrim ( $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 );
$current_site = wpmu_current_site ();
2014-02-14 00:07:14 +01:00
$current_site -> cookie_domain = $current_site -> domain ;
if ( 'www.' === substr ( $current_site -> cookie_domain , 0 , 4 ) ) {
$current_site -> cookie_domain = substr ( $current_site -> cookie_domain , 4 );
}
2010-02-26 01:05:11 +01:00
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 ) );
if ( is_subdomain_install () ) {
$current_blog = wp_cache_get ( 'current_blog_' . $domain , 'site-options' );
if ( ! $current_blog ) {
$current_blog = get_blog_details ( array ( 'domain' => $domain ), false );
if ( $current_blog )
wp_cache_set ( 'current_blog_' . $domain , $current_blog , 'site-options' );
}
2010-11-30 21:45:40 +01:00
if ( $current_blog && $current_blog -> site_id != $current_site -> id ) {
2010-02-26 01:05:11 +01:00
$current_site = $wpdb -> get_row ( $wpdb -> prepare ( " SELECT * FROM $wpdb->site WHERE id = %d " , $current_blog -> site_id ) );
2010-11-30 21:45:40 +01:00
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 ) );
} else
2010-02-26 01:05:11 +01:00
$blogname = substr ( $domain , 0 , strpos ( $domain , '.' ) );
} else {
$blogname = htmlspecialchars ( substr ( $_SERVER [ 'REQUEST_URI' ], strlen ( $path ) ) );
if ( false !== strpos ( $blogname , '/' ) )
$blogname = substr ( $blogname , 0 , strpos ( $blogname , '/' ) );
if ( false !== strpos ( $blogname , '?' ) )
$blogname = substr ( $blogname , 0 , strpos ( $blogname , '?' ) );
$reserved_blognames = array ( 'page' , 'comments' , 'blog' , 'wp-admin' , 'wp-includes' , 'wp-content' , 'files' , 'feed' );
if ( $blogname != '' && ! in_array ( $blogname , $reserved_blognames ) && ! is_file ( $blogname ) )
$path .= $blogname . '/' ;
$current_blog = wp_cache_get ( 'current_blog_' . $domain . $path , 'site-options' );
if ( ! $current_blog ) {
$current_blog = get_blog_details ( array ( 'domain' => $domain , 'path' => $path ), false );
if ( $current_blog )
wp_cache_set ( 'current_blog_' . $domain . $path , $current_blog , 'site-options' );
}
2010-10-07 22:12:49 +02:00
unset ( $reserved_blognames );
2010-01-06 08:50:12 +01:00
}
2010-02-26 01:05:11 +01:00
if ( ! defined ( 'WP_INSTALLING' ) && is_subdomain_install () && ! is_object ( $current_blog ) ) {
if ( defined ( 'NOBLOGREDIRECT' ) ) {
$destination = NOBLOGREDIRECT ;
if ( '%siteurl%' == $destination )
$destination = " http:// " . $current_site -> domain . $current_site -> path ;
} else {
$destination = 'http://' . $current_site -> domain . $current_site -> path . 'wp-signup.php?new=' . str_replace ( '.' . $current_site -> domain , '' , $domain );
}
header ( 'Location: ' . $destination );
die ();
2010-01-06 08:50:12 +01:00
}
2010-02-26 01:05:11 +01:00
if ( ! defined ( 'WP_INSTALLING' ) ) {
if ( $current_site && ! $current_blog ) {
if ( $current_site -> domain != $_SERVER [ 'HTTP_HOST' ] ) {
header ( 'Location: http://' . $current_site -> domain . $current_site -> path );
exit ;
}
$current_blog = get_blog_details ( array ( 'domain' => $current_site -> domain , 'path' => $current_site -> path ), false );
2010-01-06 08:50:12 +01:00
}
2010-02-26 01:05:11 +01:00
if ( ! $current_blog || ! $current_site )
ms_not_installed ();
2010-01-06 08:50:12 +01:00
}
2010-02-26 01:05:11 +01:00
$blog_id = $current_blog -> blog_id ;
$public = $current_blog -> public ;
2010-01-06 08:50:12 +01:00
2010-02-26 01:05:11 +01:00
if ( empty ( $current_blog -> site_id ) )
$current_blog -> site_id = 1 ;
$site_id = $current_blog -> site_id ;
2010-01-06 08:50:12 +01:00
2010-02-26 01:05:11 +01:00
$current_site = get_current_site_name ( $current_site );
2010-01-06 08:50:12 +01:00
2010-02-26 01:05:11 +01:00
if ( ! $blog_id ) {
if ( defined ( 'WP_INSTALLING' ) ) {
$current_blog -> blog_id = $blog_id = 1 ;
} else {
2012-01-26 21:34:27 +01:00
wp_load_translations_early ();
$msg = ! $wpdb -> get_var ( " SHOW TABLES LIKE ' $wpdb->site ' " ) ? ' ' . __ ( 'Database tables are missing.' ) : '' ;
wp_die ( __ ( 'No site by that name on this system.' ) . $msg );
2010-02-26 01:05:11 +01:00
}
}
2010-01-06 08:50:12 +01:00
}
2010-02-26 01:05:11 +01:00
$wpdb -> set_prefix ( $table_prefix , false ); // $table_prefix can be set in sunrise.php
2010-02-24 22:07:23 +01:00
$wpdb -> set_blog_id ( $current_blog -> blog_id , $current_blog -> site_id );
2010-01-28 17:09:52 +01:00
$table_prefix = $wpdb -> get_blog_prefix ();
2012-08-09 18:28:15 +02:00
$_wp_switched_stack = array ();
2012-08-22 05:34:00 +02:00
$switched = false ;
2010-01-06 08:50:12 +01:00
2010-01-28 18:28:44 +01:00
// need to init cache again after blog_id is set
wp_start_object_cache ();
2010-01-06 08:50:12 +01:00
2010-01-29 17:26:46 +01:00
// Define upload directory constants
2010-02-20 15:07:23 +01:00
ms_upload_constants ();