From 4629103d2c89821e248f36f2a9d2acf47f20465d Mon Sep 17 00:00:00 2001 From: dd32 Date: Mon, 4 Oct 2010 09:59:53 +0000 Subject: [PATCH] Simplify get_user_metavalues() to entirely rely upon the Metadata API, Removes a direct SQL Query. de-serializing is handled by the Metadata API now. git-svn-id: http://svn.automattic.com/wordpress/trunk@15703 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/user.php | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/wp-includes/user.php b/wp-includes/user.php index 692dbce27b..ca51a2fedb 100644 --- a/wp-includes/user.php +++ b/wp-includes/user.php @@ -1051,36 +1051,23 @@ function _fill_user( &$user ) { * @return array of arrays. The array is indexed by user_id, containing $metavalues object arrays. */ function get_user_metavalues($ids) { - global $wpdb; - $objects = array(); $ids = array_map('intval', $ids); foreach ( $ids as $id ) $objects[$id] = array(); - if ( 0 == count($ids) ) { - return $objects; - } elseif ( 1 == count($ids) ) { - // Take advantage of the single-user cache - $id = $ids[0]; + update_meta_cache('user', $ids); + + foreach ( $ids as $id ) { $meta = get_metadata('user', $id); - foreach ( $meta as $key => $metavalues ) - foreach ( $metavalues as $value ) + foreach ( $meta as $key => $metavalues ) { + foreach ( $metavalues as $value ) { $objects[$id][] = (object)array( 'user_id' => $id, 'meta_key' => $key, 'meta_value' => $value); - - return $objects; + } + } } - $list = implode(',', $ids); - - $show = $wpdb->hide_errors(); - $metavalues = $wpdb->get_results("SELECT user_id, meta_key, meta_value FROM $wpdb->usermeta WHERE user_id IN ($list)"); - $wpdb->show_errors($show); - - foreach ( $metavalues as $meta_object ) - $objects[$meta_object->user_id][] = $meta_object; - return $objects; } @@ -1095,7 +1082,6 @@ function _fill_single_user( &$user, &$metavalues ) { global $wpdb; foreach ( $metavalues as $meta ) { - $value = maybe_unserialize($meta->meta_value); // Keys used as object vars cannot have dashes. $key = str_replace('-', '', $meta->meta_key); $user->{$key} = $value;