0

When creating a new user with user_save, it seems to get the "approved" role automatically, even though I pass an empty array to $user->roles.

How can I force the programatically created user to need admin approval before being activated?

  • I suppose (but did not check) that you can set the status to 0. That should create a 'disabled user'. I do however not know if that will trigger all mails that would otherwise be sent with the UI. – Neograph734 Sep 18 '18 at 19:32
  • Thanks. I think status 0 is a blocked user though - user can't log in, doesn't get any errors, and no mails are triggered when the user is activated. – Rasmus B Sep 18 '18 at 19:34
  • I am pretty sure the admin approval does nothing more than setting the status to 1 e.g. from blocked to active. There is no such thing as an "approved" role. – Neograph734 Sep 18 '18 at 19:36
  • Whats the english name of the user role with id 2? It is enabled by default and checkbox is disabled in backend. – Rasmus B Sep 18 '18 at 19:48
  • I am sorry, but a fresh Drupal installation creates the anonymous user as uid=0 and the admin as uid=1. There is no user 2. – Neograph734 Sep 18 '18 at 20:03
0

Step1
Not need to follow it compulsary
You don't need any third-party modules. Drupal core has the option to verify the email the user enters, and the option for the administrator user to approve the accounts users create. In Drupal 7, those settings are on /admin/config/people/accounts. enter image description here
Step2

  • Once you prepare your $user object and use it on user_save function you have to follow below steps to send the mail.


$userData = user_save($user);
$account = user_load($userData->uid);
$op = 'register_pending_approval';
$status = _user_mail_notify($op, $account);
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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