Tidy up get_userdatabylogin().
git-svn-id: http://svn.automattic.com/wordpress/trunk@3137 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
544842e3dc
commit
e6425a4127
|
@ -64,37 +64,13 @@ endif;
|
||||||
|
|
||||||
if ( !function_exists('update_user_cache') ) :
|
if ( !function_exists('update_user_cache') ) :
|
||||||
function update_user_cache() {
|
function update_user_cache() {
|
||||||
global $cache_userdata, $wpdb;
|
return true;
|
||||||
$level_key = $wpdb->prefix . 'user_level';
|
|
||||||
$user_ids = $wpdb->get_col("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$level_key'");
|
|
||||||
$user_ids = join(',', $user_ids);
|
|
||||||
$query = apply_filters('user_cache_query', "SELECT * FROM $wpdb->users WHERE ID IN ($user_ids)");
|
|
||||||
if ( $users = $wpdb->get_results( $query ) ) :
|
|
||||||
foreach ($users as $user) :
|
|
||||||
$metavalues = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = '$user->ID'");
|
|
||||||
foreach ( $metavalues as $meta ) {
|
|
||||||
@ $value = unserialize($meta->meta_value);
|
|
||||||
if ($value === FALSE)
|
|
||||||
$value = $meta->meta_value;
|
|
||||||
$user->{$meta->meta_key} = $value;
|
|
||||||
// We need to set user_level from meta, not row
|
|
||||||
if ( $wpdb->prefix . 'user_level' == $meta->meta_key )
|
|
||||||
$user->user_level = $meta->meta_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
$cache_userdata[$user->ID] = $user;
|
|
||||||
$cache_userdata[$user->user_login] =& $cache_userdata[$user->ID];
|
|
||||||
endforeach;
|
|
||||||
return true;
|
|
||||||
else :
|
|
||||||
return false;
|
|
||||||
endif;
|
|
||||||
}
|
}
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
if ( !function_exists('get_userdatabylogin') ) :
|
if ( !function_exists('get_userdatabylogin') ) :
|
||||||
function get_userdatabylogin($user_login) {
|
function get_userdatabylogin($user_login) {
|
||||||
global $cache_userdata, $wpdb;
|
global $wpdb;
|
||||||
$user_login = sanitize_user( $user_login );
|
$user_login = sanitize_user( $user_login );
|
||||||
|
|
||||||
if ( empty( $user_login ) )
|
if ( empty( $user_login ) )
|
||||||
|
@ -105,25 +81,27 @@ function get_userdatabylogin($user_login) {
|
||||||
return $userdata;
|
return $userdata;
|
||||||
|
|
||||||
if ( !$user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE user_login = '$user_login'") )
|
if ( !$user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE user_login = '$user_login'") )
|
||||||
return $cache_userdata[$user_login] = false;
|
return false;
|
||||||
|
|
||||||
$metavalues = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = '$user->ID'");
|
$metavalues = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = '$user->ID'");
|
||||||
|
|
||||||
foreach ( $metavalues as $meta ) {
|
if ($metavalues) {
|
||||||
@ $value = unserialize($meta->meta_value);
|
foreach ( $metavalues as $meta ) {
|
||||||
if ($value === FALSE)
|
@ $value = unserialize($meta->meta_value);
|
||||||
$value = $meta->meta_value;
|
if ($value === FALSE)
|
||||||
$user->{$meta->meta_key} = $value;
|
$value = $meta->meta_value;
|
||||||
|
$user->{$meta->meta_key} = $value;
|
||||||
|
|
||||||
// We need to set user_level from meta, not row
|
// We need to set user_level from meta, not row
|
||||||
if ( $wpdb->prefix . 'user_level' == $meta->meta_key )
|
if ( $wpdb->prefix . 'user_level' == $meta->meta_key )
|
||||||
$user->user_level = $meta->meta_value;
|
$user->user_level = $meta->meta_value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$cache_userdata[$user->ID] = $user;
|
wp_cache_add($user->ID, $user, 'users');
|
||||||
$cache_userdata[$cache_userdata[$user->ID]->user_login] =& $cache_userdata[$user->ID];
|
wp_cache_add($user->user_login, $user, 'users');
|
||||||
|
|
||||||
return $cache_userdata[$user->ID];
|
return $user;
|
||||||
|
|
||||||
}
|
}
|
||||||
endif;
|
endif;
|
||||||
|
|
Loading…
Reference in New Issue