MODX Community

Generate Folder on new user registration (Login hook)

I want to create a new folder after a user has activated his account after the registration (with Login extra).
I found in the old forum a discussion about that, but I’m not sure if it’s still valid and what is the final version for a post hook.

I used following code but it has problems (HTTP Error 500)

$userName = $user->get('username');
$dir = (boolean)$modx->getOption('filemanager_path_relative',null,false) ? $modx->getOption('base_path') : '';
$dir .= $modx->getOption('filemanager_path',null,'').'media/images/artists/'.$userName;
$folder_permissions = octdec($modx->getOption('new_folder_permissions'));
if (!@mkdir($dir,$folder_permissions)) {
    $modx->log(modX::LOG_LEVEL_ERROR,'Could not create user directory: '.$dir);
return true;

I changed the path for my needs.

Also I want to use the user id instead of username. The username will be hidden in path and allows to rename username.

Your final } doesn’t appear to match anything. That could cause your 500 error.