From d85d86db038073a482b0b8d260f2972ba0a96d62 Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 31 Oct 2007 03:59:18 +0000 Subject: [PATCH] wpdb::set_prefix(). fixes #5287 git-svn-id: http://svn.automattic.com/wordpress/trunk@6300 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/wp-db.php | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/wp-includes/wp-db.php b/wp-includes/wp-db.php index 5713104f5..89cd2b2d1 100644 --- a/wp-includes/wp-db.php +++ b/wp-includes/wp-db.php @@ -20,6 +20,7 @@ class wpdb { var $last_query; var $col_info; var $queries; + var $prefix = ''; // Our tables var $posts; @@ -29,16 +30,13 @@ class wpdb { var $comments; var $links; var $options; - var $optiontypes; - var $optionvalues; - var $optiongroups; - var $optiongroup_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', + 'postmeta', 'terms', 'term_taxonomy', 'term_relationships'); var $charset; var $collate; @@ -86,6 +84,26 @@ class wpdb { return true; } + 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; + + foreach ( $this->tables as $table ) + $this->$table = $this->prefix . $table; + + if ( defined('CUSTOM_USER_TABLE') ) + $this->users = CUSTOM_USER_TABLE; + + if ( defined('CUSTOM_USER_META_TABLE') ) + $this->usermeta = CUSTOM_USER_META_TABLE; + + return $old_prefix; + } + /** * Selects a database using the current class's $this->dbh * @param string $db name