From df35b1041bfa4efcfce0d386493328d1bbe77cd0 Mon Sep 17 00:00:00 2001 From: ryan Date: Fri, 3 Mar 2006 17:19:05 +0000 Subject: [PATCH] Use table prefix from wpdb. Props Mark J. #2524 git-svn-id: http://svn.automattic.com/wordpress/trunk@3603 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/install.php | 4 ++-- wp-admin/upgrade-functions.php | 22 +++++++++++----------- wp-content/plugins/wp-db-backup.php | 18 +++++++++--------- wp-includes/capabilities.php | 12 ++++++------ 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/wp-admin/install.php b/wp-admin/install.php index 88f1d86a40..3774b118a9 100644 --- a/wp-admin/install.php +++ b/wp-admin/install.php @@ -202,9 +202,9 @@ $random_password = substr(md5(uniqid(microtime())), 0, 6); $display_name_array = explode('@', $admin_email); $display_name = $display_name_array[0]; $wpdb->query("INSERT INTO $wpdb->users (ID, user_login, user_pass, user_email, user_registered, display_name, user_nicename) VALUES ( '1', 'admin', MD5('$random_password'), '$admin_email', NOW(), '$display_name', 'admin')"); -$wpdb->query("INSERT INTO $wpdb->usermeta (user_id, meta_key, meta_value) VALUES ({$wpdb->insert_id}, '{$table_prefix}user_level', '10');"); +$wpdb->query("INSERT INTO $wpdb->usermeta (user_id, meta_key, meta_value) VALUES ({$wpdb->insert_id}, '{$wpdb->table_prefix}user_level', '10');"); $admin_caps = serialize(array('administrator' => true)); -$wpdb->query("INSERT INTO $wpdb->usermeta (user_id, meta_key, meta_value) VALUES ({$wpdb->insert_id}, '{$table_prefix}capabilities', '{$admin_caps}');"); +$wpdb->query("INSERT INTO $wpdb->usermeta (user_id, meta_key, meta_value) VALUES ({$wpdb->insert_id}, '{$wpdb->table_prefix}capabilities', '{$admin_caps}');"); $message_headers = 'From: ' . $weblog_title . ' '; $message = sprintf(__("Your new WordPress blog has been successfully set up at: diff --git a/wp-admin/upgrade-functions.php b/wp-admin/upgrade-functions.php index 71390ed62b..2266210fff 100644 --- a/wp-admin/upgrade-functions.php +++ b/wp-admin/upgrade-functions.php @@ -167,7 +167,7 @@ function upgrade_110() { } function upgrade_130() { - global $wpdb, $table_prefix; + global $wpdb; // Remove extraneous backslashes. $posts = $wpdb->get_results("SELECT ID, post_title, post_content, post_excerpt, guid, post_date, post_name, post_status, post_author FROM $wpdb->posts"); @@ -220,10 +220,10 @@ function upgrade_130() { } // Obsolete tables - $wpdb->query('DROP TABLE IF EXISTS ' . $table_prefix . 'optionvalues'); - $wpdb->query('DROP TABLE IF EXISTS ' . $table_prefix . 'optiontypes'); - $wpdb->query('DROP TABLE IF EXISTS ' . $table_prefix . 'optiongroups'); - $wpdb->query('DROP TABLE IF EXISTS ' . $table_prefix . 'optiongroup_options'); + $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->table_prefix . 'optionvalues'); + $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->table_prefix . 'optiontypes'); + $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->table_prefix . 'optiongroups'); + $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->table_prefix . 'optiongroup_options'); // Update comments table to use comment_type $wpdb->query("UPDATE $wpdb->comments SET comment_type='trackback', comment_content = REPLACE(comment_content, '', '') WHERE comment_content LIKE '%'"); @@ -244,7 +244,7 @@ function upgrade_130() { } function upgrade_160() { - global $wpdb, $table_prefix, $wp_current_db_version; + global $wpdb, $wp_current_db_version; populate_roles_160(); @@ -257,7 +257,7 @@ function upgrade_160() { if ( !empty( $user->user_nickname ) ) update_usermeta( $user->ID, 'nickname', $wpdb->escape($user->user_nickname) ); if ( !empty( $user->user_level ) ) - update_usermeta( $user->ID, $table_prefix . 'user_level', $user->user_level ); + update_usermeta( $user->ID, $wpdb->table_prefix . 'user_level', $user->user_level ); if ( !empty( $user->user_icq ) ) update_usermeta( $user->ID, 'icq', $wpdb->escape($user->user_icq) ); if ( !empty( $user->user_aim ) ) @@ -283,11 +283,11 @@ function upgrade_160() { endif; // FIXME: RESET_CAPS is temporary code to reset roles and caps if flag is set. - $caps = get_usermeta( $user->ID, $table_prefix . 'capabilities'); + $caps = get_usermeta( $user->ID, $wpdb->table_prefix . 'capabilities'); if ( empty($caps) || defined('RESET_CAPS') ) { - $level = get_usermeta($user->ID, $table_prefix . 'user_level'); + $level = get_usermeta($user->ID, $wpdb->table_prefix . 'user_level'); $role = translate_level_to_role($level); - update_usermeta( $user->ID, $table_prefix . 'capabilities', array($role => true) ); + update_usermeta( $user->ID, $wpdb->table_prefix . 'capabilities', array($role => true) ); } endforeach; @@ -331,7 +331,7 @@ function upgrade_160() { } function upgrade_210() { - global $wpdb, $table_prefix, $wp_current_db_version; + global $wpdb, $wp_current_db_version; if ( $wp_current_db_version < 3506 ) { // Update status and type. diff --git a/wp-content/plugins/wp-db-backup.php b/wp-content/plugins/wp-db-backup.php index b328608328..a5d0f09030 100644 --- a/wp-content/plugins/wp-db-backup.php +++ b/wp-content/plugins/wp-db-backup.php @@ -103,10 +103,10 @@ class wpdbBackup { } function build_backup_script() { - global $table_prefix, $wpdb; + global $wpdb; $datum = date("Ymd_B"); - $backup_filename = DB_NAME . "_$table_prefix$datum.sql"; + $backup_filename = DB_NAME . '_' . $wpdb->table_prefix . $datum . '.sql'; if ($this->gzip()) $backup_filename .= '.gz'; echo "
"; @@ -223,7 +223,7 @@ class wpdbBackup { } function backup_fragment($table, $segment, $filename) { - global $table_prefix, $wpdb; + global $wpdb; echo "$table:$segment:$filename"; @@ -555,10 +555,10 @@ class wpdbBackup { //////////////////////////// function db_backup($core_tables, $other_tables) { - global $table_prefix, $wpdb; + global $wpdb; $datum = date("Ymd_B"); - $wp_backup_filename = DB_NAME . "_$table_prefix$datum.sql"; + $wp_backup_filename = DB_NAME . '_' . $wpdb->table_prefix . $datum . '.sql'; if ($this->gzip()) { $wp_backup_filename .= '.gz'; } @@ -672,7 +672,7 @@ class wpdbBackup { //////////////////////////// function backup_menu() { - global $table_prefix, $wpdb; + global $wpdb; $feedback = ''; $WHOOPS = FALSE; @@ -720,7 +720,7 @@ class wpdbBackup { // Simple table name storage $wp_table_names = explode(',','categories,comments,linkcategories,links,options,post2cat,postmeta,posts,users,usermeta'); // Apply WP DB prefix to table names - $wp_table_names = array_map(create_function('$a', 'global $table_prefix;return "{$table_prefix}{$a}";'), $wp_table_names); + $wp_table_names = array_map(create_function('$a', 'global $wpdb;return "{$wpdb->table_prefix}{$a}";'), $wp_table_names); $other_tables = array(); $also_backup = array(); @@ -864,10 +864,10 @@ class wpdbBackup { return; } - global $table_prefix, $wpdb; + global $wpdb; $wp_table_names = explode(',','categories,comments,linkcategories,links,options,post2cat,postmeta,posts,users,usermeta'); - $wp_table_names = array_map(create_function('$a', 'global $table_prefix;return "{$table_prefix}{$a}";'), $wp_table_names); + $wp_table_names = array_map(create_function('$a', 'global $wpdb;return "{$wpdb->table_prefix}{$a}";'), $wp_table_names); $all_tables = $wpdb->get_results("SHOW TABLES", ARRAY_N); $all_tables = array_map(create_function('$a', 'return $a[0];'), $all_tables); $core_tables = array_intersect($all_tables, $wp_table_names); diff --git a/wp-includes/capabilities.php b/wp-includes/capabilities.php index fee7940ed6..41eb84987c 100644 --- a/wp-includes/capabilities.php +++ b/wp-includes/capabilities.php @@ -8,8 +8,8 @@ class WP_Roles { var $role_key; function WP_Roles() { - global $table_prefix; - $this->role_key = $table_prefix . 'user_roles'; + global $wpdb; + $this->role_key = $wpdb->table_prefix . 'user_roles'; $this->roles = get_option($this->role_key); @@ -121,7 +121,7 @@ class WP_User { var $allcaps = array(); function WP_User($id, $name = '') { - global $table_prefix; + global $wpdb; if ( empty($id) && empty($name) ) return; @@ -144,7 +144,7 @@ class WP_User { } $this->id = $this->ID; - $this->cap_key = $table_prefix . 'capabilities'; + $this->cap_key = $wpdb->table_prefix . 'capabilities'; $this->caps = &$this->{$this->cap_key}; if ( ! is_array($this->caps) ) $this->caps = array(); @@ -205,9 +205,9 @@ class WP_User { } function update_user_level_from_caps() { - global $table_prefix; + global $wpdb; $this->user_level = array_reduce(array_keys($this->allcaps), array(&$this, 'level_reduction'), 0); - update_usermeta($this->id, $table_prefix.'user_level', $this->user_level); + update_usermeta($this->id, $wpdb->table_prefix.'user_level', $this->user_level); } function add_cap($cap, $grant = true) {