I want to add a content type after a user registers to the site.

I tried hook_user_save() but it saves the content type before the user confirms his e-mail.

Is there a hook after e-mail confirmation?


Although this approach uses modules, I add nodes after users confirm their e-mails using Logintoboggan and Rules. The Logintoboggan rules integration adds a new event, When the user account is validated, which will allow you to perform actions upon e-mail confirmation.

  • Be sure to install the LoginToboggan Rules Integration module from the LoginToboggan project. – Batandwa Aug 21 '14 at 0:02

This does the job for me:

 * Implements @see hook_user_presave
function hook_user_presave(&$edit, $account, $category) {
  if ($account->uid // user is not new
      && $account->status === "0" && $edit['status']==1) { // user is being activated
  • I had to use if($account->uid && $account->original->status == 0 && $account->status == 1) – user2534880 Jul 26 '16 at 11:01

If you're using the LoginToboggan module for e-mail validation and you don't wish to use the rules module you can simply mimic the module's validation response (exploiting a temporary logintoboggan_email_validated = TRUE account property that's pushed to hook_user_update) yourself in code:

 * Implement hook_user_update()
function yourcustommodule_user_update(&$edit, $account) {
  if (!empty($account->logintoboggan_email_validated) && !isset($account->your_custom_action)) {
        $account->your_custom_action = TRUE;

        // Do what you want here


Since core and other modules will also invoke hook_user_update you'd want to implement something to avoid repeated actions. In this example I set another property on the $account once the action is initiated but you can impose finer control if necessary.

Note that if using LoginToboggan for automatic e-mail validation IOco's method won't work (among the many reasons - during a hook_user_presave, the $account->status == 1 (it's just the role is in your elected "pre-authorised" state).

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.