/**
  * Clear cache objects for the user.
  * @param int $user_id
  */
 public static function clear_cache($user_id)
 {
     // be lazy, clear the entries so they are rebuilt when requested
     Groups_Cache::delete(self::CAPABILITIES . $user_id, self::CACHE_GROUP);
     Groups_Cache::delete(self::CAPABILITIES_BASE . $user_id, self::CACHE_GROUP);
     Groups_Cache::delete(self::CAPABILITY_IDS . $user_id, self::CACHE_GROUP);
     Groups_Cache::delete(self::CAPABILITY_IDS_BASE . $user_id, self::CACHE_GROUP);
     Groups_Cache::delete(self::GROUP_IDS . $user_id, self::CACHE_GROUP);
     Groups_Cache::delete(self::GROUP_IDS_BASE . $user_id, self::CACHE_GROUP);
     Groups_Cache::delete(self::GROUPS . $user_id, self::CACHE_GROUP);
     Groups_Cache::delete(self::GROUPS_BASE . $user_id, self::CACHE_GROUP);
 }
 /**
  * Remove capability and its relations.
  * 
  * @param int $capability_id
  * @return capability_id if successful, false otherwise
  */
 public static function delete($capability_id)
 {
     global $wpdb;
     $result = false;
     // avoid nonsense requests
     if ($capability = Groups_Capability::read($capability_id)) {
         $capability_table = _groups_get_tablename('capability');
         // get rid of it
         if ($rows = $wpdb->query($wpdb->prepare("DELETE FROM {$capability_table} WHERE capability_id = %d", Groups_Utility::id($capability_id)))) {
             $result = $capability_id;
             if (!empty($capability->capability)) {
                 Groups_Cache::delete(self::READ_BY_CAPABILITY . '_' . $capability->capability, self::CACHE_GROUP);
                 do_action('groups_deleted_capability_capability', $capability->capability);
             }
             do_action("groups_deleted_capability", $result);
         }
     }
     return $result;
 }
 /**
  * Remove group and its relations.
  * 
  * @param int $group_id
  * @return group_id if successful, false otherwise
  */
 public static function delete($group_id)
 {
     global $wpdb;
     $result = false;
     if ($group = self::read($group_id)) {
         // delete group-capabilities
         $group_capability_table = _groups_get_tablename('group_capability');
         $wpdb->query($wpdb->prepare("DELETE FROM {$group_capability_table} WHERE group_id = %d", Groups_Utility::id($group->group_id)));
         // delete group-users
         $user_group_table = _groups_get_tablename('user_group');
         $wpdb->query($wpdb->prepare("DELETE FROM {$user_group_table} WHERE group_id = %d", $group->group_id));
         // set parent_id to null where this group is parent
         $group_table = _groups_get_tablename('group');
         $wpdb->query($wpdb->prepare("UPDATE {$group_table} SET parent_id = NULL WHERE parent_id = %d", $group->group_id));
         // delete group
         if ($wpdb->query($wpdb->prepare("DELETE FROM {$group_table} WHERE group_id = %d", $group->group_id))) {
             $result = $group->group_id;
             if (!empty($group->name)) {
                 Groups_Cache::delete(self::READ_BY_NAME . '_' . $group->name, self::CACHE_GROUP);
             }
             do_action("groups_deleted_group", $result);
         }
     }
     return $result;
 }