We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9207 ☆ A M B ☆
    • 2,475 Posts
    I've been working on this all day: http://rtfm.modx.com/display/revolution20/Extending+modUser

    Long story short: I've got things working, and I can do a simple Snippet that lets me save my new user class extUser.

    $username = 'test';
    $modx->addPackage('extendeduser', MODX_CORE_PATH . 'components/extendeduser/model/', 'ext_');
    $user = $modx->newObject('extUser', array('username'=>$username)); 
    $data = $modx->newObject('Userdata');
    $data->set('extra_field', 'xxxxxx');
    $user->addOne($data, 'Data');
    
    if (!$user->save()) {
    
       return 'Problem...';
    }
    
    return 'Ok!';


    But when I try to use this in a postHook (for the Register Snippet), the user data gets saved incorrectly: only the core user attributes are saved, the class_key is saved as "modUser", and the extended "Userdata" stuff doesn't get saved at all. Any ideas?

    Actually, I think I just thought of something: the saving should be a prehook instead... since I think the Register Snippet must be creating the user already, and when I try to re-create it, it fails. That might be why the class_key is being populated as "modUser" instead of my "extUser"...

    A couple related notices from the PHP logs:

    PHP Notice:  Undefined index: username in /core/components/login/model/login/loginhooks.class.php on line 183
    PHP Notice:  Undefined index: hook in /core/components/login/model/login/loginhooks.class.php on line 137