bp_groups_update_orphaned_groups_on_group_delete( BP_Groups_Group $group )
Update orphaned child groups when the parent is deleted.
Description Description
Parameters Parameters
- $group
-
(Required) Instance of the group item being deleted.
Source Source
File: bp-groups/bp-groups-functions.php
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 |
|---|---|
| 2.7.0 | Introduced. |