From 8e29dfa495ef99b22dc8ed774627be976cb3c981 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Wed, 31 Oct 2007 03:59:18 +0000 Subject: [PATCH] wpdb::set_prefix(). fixes #5287 git-svn-id: https://develop.svn.wordpress.org/trunk@6300 602fd350-edb4-49c9-b593-d223f7449a82 --- 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 5713104f5e..89cd2b2d1d 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