<p>Try <code>$isNew = $user-&gt;isNewForSite</code>.</p>

CC BY-SA 4.0
2024-02-23T07:17:24.500Z
Here you can get more detail about this
https://docs.craftcms.com/api/v3/craft-base-elementtrait.html#isnewforsite
Taher Kathiriya
CC BY-SA 4.0
2024-02-19T11:55:26.383Z
2024-02-19T11:55:26.383Z
James Smith
<p>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 </p>
<pre><code> Event::on(
        User::class,
        User::EVENT_AFTER_SAVE,
        function (ModelEvent $event) {
            $user = $event-&gt;sender;
            $isNew = $event-&gt;isNew;
    
            if ($isNew) {
                Craft::info('is new', __METHOD__);
            } else {
                Craft::info('is not new', __METHOD__);
            }
        }
    );
</code></pre>

<craft3><users><extends>
Event on new user created
# Event on new user created

(Asked by: username_0 on 2024-02-17)

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__);
            }
        }
    );

**Tags:** craft3, users, extends

---

## 1 answers

### Answer by username_1 on 2024-02-19. Score: 2 | Accepted answer

Try `$isNew = $user->isNewForSite`.

> **Comments:**
> **username_2**: Here you can get more detail about this https://docs.craftcms.com/api/v3/craft-base-elementtrait.html#isnewforsite  

---

