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: https://develop.svn.wordpress.org/trunk@15703 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
761ad85a17
commit
6c9b29e6f3
|
@ -1051,35 +1051,22 @@ function _fill_user( &$user ) {
|
||||||
* @return array of arrays. The array is indexed by user_id, containing $metavalues object arrays.
|
* @return array of arrays. The array is indexed by user_id, containing $metavalues object arrays.
|
||||||
*/
|
*/
|
||||||
function get_user_metavalues($ids) {
|
function get_user_metavalues($ids) {
|
||||||
global $wpdb;
|
|
||||||
|
|
||||||
$objects = array();
|
$objects = array();
|
||||||
|
|
||||||
$ids = array_map('intval', $ids);
|
$ids = array_map('intval', $ids);
|
||||||
foreach ( $ids as $id )
|
foreach ( $ids as $id )
|
||||||
$objects[$id] = array();
|
$objects[$id] = array();
|
||||||
|
|
||||||
if ( 0 == count($ids) ) {
|
update_meta_cache('user', $ids);
|
||||||
return $objects;
|
|
||||||
} elseif ( 1 == count($ids) ) {
|
foreach ( $ids as $id ) {
|
||||||
// Take advantage of the single-user cache
|
|
||||||
$id = $ids[0];
|
|
||||||
$meta = get_metadata('user', $id);
|
$meta = get_metadata('user', $id);
|
||||||
foreach ( $meta as $key => $metavalues )
|
foreach ( $meta as $key => $metavalues ) {
|
||||||
foreach ( $metavalues as $value )
|
foreach ( $metavalues as $value ) {
|
||||||
$objects[$id][] = (object)array( 'user_id' => $id, 'meta_key' => $key, 'meta_value' => $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;
|
return $objects;
|
||||||
}
|
}
|
||||||
|
@ -1095,7 +1082,6 @@ function _fill_single_user( &$user, &$metavalues ) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
foreach ( $metavalues as $meta ) {
|
foreach ( $metavalues as $meta ) {
|
||||||
$value = maybe_unserialize($meta->meta_value);
|
|
||||||
// Keys used as object vars cannot have dashes.
|
// Keys used as object vars cannot have dashes.
|
||||||
$key = str_replace('-', '', $meta->meta_key);
|
$key = str_replace('-', '', $meta->meta_key);
|
||||||
$user->{$key} = $value;
|
$user->{$key} = $value;
|
||||||
|
|
Loading…
Reference in New Issue