Skip to:

Counting Parent Groups

  • MutualDesigns


    I found the following function inside your plugin, but I’m having trouble getting it to work:

    `function bp_group_hierarchy_get_parents( $group = null ) {
    global $groups_template;

    if ( !$group ) {
    /** need a copy since we’re going to walk up the tree */
    $group = $groups_template->group;

    $parents = array();

    while($group->parent_id != 0) {
    $parents[] = $group->parent_id;
    $group = new BP_Groups_Hierarchy($group->parent_id);

    return $parents;

    If I run the function, I get nothing. Keep in mind I’m trying to run this inside the groups single template pages and not inside the tree loop or group loop. I’d like to be able to identify the level of the group and perform some tasks once it has been identified.

Viewing 3 replies - 1 through 3 (of 3 total)

  • MutualDesigns


    Figured it out! Stored the number inside the variable to test, but you could do a number of things with this information. I’m working on limiting the permissions in the creation phase to prevent more than three levels of groups.





    I’ve been fighting with this all evening and morning and I’m wondering if anyone has any input on this issue:

    I’d like to take the output I’ve stored in the variable above and store this information to carry using a cookie or session to the “create a group” pages. The reason I’d like to do this is because I’d like to write some logic that sets permissions on creating groups. For example:

    In the below scenario, I’d like only superadmins to be able to create top level and second level groups. Group members can go nuts and create as many third level groups as possible.

    Top level: Identify $grouplevel from current group and only allow noone as a option (this allows only super_admins to create member groups.

    Second Level: Identify $grouplevel from current group and only allow groupmembers as an option (this allows any members to make third level groups)

    Third Level: Identify $grouplevel from current group and only allow noone as an option (this ends the group creation at level three)

    Anyone have any ideas on how to do this. I’ve tried storing the variable as a cookie without much luck.

    David Dean


    This seems like something you could cobble together without trying to send params to the group creation process, which is very awkward.

    Top level: set toplevel groups to “Nobody” in the admin dashboard.
    Then, since only super admins can create toplevel groups, set the permissions in each of those groups to “no one”

    Second and Third level: hook `bp_group_hierarchy_subgroup_permission_options` and return only the `group_members` and `noone` keys (respectively).

    This filter passes the current group_id as a second parameter.

    If none of that works for you, you can look at the `bp_group_hierarchy_set_parent_id_cookie()` function for a working example of setting cookies for group creation.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Counting Parent Groups’ is closed to new replies.
Skip to toolbar