Refactor level to cap upgrade code.

git-svn-id: http://svn.automattic.com/wordpress/trunk@2727 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2005-07-19 14:24:06 +00:00
parent 6a30e8033f
commit 9bca3f5db6
2 changed files with 11 additions and 6 deletions

View File

@ -226,11 +226,8 @@ function upgrade_160() {
update_usermeta( $user->ID, 'last_name', $wpdb->escape($user->user_lastname) );
if ( !empty( $user->user_nickname ) )
update_usermeta( $user->ID, 'nickname', $wpdb->escape($user->user_nickname) );
if ( !empty( $user->user_level ) ) {
if ( !empty( $user->user_level ) )
update_usermeta( $user->ID, $table_prefix . 'user_level', $user->user_level );
$role = translate_level_to_role($user->user_level);
update_usermeta( $user->ID, $table_prefix . 'capabilities', array($role => true) );
}
if ( !empty( $user->user_icq ) )
update_usermeta( $user->ID, 'icq', $wpdb->escape($user->user_icq) );
if ( !empty( $user->user_aim ) )
@ -255,8 +252,9 @@ function upgrade_160() {
$wpdb->query("UPDATE $wpdb->users SET display_name = '$id' WHERE ID = '$user->ID'");
endif;
// FIXME: Temporary code to reset roles and caps if flag is set.
if ( defined('RESET_CAPS') ) {
// FIXME: RESET_CAPS is temporary code to reset roles and caps if flag is set.
$caps = get_usermeta( $user->ID, $table_prefix . 'capabilities');
if ( empty($caps) || defined('RESET_CAPS') ) {
$level = get_usermeta($user->ID, $table_prefix . 'user_level');
$role = translate_level_to_role($level);
update_usermeta( $user->ID, $table_prefix . 'capabilities', array($role => true) );

View File

@ -1957,6 +1957,13 @@ function get_usermeta( $user_id, $meta_key = '') {
$metas = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = '$user_id'");
}
if ( empty($metas) ) {
if ( empty($meta_key) )
return array();
else
return '';
}
foreach ($metas as $index => $meta) {
@ $value = unserialize($meta->meta_value);
if ($value === FALSE)