Ticket #5287: set_prefix.diff
| File set_prefix.diff, 3.3 KB (added by , 18 years ago) |
|---|
-
wp-includes/wp-db.php
20 20 var $last_query; 21 21 var $col_info; 22 22 var $queries; 23 var $prefix = ''; 23 24 24 25 // Our tables 25 26 var $posts; … … 29 30 var $comments; 30 31 var $links; 31 32 var $options; 32 var $optiontypes;33 var $optionvalues;34 var $optiongroups;35 var $optiongroup_options;36 33 var $postmeta; 37 34 var $usermeta; 38 35 var $terms; 39 36 var $term_taxonomy; 40 37 var $term_relationships; 41 38 var $tables = array('users', 'usermeta', 'posts', 'categories', 'post2cat', 'comments', 'links', 'link2cat', 'options', 39 'postmeta', 'terms', 'term_taxonomy', 'term_relationships'); 42 40 var $charset; 43 41 var $collate; 44 42 … … 86 84 return true; 87 85 } 88 86 87 function set_prefix($prefix) { 88 89 if ( preg_match('|[^a-z0-9_]|i', $prefix) ) 90 return new WP_Error('invalid_db_prefix', 'Invalid database prefix'); // No gettext here 91 92 $old_prefix = $this->prefix; 93 $this->prefix = $prefix; 94 95 foreach ( $this->tables as $table ) 96 $this->$table = $this->prefix . $table; 97 98 if ( defined('CUSTOM_USER_TABLE') ) 99 $this->users = CUSTOM_USER_TABLE; 100 101 if ( defined('CUSTOM_USER_META_TABLE') ) 102 $this->usermeta = CUSTOM_USER_META_TABLE; 103 104 return $old_prefix; 105 } 106 89 107 /** 90 108 * Selects a database using the current class's $this->dbh 91 109 * @param string $db name -
wp-settings.php
118 118 119 119 require (ABSPATH . WPINC . '/compat.php'); 120 120 require (ABSPATH . WPINC . '/functions.php'); 121 require (ABSPATH . WPINC . '/classes.php'); 121 122 122 123 require_wp_db(); 123 // $table_prefix is deprecated as of 2.1 124 $wpdb->prefix = $table_prefix; 124 $prefix = $wpdb->set_prefix($table_prefix); 125 125 126 if ( preg_match('|[^a-z0-9_]|i', $wpdb->prefix) && !file_exists(ABSPATH . 'wp-content/db.php') )126 if ( is_wp_error($prefix) ) 127 127 wp_die("<strong>ERROR</strong>: <code>$table_prefix</code> in <code>wp-config.php</code> can only contain numbers, letters, and underscores."); 128 128 129 // Table names130 $wpdb->posts = $wpdb->prefix . 'posts';131 $wpdb->users = $wpdb->prefix . 'users';132 $wpdb->categories = $wpdb->prefix . 'categories';133 $wpdb->post2cat = $wpdb->prefix . 'post2cat';134 $wpdb->comments = $wpdb->prefix . 'comments';135 $wpdb->link2cat = $wpdb->prefix . 'link2cat';136 $wpdb->links = $wpdb->prefix . 'links';137 $wpdb->options = $wpdb->prefix . 'options';138 $wpdb->postmeta = $wpdb->prefix . 'postmeta';139 $wpdb->usermeta = $wpdb->prefix . 'usermeta';140 $wpdb->terms = $wpdb->prefix . 'terms';141 $wpdb->term_taxonomy = $wpdb->prefix . 'term_taxonomy';142 $wpdb->term_relationships = $wpdb->prefix . 'term_relationships';143 144 if ( defined('CUSTOM_USER_TABLE') )145 $wpdb->users = CUSTOM_USER_TABLE;146 if ( defined('CUSTOM_USER_META_TABLE') )147 $wpdb->usermeta = CUSTOM_USER_META_TABLE;148 149 129 if ( file_exists(ABSPATH . 'wp-content/object-cache.php') ) 150 130 require_once (ABSPATH . 'wp-content/object-cache.php'); 151 131 else … … 153 133 154 134 wp_cache_init(); 155 135 156 require (ABSPATH . WPINC . '/classes.php');157 136 require (ABSPATH . WPINC . '/plugin.php'); 158 137 require (ABSPATH . WPINC . '/default-filters.php'); 159 138 include_once(ABSPATH . WPINC . '/streams.php');