Answers.Body: <p>Try <code>$isNew = $user-&gt;isNewForSite</code>.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-02-23T07:17:24.500Z
Answers.Text: Here you can get more detail about this
  https://docs.craftcms.com/api/v3/craft-base-elementtrait.html#isnewforsite
Answers.UserDisplayName: Taher Kathiriya
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-02-19T11:55:26.383Z
Answers.LastActivityDate: 2024-02-19T11:55:26.383Z
Answers.UserDisplayName: James Smith
Body: <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>
  
Tags: <craft3><users><extends>
Title: Event on new user created
ThreadText: # 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  
  
  ---
  
  