function _menu_delete_item($item) { // System-created items get automatically deleted, but only on menu rebuild. if ($item && $item['module'] != 'system') { // Children get re-attached to the item's parent if ($item['has_children']) { $result = db_query("SELECT mlid FROM {menu_links} WHERE plid = %d", $item['mlid']); while ($m = db_fetch_array($result)) { $child = menu_link_load($m['mlid']); $child['plid'] = $item['plid']; menu_link_save($child); } } db_query('DELETE FROM {menu_links} WHERE mlid = %d', $item['mlid']); // Update the has_children status of the parent $children = (bool)db_result(db_query("SELECT COUNT(*) FROM {menu_links} WHERE plid = %d AND hidden = 0", $item['plid'])); db_query("UPDATE {menu_links} SET has_children = %d WHERE mlid = %d", $children, $item['plid']); menu_cache_clear($item['menu_name']); }}