1

I have a plugin that uses its init function to save custom user data from front end registrations. It uses:

 if ($event->params['isNewUser']) {}

and

if (craft()->request->isSiteRequest()) {}

To perform front end save routines.

I want to add a small custom user save rule for admin usage outside of the IsNewUser logic in order to preserve like this:

 if (craft()->request->isCpRequest()) {
   $user = craft()->users->getUserById($uidfromURL);
   $user->getContent()->URN = 'my custom value';
   $success = craft()->users->saveUser($user);
 }

The problem is that this code just loops thru the plugin. I need the custom field to be manually editable, but i also need to create a default value too on initial user creation in admin.

1

I had a similar problem a while ago when a plugin listened for onSaveUser and then saved the user itself, causing an infinite loop. Someone provided me something like:

craft()->on('users.onSaveUser', function(Event $event) {
    static $recursionLevel = 0;
    if ($recursionLevel == 0) {
        $recursionLevel++;
        // do your stuff
    }
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.