<p>Matt and I managed to work this out together. Seems like setting the <code>pending</code> and <code>unverifiedEmail</code> attributes on the userModel before saving the user does the trick.</p>

<pre><code>$user = new UserModel();
$user-&gt;pending = true;
$user-&gt;unverifiedEmail = "username@domain.com";
craft()-&gt;users-&gt;saveUser($user);
</code></pre>

<p>Edit: Might also want to look into another syntax that I noticed in <a href="https://craftcms.stackexchange.com/questions/1425/how-to-add-link-an-entry-to-an-object-using-php">this question</a>.</p>

<pre><code>$user = new UserModel();
$user-&gt;status = UserStatus::Pending;
$user-&gt;email = "username@domain.com";
craft()-&gt;users-&gt;saveUser($user);
</code></pre>

CC BY-SA 3.0
2015-04-03T17:47:36.967Z
2015-04-03T18:01:33.880Z
2017-04-13T12:51:00.253Z
Douglas McDonald
<p>I'm writing a plugin to create users. The problem I'm having is when I create them Craft is automatically setting the user as "active". I want them to be "inactive" so that I can then send a verification email. I've look through the code and there appears to be no way to Create a user using <strong>craft()->users->saveUser($user)</strong> without having them always be active. </p>

<p>In the admin panel I do have the "Verify email addresses?" option checked.</p>

<p>Please help!</p>

CC BY-SA 3.0
2015-04-03T16:01:32.583Z
Just beacuse they are active does not mean that they can login yet. I believe that they still have to go through the email verification process to set their password, etc. Setting them as inactive would mean that they could never login or verify their email address. Is there some other reason you want them to be inactive?
Douglas McDonald
CC BY-SA 3.0
2015-04-03T16:07:34.263Z
I think rather the "inactive" I should've said "unverified". I don't want new users to be verified until they click the link in the verification email.
Matt V
CC BY-SA 3.0
2015-04-03T16:22:41.367Z
Not sure. But you might try setting the 'unverifiedEmail' property on the user model (vs 'email' property) before saving. Not sure if that alone will do it.
Douglas McDonald
CC BY-SA 3.0
2015-04-03T16:26:28.860Z
Fyi.. here is a list of all the [userModel attributes](http://buildwithcraft.com/classreference/models/UserModel#defineAttributes-detail) which might help. I see that there is also a 'pending' attribute which should probably be set to true, as well as the unverifiedEmail.
Douglas McDonald
CC BY-SA 3.0
2015-04-03T16:42:58.523Z
Ah! Yes! Thank you. I did see this earlier but it looks like "pending" and "unverifiedEmail" work together? Because I did try just setting "pending" to true and that did nothing. But setting both works.
Matt V
CC BY-SA 3.0
2015-04-03T17:45:54.253Z
Cool. Glad it worked.
Douglas McDonald
<plugin-development><users><user-profile>
Creating users as inactive
# Creating users as inactive

(Asked by: username_0 on 2015-04-03)

I'm writing a plugin to create users. The problem I'm having is when I create them Craft is automatically setting the user as "active". I want them to be "inactive" so that I can then send a verification email. I've look through the code and there appears to be no way to Create a user using **craft()->users->saveUser($user)** without having them always be active.

In the admin panel I do have the "Verify email addresses?" option checked.

Please help!

**Tags:** plugin-development, users, user-profile

> **Comments:**
> **username_1**: Just beacuse they are active does not mean that they can login yet. I believe that they still have to go through the email verification process to set their password, etc. Setting them as inactive would mean that they could never login or verify their email address. Is there some other reason you want them to be inactive?  
> **username_0**: I think rather the "inactive" I should've said "unverified". I don't want new users to be verified until they click the link in the verification email.  
> **username_1**: Not sure. But you might try setting the 'unverifiedEmail' property on the user model (vs 'email' property) before saving. Not sure if that alone will do it.  
> **username_1**: Fyi.. here is a list of all the [userModel attributes](http://buildwithcraft.com/classreference/models/UserModel#defineAttributes-detail) which might help. I see that there is also a 'pending' attribute which should probably be set to true, as well as the unverifiedEmail.  
> **username_0**: Ah! Yes! Thank you. I did see this earlier but it looks like "pending" and "unverifiedEmail" work together? Because I did try just setting "pending" to true and that did nothing. But setting both works.  
> **username_1**: Cool. Glad it worked.  

---

## 1 answers

### Answer by username_1 on 2015-04-03. Score: 2

Matt and I managed to work this out together. Seems like setting the pending and unverifiedEmail attributes on the userModel before saving the user does the trick.
$user = new UserModel();
$user->pending = true;
$user->unverifiedEmail = "username@domain.com";
craft()->users->saveUser($user);

Edit: Might also want to look into another syntax that I noticed in this question.
$user = new UserModel();
$user->status = UserStatus::Pending;
$user->email = "username@domain.com";
craft()->users->saveUser($user);


---

