Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-02T15:38:14.717Z
Answers.Text: Yes, your code works well. Thank you.
Answers.UserDisplayName: Kota.M
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-06T18:52:28.487Z
Answers.Text: Thankfully I found this one my second search, works perfect!
Answers.UserDisplayName: mcclaskiem
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-02T15:03:12.347Z
Answers.LastActivityDate: 2019-07-02T15:03:12.347Z
Answers.UserDisplayName: Oli
Body: <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>
  
Tags: <craft3><php><registration>
Title: Detect if it is a new user or not in PHP
ThreadText: # 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!  
  
  ---
  
  