Make WordPress Core

Ticket #2524: table_prefix.diff

File table_prefix.diff, 8.0 KB (added by markjaquith, 20 years ago)
  • wp-includes/capabilities.php

     
    88        var $role_key;
    99
    1010        function WP_Roles() {
    11                 global $table_prefix;
    12                 $this->role_key = $table_prefix . 'user_roles';
     11                global $wpdb;
     12                $this->role_key = $wpdb->table_prefix . 'user_roles';
    1313
    1414                $this->roles = get_option($this->role_key);
    1515
     
    121121        var $allcaps = array();
    122122
    123123        function WP_User($id, $name = '') {
    124                 global $table_prefix;
     124                global $wpdb;
    125125
    126126                if ( empty($id) && empty($name) )
    127127                        return;
     
    144144                }
    145145
    146146                $this->id = $this->ID;
    147                 $this->cap_key = $table_prefix . 'capabilities';
     147                $this->cap_key = $wpdb->table_prefix . 'capabilities';
    148148                $this->caps = &$this->{$this->cap_key};
    149149                if ( ! is_array($this->caps) )
    150150                        $this->caps = array();
     
    205205        }
    206206
    207207        function update_user_level_from_caps() {
    208             global $table_prefix;
     208            global $wpdb;
    209209            $this->user_level = array_reduce(array_keys($this->allcaps),        array(&$this, 'level_reduction'), 0);
    210             update_usermeta($this->id, $table_prefix.'user_level', $this->user_level);
     210            update_usermeta($this->id, $wpdb->table_prefix.'user_level', $this->user_level);
    211211        }
    212212
    213213        function add_cap($cap, $grant = true) {
  • wp-content/plugins/wp-db-backup.php

     
    103103        }
    104104
    105105        function build_backup_script() {
    106                 global $table_prefix, $wpdb;
     106                global $wpdb;
    107107
    108108                $datum = date("Ymd_B");
    109                 $backup_filename = DB_NAME . "_$table_prefix$datum.sql";
     109                $backup_filename = DB_NAME . '_' . $wpdb->table_prefix . $datum . '.sql';
    110110                if ($this->gzip()) $backup_filename .= '.gz';
    111111
    112112                echo "<div class='wrap'>";
     
    223223        }
    224224
    225225        function backup_fragment($table, $segment, $filename) {
    226                 global $table_prefix, $wpdb;
     226                global $wpdb;
    227227
    228228                echo "$table:$segment:$filename";
    229229
     
    555555
    556556        ////////////////////////////
    557557        function db_backup($core_tables, $other_tables) {
    558                 global $table_prefix, $wpdb;
     558                global $wpdb;
    559559
    560560                $datum = date("Ymd_B");
    561                 $wp_backup_filename = DB_NAME . "_$table_prefix$datum.sql";
     561                $wp_backup_filename = DB_NAME . '_' . $wpdb->table_prefix . $datum . '.sql';
    562562                        if ($this->gzip()) {
    563563                                $wp_backup_filename .= '.gz';
    564564                        }
     
    672672
    673673        ////////////////////////////
    674674        function backup_menu() {
    675                 global $table_prefix, $wpdb;
     675                global $wpdb;
    676676                $feedback = '';
    677677                $WHOOPS = FALSE;
    678678
     
    720720                // Simple table name storage
    721721                $wp_table_names = explode(',','categories,comments,linkcategories,links,options,post2cat,postmeta,posts,users,usermeta');
    722722                // Apply WP DB prefix to table names
    723                 $wp_table_names = array_map(create_function('$a', 'global $table_prefix;return "{$table_prefix}{$a}";'), $wp_table_names);
     723                $wp_table_names = array_map(create_function('$a', 'global $wpdb;return "{$wpdb->table_prefix}{$a}";'), $wp_table_names);
    724724
    725725                $other_tables = array();
    726726                $also_backup = array();
     
    864864                        return;
    865865                }
    866866
    867                 global $table_prefix, $wpdb;
     867                global $wpdb;
    868868
    869869                $wp_table_names = explode(',','categories,comments,linkcategories,links,options,post2cat,postmeta,posts,users,usermeta');
    870                 $wp_table_names = array_map(create_function('$a', 'global $table_prefix;return "{$table_prefix}{$a}";'), $wp_table_names);
     870                $wp_table_names = array_map(create_function('$a', 'global $wpdb;return "{$wpdb->table_prefix}{$a}";'), $wp_table_names);
    871871                $all_tables = $wpdb->get_results("SHOW TABLES", ARRAY_N);
    872872                $all_tables = array_map(create_function('$a', 'return $a[0];'), $all_tables);
    873873                $core_tables = array_intersect($all_tables, $wp_table_names);
  • wp-admin/upgrade-functions.php

     
    167167}
    168168
    169169function upgrade_130() {
    170     global $wpdb, $table_prefix;
     170    global $wpdb;
    171171
    172172    // Remove extraneous backslashes.
    173173        $posts = $wpdb->get_results("SELECT ID, post_title, post_content, post_excerpt, guid, post_date, post_name, post_status, post_author FROM $wpdb->posts");
     
    220220                }
    221221
    222222        // Obsolete tables
    223         $wpdb->query('DROP TABLE IF EXISTS ' . $table_prefix . 'optionvalues');
    224         $wpdb->query('DROP TABLE IF EXISTS ' . $table_prefix . 'optiontypes');
    225         $wpdb->query('DROP TABLE IF EXISTS ' . $table_prefix . 'optiongroups');
    226         $wpdb->query('DROP TABLE IF EXISTS ' . $table_prefix . 'optiongroup_options');
     223        $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->table_prefix . 'optionvalues');
     224        $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->table_prefix . 'optiontypes');
     225        $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->table_prefix . 'optiongroups');
     226        $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->table_prefix . 'optiongroup_options');
    227227
    228228        // Update comments table to use comment_type
    229229        $wpdb->query("UPDATE $wpdb->comments SET comment_type='trackback', comment_content = REPLACE(comment_content, '<trackback />', '') WHERE comment_content LIKE '<trackback />%'");
     
    244244}
    245245
    246246function upgrade_160() {
    247         global $wpdb, $table_prefix, $wp_current_db_version;
     247        global $wpdb, $wp_current_db_version;
    248248
    249249        populate_roles_160();
    250250
     
    257257                if ( !empty( $user->user_nickname ) )
    258258                        update_usermeta( $user->ID, 'nickname', $wpdb->escape($user->user_nickname) );
    259259                if ( !empty( $user->user_level ) )
    260                         update_usermeta( $user->ID, $table_prefix . 'user_level', $user->user_level );
     260                        update_usermeta( $user->ID, $wpdb->table_prefix . 'user_level', $user->user_level );
    261261                if ( !empty( $user->user_icq ) )
    262262                        update_usermeta( $user->ID, 'icq', $wpdb->escape($user->user_icq) );
    263263                if ( !empty( $user->user_aim ) )
     
    283283                endif;
    284284
    285285                // FIXME: RESET_CAPS is temporary code to reset roles and caps if flag is set.
    286                 $caps = get_usermeta( $user->ID, $table_prefix . 'capabilities');
     286                $caps = get_usermeta( $user->ID, $wpdb->table_prefix . 'capabilities');
    287287                if ( empty($caps) || defined('RESET_CAPS') ) {
    288                         $level = get_usermeta($user->ID, $table_prefix . 'user_level');
     288                        $level = get_usermeta($user->ID, $wpdb->table_prefix . 'user_level');
    289289                        $role = translate_level_to_role($level);
    290                         update_usermeta( $user->ID, $table_prefix . 'capabilities', array($role => true) );
     290                        update_usermeta( $user->ID, $wpdb->table_prefix . 'capabilities', array($role => true) );
    291291                }
    292292
    293293        endforeach;
     
    331331}
    332332
    333333function upgrade_210() {
    334         global $wpdb, $table_prefix, $wp_current_db_version;
     334        global $wpdb, $wp_current_db_version;
    335335
    336336        if ( $wp_current_db_version < 3506 ) {
    337337                // Update status and type.
  • wp-admin/install.php

     
    202202$display_name_array = explode('@', $admin_email);
    203203$display_name = $display_name_array[0];
    204204$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')");
    205 $wpdb->query("INSERT INTO $wpdb->usermeta (user_id, meta_key, meta_value) VALUES ({$wpdb->insert_id}, '{$table_prefix}user_level', '10');");
     205$wpdb->query("INSERT INTO $wpdb->usermeta (user_id, meta_key, meta_value) VALUES ({$wpdb->insert_id}, '{prefix}user_level', '10');");
    206206$admin_caps = serialize(array('administrator' => true));
    207 $wpdb->query("INSERT INTO $wpdb->usermeta (user_id, meta_key, meta_value) VALUES ({$wpdb->insert_id}, '{$table_prefix}capabilities', '{$admin_caps}');");
     207$wpdb->query("INSERT INTO $wpdb->usermeta (user_id, meta_key, meta_value) VALUES ({$wpdb->insert_id}, '{prefix}capabilities', '{$admin_caps}');");
    208208
    209209$message_headers = 'From: ' . $weblog_title . ' <wordpress@' . $_SERVER['SERVER_NAME'] . '>';
    210210$message = sprintf(__("Your new WordPress blog has been successfully set up at: