I'm trying to change a new user's class_key value when they are created VIA the manager.
In a plugin that fires on the onUserSave event:
<?php
$uid = $_POST['id'];
$sql = "update modx_users set `class_key` = 'extUser' where id = $uid;";
$modx->log(modX::LOG_LEVEL_ERROR, 'query = ' . $sql);
$query = $modx->query($sql);
return;
Which works when you EDIT an EXISTING user, but does not work if you try to create a new user.
Any thoughts on how to do this? none of the events [*obviously*] look like they fire when a new user is created.
*** Not just websites, we also create signage, banners, print, trade show displays and more! ***
Sean Kimball CLP, CLS.
Technical Director / Sr. Developer | BigBlock Studios
._______________________________________________.
Bigblock Studios
http://www.bigblockstudios.ca Web site design & development.
27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
phone/fax: 905-426-5525
I'm not sure that event fires reliably for new users. Looking at the code, it appears that it only gets called when the user is saved with $user->save(), not when the user/create or user/update processors are called.
I think OnUserFormSave is called for both create and update, but I believe it only fires when you use the Create/Edit User form in the Manager.
Be sure to save the user after setting the class_key.
Note that changing the user's class_key could possibly cause trouble with extras that extend modUser, though it's not a problem with ClassExtender (which leaves the class_key as modUser).
IMO, changing the users' class_key is only necessary if they are separate from "regular" users and you need to search among just the users with the modified class_key. If *all* users get the new class_key, it's not necessary to change it.
The problem is that the user has not been saved yet, no user object or database object to edit. I tried changing the $_POST data, but no luck. [very frustrating]
Quote from: BobRay at Sep 23, 2014, 11:36 PMI'm not sure that event fires reliably for new users. Looking at the code, it appears that it only gets called when the user is saved with $user->save(), not when the user/create or user/update processors are called.
I think OnUserFormSave is called for both create and update, but I believe it only fires when you use the Create/Edit User form in the Manager.
Be sure to save the user after setting the class_key.
Note that changing the user's class_key could possibly cause trouble with extras that extend modUser, though it's not a problem with ClassExtender (which leaves the class_key as modUser).
IMO, changing the users' class_key is only necessary if they are separate from "regular" users and you need to search among just the users with the modified class_key. If *all* users get the new class_key, it's not necessary to change it.
*** Not just websites, we also create signage, banners, print, trade show displays and more! ***
Sean Kimball CLP, CLS.
Technical Director / Sr. Developer | BigBlock Studios
._______________________________________________.
Bigblock Studios
http://www.bigblockstudios.ca Web site design & development.
27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
phone/fax: 905-426-5525
Erm ... that's impossible. OnUserFormSave only fires after the user has been successfully saved.
This would be the entire code for the plugin (unless there are conditions you need to check):
$user->set('class_key', 'Whatever');
$user->save();
ok - hmm, maybe I'm not seeing that because if we try to get any user attributes in the plugin [$user->get('id');] modx will assume the current user [manager] ~ how do we get the ID of the user that was just saved in the plugin for OnUserFormSave ??
Quote from: BobRay at Sep 24, 2014, 04:56 PMErm ... that's impossible. OnUserFormSave only fires after the user has been successfully saved.
This would be the entire code for the plugin (unless there are conditions you need to check):
$user->set('class_key', 'Whatever');
$user->save();
*** Not just websites, we also create signage, banners, print, trade show displays and more! ***
Sean Kimball CLP, CLS.
Technical Director / Sr. Developer | BigBlock Studios
._______________________________________________.
Bigblock Studios
http://www.bigblockstudios.ca Web site design & development.
27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
phone/fax: 905-426-5525
In a plugin attached to OnUserFormSave, the $user object will always be the user being created or edited.
ouch - it's just me, I must be losing my mind!
Quote from: BobRay at Sep 25, 2014, 06:12 PMIn a plugin attached to OnUserFormSave, the $user object will always be the user being created or edited.
*** Not just websites, we also create signage, banners, print, trade show displays and more! ***
Sean Kimball CLP, CLS.
Technical Director / Sr. Developer | BigBlock Studios
._______________________________________________.
Bigblock Studios
http://www.bigblockstudios.ca Web site design & development.
27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
phone/fax: 905-426-5525
You may have been thinking of $modx->user, which (if set) will be the current logged-in user.