bp_get_descendent_groups (int | boolgroup_id美元int | booluser_id美元字符串美元的上下文“正常”

获取特定组的所有后代组。

描述

要返回所有的后代组,请保留$user_id参数为空。要只返回对特定用户可见的子组,请指定$user_id。

参数

group_id美元

int|保龄球(可选)组ID。

默认值:假

user_id美元

int|保龄球(可选)要检查组可见性的用户ID。

默认值:假

美元的上下文

字符串(可选)看到bp_include_group_by_context ()为描述。

默认值:“正常”

返回

(数组)组对象的数组。

文件:bp-groups / bp-groups-template.php

function bp_get_descendent_groups($group_id = false, $user_id = false, $context = 'normal'){/* *传递一个0的组id会找到所有的顶级组,这可能是有意为之的。我们只在$group_id为false时尝试查找当前组。*/ if (false === $group_id) {$group_id = bp_get_current_group_id();如果(!$group_id){//如果我们不能解析group_id,不要继续使用零值。返回数组();}} //准备返回集。$组=数组();//如果指定了用户ID,则过滤相应的隐藏组。$filter = (false !== $user_id && !) bp_user_can( $user_id, 'bp_moderate' ) ); // Start from the group specified. $parents = array( $group_id ); $descendants = array(); // We work down the tree until no new children are found. //while ( $parents ) { // Fetch all child groups. $child_args = array( 'parent_id' => $parents, 'show_hidden' => true, 'per_page' => false, 'page' => false, ); $children = groups_get_groups( $child_args ); // Reset parents array to rebuild for next round. $parents = array(); foreach ( $children['groups'] as $group ) { if ( $filter ) { if ( bp_include_group_by_context( $group, $user_id, $context ) ) { $groups[] = $group; $parents[] = $group->id; } } else { $groups[] = $group; $parents[] = $group->id; } } //} return $groups; }

更新日志

更新日志
版本 描述
BuddyBoss 1.0.0 介绍了。

问题吗?

我们总是很乐意帮助您解决代码或其他问题!搜索我们的开发人员文档联络支持,或与我们联系销售团队