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
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
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.