bp_get_user_groups (㈡user_id美元,大批args美元=数组())
获取指定用户所属的组的列表。
描述
获取此成员所属的组列表,通过组成员身份和角色过滤。用法示例:没有指定参数,
bp_get_user_groups (bp_loggedin_user_id());
返回已登录用户为未晋升成员的组的数组。要获取当前用户在任何成员角色、成员、主持人或管理员中所属的所有组的数组,请使用
Bp_get_user_groups ($user_id, array(' is_admin ' => null, ' is_mod ' => null,));
参数
- user_id美元
-
(㈡)(必需的)用户的ID。
- args美元
-
(大批)(可选)可选参数数组。@param bool|null $is_confirmed是否只返回已确认的成员。通过
空值
禁用此过滤器。默认值:真的。@param bool|null $is_banned是否只返回被禁止的会员。通过空值
禁用此过滤器。默认值:false。@param bool | null $ is_admin是否仅返回管理员会员身份。通过空值
禁用此过滤器。默认值:false。@param bool|null $is_mod是否只返回mod成员。通过空值
禁用此过滤器。默认值:false。@param bool|null $invite_sent是否只返回'invite_sent'的会员。通过空值
禁用此过滤器。默认值:false。@param string $ orderby字段订购。接受“ID”(隶属ID),'Group_id','date_modified'。默认值:'group_id'。@param string $ sold排序顺序。接受'ASC'或'DESC'。默认值:'asc'。默认值:数组()
返回
(大批)匹配的组成员数组,按组ID键。
来源
文件:bp-groups / bp-groups-clusers.php
函数bp_get_user_groups($user_id, $args = array()) {$r = bp_parse_args($args, array('is_confirmed' => true, 'is_banned' => false, 'is_admin' => false, 'is_mod' => false, 'invite_sent' => null, 'orderby' => 'group_id', 'order' => 'ASC',), 'get_user_groups');$user_id = intval($user_id);$membership_ids = wp_cache_get($user_id, ' bp_group_memberships_for_user ');如果(false === $membership_ids) {$membership_ids = bp_group_member::get_membership_ids_for_user($user_id);Wp_cache_set ($user_id, $membership_ids, ' bp_group_memberships_for_user ');} //成员缓存的质数。$ unached_membership_ids = bp_get_non_cached_ids($membership_ids, 'bp_groups_memberships');如果(!$ unached_membership_ids = BP_Groups_Member::get_memberships_by_id($ unached_membership_ids); / / membership_member_id = BP_Groups_Member::get_memberships_by_id($ unached_membership_ids);Foreach ($uncached_memberships as $uncached_membership) {wp_cache_set($uncached_membership->id, $uncached_membership, 'bp_groups_memberships'); } } // Assemble filter array for use in `wp_list_filter()`. $filters = wp_array_slice_assoc( $r, array( 'is_confirmed', 'is_banned', 'is_admin', 'is_mod', 'invite_sent' ) ); foreach ( $filters as $filter_name => $filter_value ) { if ( is_null( $filter_value ) ) { unset( $filters[ $filter_name ] ); } } // Populate group membership array from cache, and normalize. $groups = array(); $int_keys = array( 'id', 'group_id', 'user_id', 'inviter_id' ); $bool_keys = array( 'is_admin', 'is_mod', 'is_confirmed', 'is_banned', 'invite_sent' ); foreach ( $membership_ids as $membership_id ) { $membership = wp_cache_get( $membership_id, 'bp_groups_memberships' ); // Sanity check. if ( ! isset( $membership->group_id ) ) { continue; } // Integer values. foreach ( $int_keys as $index ) { $membership->{$index} = intval( $membership->{$index} ); } // Boolean values. foreach ( $bool_keys as $index ) { $membership->{$index} = (bool) $membership->{$index}; } foreach ( $filters as $filter_name => $filter_value ) { if ( ! isset( $membership->{$filter_name} ) || $filter_value != $membership->{$filter_name} ) { continue 2; } } $group_id = (int) $membership->group_id; $groups[ $group_id ] = $membership; } // By default, results are ordered by membership id. if ( 'group_id' === $r['orderby'] ) { ksort( $groups ); } elseif ( in_array( $r['orderby'], array( 'id', 'date_modified' ) ) ) { $groups = bp_sort_by_key( $groups, $r['orderby'] ); } // By default, results are ordered ASC. if ( 'DESC' === strtoupper( $r['order'] ) ) { // `true` to preserve keys. $groups = array_reverse( $groups, true ); } return $groups; }
更新日志
版本 | 描述 |
---|---|
BuddyPress 2.6.0. | 介绍。 |