1

I have been developing some plugin code for my registration form in Craft 3.

The event will be EVENT_AFTER_SAVE_ELEMENT, but I do not know how to detect if it is a new user or not. In Craft 2, the way was if ($event->params['isNewUser']).

It would be grateful for me if someone tell me how to do it.

2

In Craft 3 you would do:

Event::on(
    Elements::class, 
    Elements::EVENT_AFTER_SAVE_ELEMENT,
    function(Event $event) {
        if ($event->element instanceof \craft\elements\User && $event->isNew) {
            // It's a new user 
        }
    }
);
  • Yes, your code works well. Thank you. – Kota.M Jul 2 at 15:38

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.