1

please can someone help me with this snippet of code I have written. I basically would like to check if a user is new. However, the below only triggers when an existing user is saved, not when a new account is created. i would like this to apply only to new users Thanks for any help 🙂

 Event::on(
        User::class,
        User::EVENT_AFTER_SAVE,
        function (ModelEvent $event) {
            $user = $event->sender;
            $isNew = $event->isNew;
    
            if ($isNew) {
                Craft::info('is new', __METHOD__);
            } else {
                Craft::info('is not new', __METHOD__);
            }
        }
    );

1 Answer 1

2

Try $isNew = $user->isNewForSite.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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