Create Profile2

Public

Example of implementation in hook_node_insert()

Get raw version
php
  1. function mymodule_user_insert(&$edit, $account, $category) {
  2. $profile = profile2_create(array('type' => 'main', 'uid' => $account->uid));
  3. profile2_save($profile);
  4. $profile = profile2_load_by_user($account);
  5. //main is an id of default profile2 profile type
  6. $profile = $profile['main'];
  7.  
  8. //using a wrapper for do the heavy lifting
  9. $wrapper = entity_metadata_wrapper('profile2', $profile);
  10. $wrapper->field_first_name->set(ucfirst(devel_generate_word(mt_rand(6, 12))));
  11. $wrapper->field_last_name->set(ucfirst(devel_generate_word(mt_rand(6, 12))));
  12. $wrapper->save();
  13. }