本文整理匯總了PHP中BP_Core_User::get_user_extras方法的典型用法代碼示例。如果您正苦於以下問題:PHP BP_Core_User::get_user_extras方法的具體用法?PHP BP_Core_User::get_user_extras怎麽用?PHP BP_Core_User::get_user_extras使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類BP_Core_User
的用法示例。
在下文中一共展示了BP_Core_User::get_user_extras方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: search_users
/**
* Find users who match on the value of an xprofile data.
*
* @global wpdb $wpdb WordPress database object.
*
* @param string $search_terms The terms to search the profile table
* value column for.
* @param integer $limit The limit of results we want.
* @param integer $page The page we are on for pagination.
* @param boolean $populate_extras Populate extra user fields?
* @return array Associative array.
*/
public static function search_users($search_terms, $limit = null, $page = 1, $populate_extras = true)
{
global $wpdb;
$bp = buddypress();
$user_ids = array();
$pag_sql = $limit && $page ? $wpdb->prepare(" LIMIT %d, %d", intval(($page - 1) * intval($limit)), intval($limit)) : '';
$search_terms_like = '%' . bp_esc_like($search_terms) . '%';
$status_sql = bp_core_get_status_sql('u.');
/**
* Filters the SQL used to query for searched users count.
*
* @since BuddyPress (1.0.0)
*
* @param string $value SQL statement for the searched users count query.
*/
$total_users_sql = apply_filters('bp_core_search_users_count_sql', $wpdb->prepare("SELECT COUNT(DISTINCT u.ID) as id FROM {$wpdb->users} u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id WHERE {$status_sql} AND pd.value LIKE %s ORDER BY pd.value ASC", $search_terms_like), $search_terms);
/**
* Filters the SQL used to query for searched users.
*
* @since BuddyPress (1.0.0)
*
* @param string $value SQL statement for the searched users query.
*/
$paged_users_sql = apply_filters('bp_core_search_users_sql', $wpdb->prepare("SELECT DISTINCT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.user_email FROM {$wpdb->users} u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id WHERE {$status_sql} AND pd.value LIKE %s ORDER BY pd.value ASC{$pag_sql}", $search_terms_like), $search_terms, $pag_sql);
$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)
*/
foreach ((array) $paged_users as $user) {
$user_ids[] = $user->id;
}
// Add additional data to the returned results
if ($populate_extras) {
$paged_users = BP_Core_User::get_user_extras($paged_users, $user_ids);
}
return array('users' => $paged_users, 'total' => $total_users);
}
示例2: search_users
/**
* Find users who match on the value of an xprofile data.
*
* @global object $bp Global BuddyPress settings object
* @global nxtdb $nxtdb NXTClass database object
* @param string $search_terms The terms to search the profile table value column for.
* @param integer $limit The limit of results we want.
* @param integer $page The page we are on for pagination.
* @param boolean $populate_extras Populate extra user fields?
* @return array Associative array
* @static
*/
function search_users($search_terms, $limit = null, $page = 1, $populate_extras = true)
{
global $bp, $nxtdb;
$pag_sql = $limit && $page ? $nxtdb->prepare(" LIMIT %d, %d", intval(($page - 1) * intval($limit)), intval($limit)) : '';
$search_terms = like_escape($nxtdb->escape($search_terms));
$status_sql = bp_core_get_status_sql('u.');
$total_users_sql = apply_filters('bp_core_search_users_count_sql', "SELECT COUNT(DISTINCT u.ID) as id FROM {$nxtdb->users} u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id WHERE {$status_sql} AND pd.value LIKE '%%{$search_terms}%%' ORDER BY pd.value ASC", $search_terms);
$paged_users_sql = apply_filters('bp_core_search_users_sql', "SELECT DISTINCT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.user_email FROM {$nxtdb->users} u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id WHERE {$status_sql} AND pd.value LIKE '%%{$search_terms}%%' ORDER BY pd.value ASC{$pag_sql}", $search_terms, $pag_sql);
$total_users = $nxtdb->get_var($total_users_sql);
$paged_users = $nxtdb->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)
*/
foreach ((array) $paged_users as $user) {
$user_ids[] = $user->id;
}
$user_ids = $nxtdb->escape(join(',', (array) $user_ids));
// Add additional data to the returned results
if ($populate_extras) {
$paged_users = BP_Core_User::get_user_extras($paged_users, $user_ids);
}
return array('users' => $paged_users, 'total' => $total_users);
}