diff options
-rw-r--r-- | wp-includes/wp-db.php | 35 | ||||
-rw-r--r-- | wp-settings.php | 51 | ||||
-rw-r--r-- | wpmu-settings.php | 3 |
3 files changed, 38 insertions, 51 deletions
diff --git a/wp-includes/wp-db.php b/wp-includes/wp-db.php index bbef0cf..b7fb414 100644 --- a/wp-includes/wp-db.php +++ b/wp-includes/wp-db.php @@ -25,26 +25,35 @@ class wpdb { var $queries; var $prefix = ''; var $ready = false; + var $blogid = 0; + var $siteid = 0; + + // Global tables + var $blogs; + var $signups; + var $site; + var $sitemeta; + var $users; + var $usermeta; + var $sitecategories; + var $global_tables = array('blogs', 'signups', 'site', 'sitemeta', 'users', 'usermeta', 'sitecategories', 'registration_log', 'blog_versions'); - // Our tables + // Blog tables var $posts; - var $users; var $categories; var $post2cat; var $comments; var $links; var $options; var $postmeta; - var $usermeta; var $terms; var $term_taxonomy; var $term_relationships; - var $tables = array('users', 'usermeta', 'posts', 'categories', 'post2cat', 'comments', 'links', 'link2cat', 'options', + var $blog_tables = array('posts', 'categories', 'post2cat', 'comments', 'links', 'link2cat', 'options', 'postmeta', 'terms', 'term_taxonomy', 'term_relationships'); + var $charset; var $collate; - var $blog_tables = array('posts', 'categories', 'post2cat', 'comments', 'links', 'link2cat', 'options', 'postmeta', 'terms', 'term_taxonomy', 'term_relationships'); - /** * Connects to the database server and selects a database @@ -106,14 +115,20 @@ class wpdb { } function set_prefix($prefix) { - if ( preg_match('|[^a-z0-9_]|i', $prefix) ) return new WP_Error('invalid_db_prefix', 'Invalid database prefix'); // No gettext here - $old_prefix = $this->prefix; - $this->prefix = $prefix; + $old_prefix = $this->base_prefix; + $this->base_prefix = $prefix; + foreach ( $this->global_tables as $table ) + $this->$table = $prefix . $table; + + if ( empty($this->blogid) ) + return $old_prefix; - foreach ( $this->tables as $table ) + $this->prefix = $this->base_prefix . $this->blogid . '_'; + + foreach ( $this->blog_tables as $table ) $this->$table = $this->prefix . $table; if ( defined('CUSTOM_USER_TABLE') ) diff --git a/wp-settings.php b/wp-settings.php index e02c967..b81dc9a 100644 --- a/wp-settings.php +++ b/wp-settings.php @@ -201,68 +201,43 @@ if ( !defined('PLUGINDIR') ) require (ABSPATH . WPINC . '/compat.php'); require (ABSPATH . WPINC . '/functions.php'); -require (ABSPATH . WPINC . '/classes.php'); require_wp_db(); - +$wpdb->set_prefix($table_prefix); // set up global tables if ( !empty($wpdb->error) ) dead_db(); -$prefix = $wpdb->set_prefix($table_prefix); +if ( !defined( 'WP_INSTALLING' ) && file_exists(ABSPATH . 'wp-content/object-cache.php') ) + require_once (ABSPATH . 'wp-content/object-cache.php'); +else + require_once (ABSPATH . WPINC . '/cache.php'); -if ( is_wp_error($prefix) ) - wp_die('<strong>ERROR</strong>: <code>$table_prefix</code> in <code>wp-config.php</code> can only contain numbers, letters, and underscores.'); -// Table names. prefix is bare "wp_" -$wpdb->blogs = $wpdb->prefix . 'blogs'; -$wpdb->site = $wpdb->prefix . 'site'; -$wpdb->sitemeta = $wpdb->prefix . 'sitemeta'; -$wpdb->sitecategories = $wpdb->prefix . 'sitecategories'; -$wpdb->signups = $wpdb->prefix . 'signups'; -$wpdb->registration_log = $wpdb->prefix . 'registration_log'; -$wpdb->blog_versions = $wpdb->prefix . 'blog_versions'; +wp_cache_init(); if( defined( 'SUNRISE' ) ) include_once( ABSPATH . 'wp-content/sunrise.php' ); require_once ( ABSPATH . 'wpmu-settings.php' ); -$prefix = $table_prefix; -$wpdb->prefix = $table_prefix; // prefix now includes a blog_id -$wpdb->posts = $wpdb->prefix . 'posts'; -$wpdb->categories = $wpdb->prefix . 'categories'; -$wpdb->post2cat = $wpdb->prefix . 'post2cat'; -$wpdb->comments = $wpdb->prefix . 'comments'; -$wpdb->link2cat = $wpdb->prefix . 'link2cat'; -$wpdb->links = $wpdb->prefix . 'links'; -$wpdb->linkcategories = $wpdb->prefix . 'linkcategories'; -$wpdb->options = $wpdb->prefix . 'options'; -$wpdb->postmeta = $wpdb->prefix . 'postmeta'; -$wpdb->terms = $wpdb->prefix . 'terms'; -$wpdb->term_taxonomy = $wpdb->prefix . 'term_taxonomy'; -$wpdb->term_relationships = $wpdb->prefix . 'term_relationships'; -$wpdb->siteid = $current_blog->site_id; $wpdb->blogid = $current_blog->blog_id; +$wpdb->siteid = $current_blog->site_id; +$wpdb->set_prefix($table_prefix); // set up blog tables +$table_prefix = $table_prefix . $blog_id . '_'; +wp_cache_init(); // need to init cache again after blog_id is set if ( defined('CUSTOM_USER_TABLE') ) $wpdb->users = CUSTOM_USER_TABLE; if ( defined('CUSTOM_USER_META_TABLE') ) $wpdb->usermeta = CUSTOM_USER_META_TABLE; -if ( !defined( 'WP_INSTALLING' ) && file_exists(ABSPATH . 'wp-content/object-cache.php') ) - require_once (ABSPATH . 'wp-content/object-cache.php'); -else - require_once (ABSPATH . WPINC . '/cache.php'); - -wp_cache_init(); - if( !defined( "UPLOADS" ) ) define( "UPLOADS", "wp-content/blogs.dir/{$wpdb->blogid}/files/" ); -require (ABSPATH . WPINC . '/plugin.php'); -require (ABSPATH . WPINC . '/default-filters.php'); - if( defined( "SHORTINIT" ) && constant( "SHORTINIT" ) == true ) // stop most of WP being loaded, we just want the basics return; +require (ABSPATH . WPINC . '/classes.php'); +require (ABSPATH . WPINC . '/plugin.php'); +require (ABSPATH . WPINC . '/default-filters.php'); include_once(ABSPATH . WPINC . '/streams.php'); include_once(ABSPATH . WPINC . '/gettext.php'); require_once (ABSPATH . WPINC . '/l10n.php'); diff --git a/wpmu-settings.php b/wpmu-settings.php index da9802f..bc658f0 100644 --- a/wpmu-settings.php +++ b/wpmu-settings.php @@ -4,7 +4,6 @@ if( $current_site && $current_blog ) // depreciated
$wpmuBaseTablePrefix = $table_prefix;
-$wpdb->base_prefix = $table_prefix;
$domain = addslashes( $_SERVER['HTTP_HOST'] );
if( substr( $domain, 0, 4 ) == 'www.' )
@@ -208,6 +207,4 @@ function is_installed() { }
}
-$table_prefix = $table_prefix . $blog_id . '_';
-
?>
|