Make WordPress Core

Changeset 15703


Ignore:
Timestamp:
10/04/2010 09:59:53 AM (14 years ago)
Author:
dd32
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/user.php

    r15702 r15703  
    10521052 */
    10531053function get_user_metavalues($ids) {
    1054     global $wpdb;
    1055 
    10561054    $objects = array();
    10571055
     
    10601058        $objects[$id] = array();
    10611059
    1062     if ( 0 == count($ids) ) {
    1063         return $objects;
    1064     } elseif ( 1 == count($ids) ) {
    1065         // Take advantage of the single-user cache
    1066         $id = $ids[0];
     1060    update_meta_cache('user', $ids);
     1061
     1062    foreach ( $ids as $id ) {
    10671063        $meta = get_metadata('user', $id);
    1068         foreach ( $meta as $key => $metavalues )
    1069             foreach ( $metavalues as $value )
     1064        foreach ( $meta as $key => $metavalues ) {
     1065            foreach ( $metavalues as $value ) {
    10701066                $objects[$id][] = (object)array( 'user_id' => $id, 'meta_key' => $key, 'meta_value' => $value);
    1071 
    1072         return $objects;
    1073     }
    1074 
    1075     $list = implode(',', $ids);
    1076 
    1077     $show = $wpdb->hide_errors();
    1078     $metavalues = $wpdb->get_results("SELECT user_id, meta_key, meta_value FROM $wpdb->usermeta WHERE user_id IN ($list)");
    1079     $wpdb->show_errors($show);
    1080 
    1081     foreach ( $metavalues as $meta_object )
    1082         $objects[$meta_object->user_id][] = $meta_object;
     1067            }
     1068        }
     1069    }
    10831070
    10841071    return $objects;
     
    10961083
    10971084    foreach ( $metavalues as $meta ) {
    1098         $value = maybe_unserialize($meta->meta_value);
    10991085        // Keys used as object vars cannot have dashes.
    11001086        $key = str_replace('-', '', $meta->meta_key);
Note: See TracChangeset for help on using the changeset viewer.