How do you save information for a user when it is part of the user’s profile?
Meaning, how do I change the user’s fullname, email, etc. but specifically in a plugin?
So far I have this for OnUserBeforeSave, but it doesn’t change anything in the database:
<?php
$profile = $user->getOne('Profile');
$profile->set('fullname', 'change fullname');
$user->addOne($profile, 'Profile');
$user->save();
Solution:
If wanting to save $user profile, then need to getObject.
Correct code:
<?php
$user_edit = $modx->getObject('modUser', $id);
$profile_edit = $user_edit->getOne('Profile');
$profile_edit->set('fullname', 'change fullname');
$user_edit->addOne($profile_edit, 'Profile');
$user_edit->save();