When you are creating a new user programatically with user_save, you would also need to manually programatically create the profile2 type for the new user account if you are using Profile2. The following code should solve the problem:

<?php
// Where 'main' is your profile2 type machine name.
$profile = profile2_create(array('type' => 'main', 'uid' => $user->uid));

// Add in the necessary custom fields and values.
$profile->field_just_example[LANGUAGE_NONE][0]['value'] = 'Awesome!';

// Save the profile2 to the user account.
profile2_save($profile);
?>
Published on 25 December 2013 - 7:26am