1

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!

6
  • 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? Apr 3, 2015 at 16:01
  • 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
    Apr 3, 2015 at 16:07
  • 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. Apr 3, 2015 at 16:22
  • Fyi.. here is a list of all the userModel attributes which might help. I see that there is also a 'pending' attribute which should probably be set to true, as well as the unverifiedEmail. Apr 3, 2015 at 16:26
  • 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
    Apr 3, 2015 at 16:42

1 Answer 1

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 = "[email protected]";
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 = "[email protected]";
craft()->users->saveUser($user);
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.