Beginning of user system overhaul, TODO: update all code that deals with user data
git-svn-id: http://svn.automattic.com/wordpress/trunk@2631 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
a436e15576
commit
0c17753031
|
@ -9,6 +9,7 @@ function upgrade_all() {
|
|||
upgrade_101();
|
||||
upgrade_110();
|
||||
upgrade_130();
|
||||
upgrade_160();
|
||||
save_mod_rewrite_rules();
|
||||
}
|
||||
|
||||
|
@ -213,6 +214,44 @@ function upgrade_130() {
|
|||
make_site_theme();
|
||||
}
|
||||
|
||||
function upgrade_160() {
|
||||
global $wpdb, $table_prefix;
|
||||
$users = $wpdb->get_results("SELECT * FROM $wpdb->users");
|
||||
foreach ( $users as $user ) :
|
||||
if ( !empty( $user->user_firstname ) )
|
||||
update_usermeta( $user->ID, 'first_name', $user->user_firstname );
|
||||
if ( !empty( $user->user_lastname ) )
|
||||
update_usermeta( $user->ID, 'last_name', $user->user_lastname );
|
||||
if ( !empty( $user->user_nickname ) )
|
||||
update_usermeta( $user->ID, 'nickname', $user->user_nickname );
|
||||
if ( !empty( $user->user_level ) )
|
||||
update_usermeta( $user->ID, $table_prefix . 'user_level', $user->user_level );
|
||||
if ( !empty( $user->user_icq ) )
|
||||
update_usermeta( $user->ID, 'icq', $user->user_icq );
|
||||
if ( !empty( $user->user_aim ) )
|
||||
update_usermeta( $user->ID, 'aim', $user->user_aim );
|
||||
if ( !empty( $user->user_msn ) )
|
||||
update_usermeta( $user->ID, 'msn', $user->user_msn );
|
||||
if ( !empty( $user->user_yim ) )
|
||||
update_usermeta( $user->ID, 'yim', $user->user_icq );
|
||||
if ( !empty( $user->user_description ) )
|
||||
update_usermeta( $user->ID, 'description', $user->user_description );
|
||||
$idmode = $user->user_idmode;
|
||||
if ($idmode == 'nickname') $id = $user->user_nickname;
|
||||
if ($idmode == 'login') $id = $user->user_login;
|
||||
if ($idmode == 'firstname') $id = $user->user_firstname;
|
||||
if ($idmode == 'lastname') $id = $user->user_lastname;
|
||||
if ($idmode == 'namefl') $id = $user->user_firstname.' '.$user->user_lastname;
|
||||
if ($idmode == 'namelf') $id = $user->user_lastname.' '.$user->user_firstname;
|
||||
if (!$idmode) $id = $user->user_nickname;
|
||||
$id = addslashes( $id );
|
||||
$wpdb->query("UPDATE $wpdb->users SET display_name = '$id' WHERE ID = '$user->ID'");
|
||||
endforeach;
|
||||
$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' );
|
||||
foreach ( $old_user_fields as $old )
|
||||
$wpdb->query("ALTER TABLE $wpdb->users DROP $old");
|
||||
}
|
||||
|
||||
// The functions we use to actually do stuff
|
||||
|
||||
// General
|
||||
|
|
|
@ -91,7 +91,7 @@ CREATE TABLE $wpdb->postmeta (
|
|||
meta_id bigint(20) NOT NULL auto_increment,
|
||||
post_id bigint(20) NOT NULL default '0',
|
||||
meta_key varchar(255) default NULL,
|
||||
meta_value text,
|
||||
meta_value longtext,
|
||||
PRIMARY KEY (meta_id),
|
||||
KEY post_id (post_id),
|
||||
KEY meta_key (meta_key)
|
||||
|
@ -144,8 +144,18 @@ CREATE TABLE $wpdb->users (
|
|||
user_activation_key varchar(60) NOT NULL default '',
|
||||
user_status int(11) NOT NULL default '0',
|
||||
user_description longtext NOT NULL default '',
|
||||
display_name varchar(250) NOT NULL default '',
|
||||
PRIMARY KEY (ID),
|
||||
UNIQUE KEY user_login (user_login)
|
||||
);
|
||||
CREATE TABLE $wpdb->usermeta (
|
||||
umeta_id bigint(20) NOT NULL auto_increment,
|
||||
user_id bigint(20) NOT NULL default '0',
|
||||
meta_key varchar(255) default NULL,
|
||||
meta_value longtext,
|
||||
PRIMARY KEY (umeta_id),
|
||||
KEY user_id (user_id),
|
||||
KEY meta_key (meta_key)
|
||||
);";
|
||||
|
||||
function populate_options() {
|
||||
|
|
|
@ -1886,4 +1886,19 @@ function nocache_headers() {
|
|||
@ header('Pragma: no-cache');
|
||||
}
|
||||
|
||||
function update_usermeta( $user_id, $meta_key, $meta_value ) {
|
||||
global $wpdb;
|
||||
$user_id = (int) $user_id;
|
||||
$meta_key = preg_replace('|a-z0-9_|i', '', $meta_key);
|
||||
$cur = $wpdb->get_row("SELECT * FROM $wpdb->usermeta WHERE user_id = '$user_id' AND meta_key = '$meta_key'");
|
||||
if ( !$cur ) {
|
||||
$wpdb->query("INSERT INTO $wpdb->usermeta ( user_id, meta_key, meta_value )
|
||||
VALUES
|
||||
( '$user_id', '$meta_key', '$meta_value' )");
|
||||
return true;
|
||||
}
|
||||
if ( $cur->meta_value != $meta_value )
|
||||
$wpdb->query("UPDATE $wpdb->usermeta SET meta_value = '$meta_value' WHERE user_id = '$user_id' AND meta_key = '$meta_key'");
|
||||
}
|
||||
|
||||
?>
|
|
@ -31,29 +31,42 @@ function get_currentuserinfo() {
|
|||
endif;
|
||||
|
||||
if ( !function_exists('get_userdata') ) :
|
||||
function get_userdata($userid) {
|
||||
function get_userdata( $user_id ) {
|
||||
global $wpdb, $cache_userdata;
|
||||
$userid = (int) $userid;
|
||||
if ( empty($cache_userdata[$userid]) && $userid != 0) {
|
||||
$cache_userdata[$userid] = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE ID = $userid");
|
||||
$cache_userdata[$cache_userdata[$userid]->user_login] =& $cache_userdata[$userid];
|
||||
}
|
||||
$user_id = (int) $user_id;
|
||||
if ( $user_id == 0 )
|
||||
return false;
|
||||
|
||||
return $cache_userdata[$userid];
|
||||
if ( isset( $cache_userdata[$user_id] ) )
|
||||
return $cache_userdata[$user_id];
|
||||
|
||||
if ( !$user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE ID = '$user_id'") )
|
||||
return $cache_userdata[$user_id] = false;
|
||||
|
||||
$metavalues = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = '$user_id'");
|
||||
|
||||
foreach ( $metavalues as $meta )
|
||||
$user->{$meta->meta_key} = $meta->meta_value;
|
||||
|
||||
die(var_dump($user));
|
||||
$cache_userdata[$cache_userdata[$userid]->user_login] =& $cache_userdata[$user_id];
|
||||
|
||||
return $cache_userdata[$user_id];
|
||||
}
|
||||
endif;
|
||||
|
||||
if ( !function_exists('get_userdatabylogin') ) :
|
||||
function get_userdatabylogin($user_login) {
|
||||
global $cache_userdata, $wpdb;
|
||||
if ( !empty($user_login) && empty($cache_userdata[$user_login]) ) {
|
||||
$user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE user_login = '$user_login'"); /* todo: get rid of this intermediate var */
|
||||
$cache_userdata[$user->ID] = $user;
|
||||
$cache_userdata[$user_login] =& $cache_userdata[$user->ID];
|
||||
} else {
|
||||
$user = $cache_userdata[$user_login];
|
||||
}
|
||||
return $user;
|
||||
$user_login = addslashes( $user_login );
|
||||
if ( empty( $user_login ) )
|
||||
return false;
|
||||
if ( isset( $cache_userdata[$user_login] ) )
|
||||
return $cache_userdata[$user_login];
|
||||
|
||||
$user_id = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_login = '$user_login'");
|
||||
|
||||
return get_userdata( $user_id );
|
||||
}
|
||||
endif;
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@ $wpdb->links = $table_prefix . 'links';
|
|||
$wpdb->linkcategories = $table_prefix . 'linkcategories';
|
||||
$wpdb->options = $table_prefix . 'options';
|
||||
$wpdb->postmeta = $table_prefix . 'postmeta';
|
||||
$wpdb->usermeta = $table_prefix . 'usermeta';
|
||||
|
||||
if ( defined('CUSTOM_USER_TABLE') )
|
||||
$wpdb->users = CUSTOM_USER_TABLE;
|
||||
|
|
Loading…
Reference in New Issue