BP_Groups_Group::delete()
Delete the current group.
Description
Return
(bool) True on success, false on failure.
Source
File: bp-groups/classes/class-bp-groups-group.php
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | public function delete () { global $wpdb ; // Delete groupmeta for the group. groups_delete_groupmeta( $this ->id ); // Fetch the user IDs of all the members of the group. $user_ids = BP_Groups_Member::get_group_member_ids( $this ->id ); $user_id_str = esc_sql( implode( ',' , wp_parse_id_list( $user_ids ) ) ); // Modify group count usermeta for members. $wpdb ->query( "UPDATE {$wpdb->usermeta} SET meta_value = meta_value - 1 WHERE meta_key = 'total_group_count' AND user_id IN ( {$user_id_str} )" ); // Now delete all group member entries. BP_Groups_Member::delete_all( $this ->id ); /** * Fires before the deletion of a group. * * @since BuddyPress 1.2.0 * * @param BP_Groups_Group $this Current instance of the group item being deleted. Passed by reference. * @param array $user_ids Array of user IDs that were members of the group. */ do_action_ref_array( 'bp_groups_delete_group' , array ( & $this , $user_ids ) ); wp_cache_delete( $this ->id, 'bp_groups' ); $bp = buddypress(); // Finally remove the group entry from the DB. if ( ! $wpdb ->query( $wpdb ->prepare( "DELETE FROM {$bp->groups->table_name} WHERE id = %d" , $this ->id ) ) ) { return false; } // delete group avatars $upload_path = bp_core_avatar_upload_path(); system( "rm -rf " . escapeshellarg ( $upload_path . '/group-avatars/' . $this ->id )); // delete group avatars $bp_attachments_uploads_dir = bp_attachments_uploads_dir_get(); $type_dir = trailingslashit( $bp_attachments_uploads_dir [ 'basedir' ] ); system( "rm -rf " . escapeshellarg ( $type_dir . 'groups/' . $this ->id ) ); return true; } |
Changelog
Version | Description |
---|---|
BuddyPress 1.6.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.