Make WordPress Core


Ignore:
Timestamp:
10/31/2007 03:59:18 AM (19 years ago)
Author:
ryan
Message:

wpdb::set_prefix(). fixes #5287

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/wp-db.php

    r6240 r6300  
    2121        var $col_info;
    2222        var $queries;
     23        var $prefix = '';
    2324
    2425        // Our tables
     
    3031        var $links;
    3132        var $options;
    32         var $optiontypes;
    33         var $optionvalues;
    34         var $optiongroups;
    35         var $optiongroup_options;
    3633        var $postmeta;
    3734        var $usermeta;
     
    3936        var $term_taxonomy;
    4037        var $term_relationships;
    41 
     38        var $tables = array('users', 'usermeta', 'posts', 'categories', 'post2cat', 'comments', 'links', 'link2cat', 'options',
     39                        'postmeta', 'terms', 'term_taxonomy', 'term_relationships');
    4240        var $charset;
    4341        var $collate;
     
    8583        function __destruct() {
    8684                return true;
     85        }
     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;
    87105        }
    88106
Note: See TracChangeset for help on using the changeset viewer.