Dynamically Adding a User to a Group

I’d like to add a user to a group upon completing a purchase using the shopping cart plugin. That group would only be able to access certain pages, using the permission settings (think membership site). I cannot seem to be able to figure out how to automate this step so that I don’t manually have to change the groups a user belongs to.

Basically you would need to take the user object, modify the group and then call save() on the object. However, you will also first need to set the file() on the object so it knows where to save it.

For example:

// Edit user object and save it
$user = $this->grav['user'];
$file = CompiledYamlFile::instance(Grav::instance()['locator']->findResource('user://accounts/' . $username . YAML_EXT, true, true));

// modify the user now...


Something like this…