BP_Core_User::get_specific_users( array $user_ids, int|null $limit = null, int $page = 1, bool $populate_extras = true )
Get details of specific users from the database.
Description
Use BP_User_Query with the ‘user_ids’ param instead.
Parameters
- $user_ids
-
(Required) The user IDs of the users who we wish to fetch information on.
- $limit
-
(Optional) The limit of results we want.
Default value: null
- $page
-
(Optional) The page we are on for pagination.
Default value: 1
- $populate_extras
-
(Optional) If we should populate extra user fields.
Default value: true
Return
(array) Associative array.
Source
File: bp-core/classes/class-bp-core-user.php
public static function get_specific_users( $user_ids, $limit = null, $page = 1, $populate_extras = true ) {
global $wpdb;
$pag_sql = '';
if ( $limit && $page )
$pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
$user_ids = implode( ',', wp_parse_id_list( $user_ids ) );
$status_sql = bp_core_get_status_sql();
/**
* Filter the SQL string used for querying specific user count.
*
* This same filter name is used for the paged user SQL, and so should be avoided.
* Use 'bp_core_user_get_specific_users_count_sql' instead.
*
* @deprecated 2.3.0
*
* @param string $sql SQL string.
*/
$total_users_sql = apply_filters( 'bp_core_get_specific_users_count_sql', "SELECT COUNT(ID) FROM {$wpdb->users} WHERE {$status_sql} AND ID IN ({$user_ids})" );
/**
* Filter the SQL string used for querying specific user count results.
*
* Use this instead of the deprecated 'bp_core_get_specific_users_count_sql'.
*
* @since BuddyPress 2.3.0
*
* @param string $sql SQL string.
* @param array $user_ids Array of IDs of specific users to fetch.
* @param int|null $limit Max number of records to return. Null for no limit.
* @param int $page The page we're on for pagination.
* @param bool $populate_extras Whether to populate extra user fields.
*/
$total_users_sql = apply_filters( 'bp_core_user_get_specific_users_count_sql', $total_users_sql, $user_ids, $limit, $page, $populate_extras );
/**
* Filter the SQL string used for querying specific user paged results.
*
* This same filter name is used for the user count SQL, and so should be avoided.
* Use 'bp_core_user_get_specific_users_paged_sql' instead.
*
* @deprecated 2.3.0
*
* @param string $sql SQL string.
*/
$paged_users_sql = apply_filters( 'bp_core_get_specific_users_count_sql', "SELECT ID as id, user_registered, user_nicename, user_login, user_email FROM {$wpdb->users} WHERE {$status_sql} AND ID IN ({$user_ids}) {$pag_sql}" );
/**
* Filter the SQL string used for querying specific user paged results.
*
* Use this instead of the deprecated 'bp_core_get_specific_users_count_sql'.
*
* @since BuddyPress 2.3.0
*
* @param string $sql SQL string.
* @param array $user_ids Array of IDs of specific users to fetch.
* @param int|null $limit Max number of records to return. Null for no limit.
* @param int $page The page we're on for pagination.
* @param bool $populate_extras Whether to populate extra user fields.
*/
$paged_users_sql = apply_filters( 'bp_core_user_get_specific_users_paged_sql', $paged_users_sql, $user_ids, $limit, $page, $populate_extras );
$total_users = $wpdb->get_var( $total_users_sql );
$paged_users = $wpdb->get_results( $paged_users_sql );
/**
* Lets fetch some other useful data in a separate queries, this will be
* faster than querying the data for every user in a list. We can't add
* these to the main query above since only users who have this
* information will be returned (since the much of the data is in
* usermeta and won't support any type of directional join)
*/
// Add additional data to the returned results.
if ( !empty( $populate_extras ) ) {
$paged_users = BP_Core_User::get_user_extras( $paged_users, $user_ids );
}
return array( 'users' => $paged_users, 'total' => $total_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.