bp_groups_update_orphaned_groups_on_group_delete( BP_Groups_Group $group )

Update orphaned child groups when the parent is deleted.

Description

Parameters

$group

(Required) Instance of the group item being deleted.

Source

File: bp-groups/bp-groups-functions.php

2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
function bp_groups_update_orphaned_groups_on_group_delete( $group ) {
    // Get child groups and set the parent to the deleted parent's parent.
    $grandparent_group_id = $group->parent_id;
    $child_args = array(
        'parent_id'         => $group->id,
        'show_hidden'       => true,
        'per_page'          => false,
        'update_meta_cache' => false,
    );
    $children = groups_get_groups( $child_args );
    $children = $children['groups'];
 
    foreach ( $children as $cgroup ) {
        $cgroup->parent_id = $grandparent_group_id;
        $cgroup->save();
    }
}

Changelog

Changelog
Version Description
BuddyPress 2.7.0 Introduced.

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.