BP_Core_User::get_user_extras( array $paged_users, string $user_ids, string|bool $type = false )
Fetch extra user information, such as friend count and last profile update message.
Description
Accepts multiple user IDs to fetch data for.
Parameters
- $paged_users
-
(Required) An array of stdClass containing the users.
- $user_ids
-
(Required) The user ids to select information about.
- $type
-
(Optional) The type of fields we wish to get.
Default value: false
Return
(mixed) False on error, otherwise associative array of results.
Source
File: bp-core/classes/class-bp-core-user.php
public static function get_user_extras( &$paged_users, &$user_ids, $type = false ) { global $wpdb; $bp = buddypress(); if ( empty( $user_ids ) ) return $paged_users; // Sanitize user IDs. $user_ids = implode( ',', wp_parse_id_list( $user_ids ) ); // Fetch the user's full name. if ( bp_is_active( 'xprofile' ) && 'alphabetical' != $type ) { $names = $wpdb->get_results( $wpdb->prepare( "SELECT pd.user_id as id, pd.value as fullname FROM {$bp->profile->table_name_fields} pf, {$bp->profile->table_name_data} pd WHERE pf.id = pd.field_id AND pf.name = %s AND pd.user_id IN ( {$user_ids} )", bp_xprofile_fullname_field_name() ) ); for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) { foreach ( (array) $names as $name ) { if ( $name->id == $paged_users[$i]->id ) $paged_users[$i]->fullname = $name->fullname; } } } // Fetch the user's total friend count. if ( 'popular' != $type ) { $friend_count = $wpdb->get_results( $wpdb->prepare( "SELECT user_id as id, meta_value as total_friend_count FROM {$wpdb->usermeta} WHERE meta_key = %s AND user_id IN ( {$user_ids} )", bp_get_user_meta_key( 'total_friend_count' ) ) ); for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) { foreach ( (array) $friend_count as $fcount ) { if ( $fcount->id == $paged_users[$i]->id ) $paged_users[$i]->total_friend_count = (int) $fcount->total_friend_count; } } } // Fetch whether or not the user is a friend. if ( bp_is_active( 'friends' ) ) { $friend_status = $wpdb->get_results( $wpdb->prepare( "SELECT initiator_user_id, friend_user_id, is_confirmed FROM {$bp->friends->table_name} WHERE (initiator_user_id = %d AND friend_user_id IN ( {$user_ids} ) ) OR (initiator_user_id IN ( {$user_ids} ) AND friend_user_id = %d )", bp_loggedin_user_id(), bp_loggedin_user_id() ) ); for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) { foreach ( (array) $friend_status as $status ) { if ( $status->initiator_user_id == $paged_users[$i]->id || $status->friend_user_id == $paged_users[$i]->id ) $paged_users[$i]->is_friend = $status->is_confirmed; } } } // Fetch the user's last_activity. if ( 'active' != $type ) { $user_activity = $wpdb->get_results( $wpdb->prepare( "SELECT user_id as id, meta_value as last_activity FROM {$wpdb->usermeta} WHERE meta_key = %s AND user_id IN ( {$user_ids} )", bp_get_user_meta_key( 'last_activity' ) ) ); for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) { foreach ( (array) $user_activity as $activity ) { if ( $activity->id == $paged_users[$i]->id ) $paged_users[$i]->last_activity = $activity->last_activity; } } } // Fetch the user's latest update. $user_update = $wpdb->get_results( $wpdb->prepare( "SELECT user_id as id, meta_value as latest_update FROM {$wpdb->usermeta} WHERE meta_key = %s AND user_id IN ( {$user_ids} )", bp_get_user_meta_key( 'bp_latest_update' ) ) ); for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) { foreach ( (array) $user_update as $update ) { if ( $update->id == $paged_users[$i]->id ) $paged_users[$i]->latest_update = $update->latest_update; } } return $paged_users; }
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.