Ticket #13319: 13319.patch
File 13319.patch, 3.6 KB (added by , 15 years ago) |
---|
-
wp-includes/user.php
663 663 * 664 664 * @since 3.0.0 665 665 * @param array $ids User ID numbers list. 666 * @return array of arrays. The array is indexed by user_id, containing $metavalues object arrays.666 * @return array of arrays. The array is indexed by user_id, containing an array of $metavalues database result objects for that user. 667 667 */ 668 function get_user_metavalues( $ids) {668 function get_user_metavalues( $ids ) { 669 669 global $wpdb; 670 670 671 $clean = array_map( 'intval', $ids);672 if ( 0 == count( $clean) )671 $clean = array_map( 'intval', $ids ); 672 if ( 0 == count( $clean ) ) 673 673 return $objects; 674 674 675 $list = implode( ',', $clean);675 $list = implode( ',', $clean ); 676 676 677 677 $show = $wpdb->hide_errors(); 678 $metavalues = $wpdb->get_results( "SELECT user_id, meta_key, meta_value FROM $wpdb->usermeta WHERE user_id IN ($list)");679 $wpdb->show_errors( $show);678 $metavalues = $wpdb->get_results( "SELECT user_id, meta_key, meta_value FROM {$wpdb->usermeta} WHERE user_id IN ($list)" ); 679 $wpdb->show_errors( $show ); 680 680 681 681 $objects = array(); 682 foreach ($clean as $id) {682 foreach ( $clean as $id ) { 683 683 $objects[$id] = array(); 684 684 } 685 foreach ($metavalues as $meta_object) {686 $objects[$meta _object->user_id][] = $meta_object;685 foreach ( array_keys( $metavalues ) as $key ) { 686 $objects[$metavalues[$key]->user_id][] = &$metavalues[$key]; 687 687 } 688 688 689 689 return $objects; … … 695 695 * @since 3.0.0 696 696 * @param object $user The User object. 697 697 * @param array $metavalues An array of objects provided by get_user_metavalues() 698 * @return void 698 699 */ 699 function _fill_single_user( &$user, &$metavalues ) {700 function _fill_single_user( &$user, $metavalues ) { 700 701 global $wpdb; 701 702 702 foreach ( $metavalues as $meta ) { 703 $value = maybe_unserialize($meta->meta_value); 704 // Keys used as object vars cannot have dashes. 705 $key = str_replace('-', '', $meta->meta_key); 706 $user->{$key} = $value; 703 foreach ( array_keys( $metavalues ) as $key ) { 704 // Keys used as Object Properties cannot have dashes. 705 $property = str_replace( '-', '', $metavalues[$key]->meta_key ); 706 $user->{$property} = maybe_unserialize( $metavalues[$key]->meta_value ); 707 707 } 708 708 709 709 $level = $wpdb->prefix . 'user_level'; … … 711 711 $user->user_level = $user->{$level}; 712 712 713 713 // For backwards compat. 714 if ( isset( $user->first_name) )714 if ( isset( $user->first_name ) ) 715 715 $user->user_firstname = $user->first_name; 716 if ( isset( $user->last_name) )716 if ( isset( $user->last_name ) ) 717 717 $user->user_lastname = $user->last_name; 718 if ( isset( $user->description) )718 if ( isset( $user->description ) ) 719 719 $user->user_description = $user->description; 720 720 721 update_user_caches( $user);721 update_user_caches( $user ); 722 722 } 723 723 724 724 /** … … 726 726 * 727 727 * @since 3.0.0 728 728 * @param array $users User objects 729 * @ param array $metas User metavalues objects729 * @return void 730 730 */ 731 function _fill_many_users( &$users ) {731 function _fill_many_users( $users ) { 732 732 $ids = array(); 733 foreach ($users as $user_object) {734 $ids[] = $user _object->ID;733 foreach ( array_keys( $users ) as $key ) { 734 $ids[] = $users[$key]->ID; 735 735 } 736 736 737 $metas = get_user_metavalues( $ids);737 $metas = get_user_metavalues( $ids ); 738 738 739 foreach($users as $user_object) { 740 if (isset($metas[$user_object->ID])) { 741 _fill_single_user($user_object, $metas[$user_object->ID]); 739 foreach( array_keys( $users ) as $key ) { 740 $user_id = $users[$key]->ID; 741 if ( isset( $metas[$user_id] ) ) { 742 _fill_single_user( $users[$key], $metas[$user_id] ); 742 743 } 743 744 } 744 745 }