<p>In Craft 3 you would do:</p>

<pre><code>Event::on(
    Elements::class, 
    Elements::EVENT_AFTER_SAVE_ELEMENT,
    function(Event $event) {
        if ($event-&gt;element instanceof \craft\elements\User &amp;&amp; $event-&gt;isNew) {
            // It's a new user 
        }
    }
);
</code></pre>

CC BY-SA 4.0
2019-07-02T15:38:14.717Z
Yes, your code works well. Thank you.
Kota.M
CC BY-SA 4.0
2020-12-06T18:52:28.487Z
Thankfully I found this one my second search, works perfect!
mcclaskiem
CC BY-SA 4.0
2019-07-02T15:03:12.347Z
2019-07-02T15:03:12.347Z
Oli
<p>I have been developing some plugin code for my registration form in Craft 3.</p>

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

<p>It would be grateful for me if someone tell me how to do it.</p>

<craft3><php><registration>
Detect if it is a new user or not in PHP
# Detect if it is a new user or not in PHP

(Asked by: username_0 on 2019-07-02)

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.

**Tags:** craft3, php, registration


---

## 1 answers

### Answer by username_1 on 2019-07-02. Score: 3 | Accepted answer

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

> **Comments:**
> **username_0**: Yes, your code works well. Thank you.  
> **username_2**: Thankfully I found this one my second search, works perfect!  

---

