Make WordPress Core

Changeset 2631


Ignore:
Timestamp:
06/12/2005 08:49:13 PM (19 years ago)
Author:
matt
Message:

Beginning of user system overhaul, TODO: update all code that deals with user data

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/upgrade-functions.php

    r2488 r2631  
    1010    upgrade_110();
    1111    upgrade_130();
     12    upgrade_160();
    1213    save_mod_rewrite_rules();
    1314}
     
    212213
    213214    make_site_theme();
     215}
     216
     217function upgrade_160() {
     218    global $wpdb, $table_prefix;
     219    $users = $wpdb->get_results("SELECT * FROM $wpdb->users");
     220    foreach ( $users as $user ) :
     221        if ( !empty( $user->user_firstname ) )
     222            update_usermeta( $user->ID, 'first_name', $user->user_firstname );
     223        if ( !empty( $user->user_lastname ) )
     224            update_usermeta( $user->ID, 'last_name', $user->user_lastname );
     225        if ( !empty( $user->user_nickname ) )
     226            update_usermeta( $user->ID, 'nickname', $user->user_nickname );
     227        if ( !empty( $user->user_level ) )
     228            update_usermeta( $user->ID, $table_prefix . 'user_level', $user->user_level );
     229        if ( !empty( $user->user_icq ) )
     230            update_usermeta( $user->ID, 'icq', $user->user_icq );
     231        if ( !empty( $user->user_aim ) )
     232            update_usermeta( $user->ID, 'aim', $user->user_aim );
     233        if ( !empty( $user->user_msn ) )
     234            update_usermeta( $user->ID, 'msn', $user->user_msn );
     235        if ( !empty( $user->user_yim ) )
     236            update_usermeta( $user->ID, 'yim', $user->user_icq );
     237        if ( !empty( $user->user_description ) )
     238            update_usermeta( $user->ID, 'description', $user->user_description );
     239        $idmode = $user->user_idmode;
     240        if ($idmode == 'nickname') $id = $user->user_nickname;
     241        if ($idmode == 'login') $id = $user->user_login;
     242        if ($idmode == 'firstname') $id = $user->user_firstname;
     243        if ($idmode == 'lastname') $id = $user->user_lastname;
     244        if ($idmode == 'namefl') $id = $user->user_firstname.' '.$user->user_lastname;
     245        if ($idmode == 'namelf') $id = $user->user_lastname.' '.$user->user_firstname;
     246        if (!$idmode) $id = $user->user_nickname;
     247        $id = addslashes( $id );
     248        $wpdb->query("UPDATE $wpdb->users SET display_name = '$id' WHERE ID = '$user->ID'");
     249    endforeach;
     250    $old_user_fields = array( 'user_firstname', 'user_lastname', 'user_icq', 'user_aim', 'user_msn', 'user_yim', 'user_idmode', 'user_ip', 'user_domain', 'user_browser', 'user_description', 'user_nickname' );
     251    foreach ( $old_user_fields as $old )
     252        $wpdb->query("ALTER TABLE $wpdb->users DROP $old");
    214253}
    215254
  • trunk/wp-admin/upgrade-schema.php

    r2629 r2631  
    9292  post_id bigint(20) NOT NULL default '0',
    9393  meta_key varchar(255) default NULL,
    94   meta_value text,
     94  meta_value longtext,
    9595  PRIMARY KEY  (meta_id),
    9696  KEY post_id (post_id),
     
    145145  user_status int(11) NOT NULL default '0',
    146146  user_description longtext NOT NULL default '',
     147  display_name varchar(250) NOT NULL default '',
    147148  PRIMARY KEY  (ID),
    148149  UNIQUE KEY user_login (user_login)
     150);
     151CREATE TABLE $wpdb->usermeta (
     152  umeta_id bigint(20) NOT NULL auto_increment,
     153  user_id bigint(20) NOT NULL default '0',
     154  meta_key varchar(255) default NULL,
     155  meta_value longtext,
     156  PRIMARY KEY  (umeta_id),
     157  KEY user_id (user_id),
     158  KEY meta_key (meta_key)
    149159);";
    150160
  • trunk/wp-includes/functions.php

    r2627 r2631  
    18871887}
    18881888
     1889function update_usermeta( $user_id, $meta_key, $meta_value ) {
     1890    global $wpdb;
     1891    $user_id = (int) $user_id;
     1892    $meta_key = preg_replace('|a-z0-9_|i', '', $meta_key);
     1893    $cur = $wpdb->get_row("SELECT * FROM $wpdb->usermeta WHERE user_id = '$user_id' AND meta_key = '$meta_key'");
     1894    if ( !$cur ) {
     1895        $wpdb->query("INSERT INTO $wpdb->usermeta ( user_id, meta_key, meta_value )
     1896        VALUES
     1897        ( '$user_id', '$meta_key', '$meta_value' )");
     1898        return true;
     1899    }
     1900    if ( $cur->meta_value != $meta_value )
     1901        $wpdb->query("UPDATE $wpdb->usermeta SET meta_value = '$meta_value' WHERE user_id = '$user_id' AND meta_key = '$meta_key'");
     1902}
     1903
    18891904?>
  • trunk/wp-includes/pluggable-functions.php

    r2623 r2631  
    3232
    3333if ( !function_exists('get_userdata') ) :
    34 function get_userdata($userid) {
     34function get_userdata( $user_id ) {
    3535    global $wpdb, $cache_userdata;
    36     $userid = (int) $userid;
    37     if ( empty($cache_userdata[$userid]) && $userid != 0) {
    38         $cache_userdata[$userid] = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE ID = $userid");
    39         $cache_userdata[$cache_userdata[$userid]->user_login] =& $cache_userdata[$userid];
    40     }
    41 
    42     return $cache_userdata[$userid];
     36    $user_id = (int) $user_id;
     37    if ( $user_id == 0 )
     38        return false;
     39
     40    if ( isset( $cache_userdata[$user_id] ) )
     41        return $cache_userdata[$user_id];
     42
     43    if ( !$user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE ID = '$user_id'") )
     44        return $cache_userdata[$user_id] = false;
     45
     46    $metavalues = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = '$user_id'");
     47
     48    foreach ( $metavalues as $meta )
     49        $user->{$meta->meta_key} = $meta->meta_value;
     50
     51    die(var_dump($user));
     52    $cache_userdata[$cache_userdata[$userid]->user_login] =& $cache_userdata[$user_id];
     53
     54    return $cache_userdata[$user_id];
    4355}
    4456endif;
     
    4759function get_userdatabylogin($user_login) {
    4860    global $cache_userdata, $wpdb;
    49     if ( !empty($user_login) && empty($cache_userdata[$user_login]) ) {
    50         $user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE user_login = '$user_login'"); /* todo: get rid of this intermediate var */
    51         $cache_userdata[$user->ID] = $user;
    52         $cache_userdata[$user_login] =& $cache_userdata[$user->ID];
    53     } else {
    54         $user = $cache_userdata[$user_login];
    55     }
    56     return $user;
     61    $user_login = addslashes( $user_login );
     62    if ( empty( $user_login ) )
     63        return false;
     64    if ( isset( $cache_userdata[$user_login] ) )
     65        return $cache_userdata[$user_login];
     66   
     67    $user_id = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_login = '$user_login'");
     68
     69    return get_userdata( $user_id );
    5770}
    5871endif;
  • trunk/wp-settings.php

    r2627 r2631  
    4949$wpdb->options          = $table_prefix . 'options';
    5050$wpdb->postmeta         = $table_prefix . 'postmeta';
     51$wpdb->usermeta         = $table_prefix . 'usermeta';
    5152
    5253if ( defined('CUSTOM_USER_TABLE') )
Note: See TracChangeset for help on using the changeset viewer.