Programatically creating a user not appearing in Users index table I'm trying to programatically create a user (once the user submits a form through Sprout Forms). The user doesn't seem to appear in the Users section of the CP.

I've ensured the user is being added correctly - I can even see a row in the craft_users database table. Going directly to admin/users/349 (the ID of the newly added user) shows all the user details.

It's been suggested that I need to index the new element data - but not sure how to do this.

$content = $entry-&gt;getContent();

$user = new UserModel();
$user-&gt;username         = $content['email'];
$user-&gt;email            = $content['email'];
$user-&gt;unverifiedEmail  = $content['email'];
$user-&gt;firstName        = $content['firstName'];
$user-&gt;lastName         = $content['lastName'];
$user-&gt;newPassword      = $content['password'];
$user-&gt;pending          = true;

$success = craft()-&gt;users-&gt;saveUser($user);

if ($success) {
    craft()-&gt;search-&gt;indexElementAttributes($user);

    // Assign them to the default user group
    craft()-&gt;userGroups-&gt;assignUserToDefaultGroup($user);

    // Send the activation email
    craft()-&gt;users-&gt;sendActivationEmail($user);

    // Update the Element Index
    craft()-&gt;search-&gt;indexElementAttributes($user);
}
For anyone's future benefit - this happens due to the fact I'm adding the user in the sproutForms.saveEntry hook. That happens after it messes around with the fieldContext and contentTable options for the Entry. As such, the user is getting saved to the wrong context, so it won't appear...

A quick workaround for this is to move the following lines in SproutForms_EntriesService.php:133-135 to lines 120. This resets the field context back before the hook is called.

if ($transaction !== null)
{
    $transaction-&gt;commit();

    SproutFormsPlugin::log('Transaction committed');
}

// Reset our field context and content table to what they were previously
craft()-&gt;content-&gt;fieldContext = $oldFieldContext;
craft()-&gt;content-&gt;contentTable = $oldContentTable;

Craft::import('plugins.sproutforms.events.SproutForms_OnSaveEntryEvent');

$event = new SproutForms_OnSaveEntryEvent(
    $this, array(
        'entry'      =&gt; $entry,
        'isNewEntry' =&gt; $isNewEntry,
        'event'      =&gt; 'saveEntry',
        'entity'     =&gt; $entry,
    )
);

craft()-&gt;sproutForms-&gt;onSaveEntry($event);