I am trying to force add a location to a user's profile2 just after the user register's an account. The user's are able to add locations to their profile by using flags, but since there are no locations just after the user registers, the rules add fails because the locations list has not been initiated.

The below code is what I currently have:

if (isset($account->is_new) && !empty($account->is_new)) {
  function user_account_presave_user_presave(&$edit, $account, $category) { 
    global $user;

    // Load profile2.
    $profile = profile2_load_by_user(array('type' => 'next', 'uid' => $user >uid));

    // Add in the necessary custom fields and values.
    $profile->field_next_destination['und'][] = array(
      'longitude' => '0.0',
      'latitude' => '0.0',

    // Save the profile2 to the user account.


I am not sure if the IF statement should be in the Function, but if it is not, the Function fails to allow users to register because the CAPTCHA reuse attack function is triggered.

Has anyone ever run into this?

Thank you!

1 Answer 1


Try using hook_user_insert instead. The $account will have $account->uid set at that stage.

P.S wrapping hook_user_presave in that condition looks wrong and probably won't work with the hook registry cache.

  • I am still getting a "CAPTCHA session reuse attack detected."
    – Bestinc
    Jul 24, 2016 at 21:22
  • "CAPTCHA session reuse attack detected" is a different issue, probably related to caching of the page/form where the captcha is being shown. see _captcha_get_posted_captcha_info for the related code. Jul 25, 2016 at 0:30
  • I have turned off recaptcha in an attempt to isolate the issue as well as use user_insert, but it doesn't seem like it it currently doing anything. Will be doing a db_insert be what I have to do?
    – Bestinc
    Jul 26, 2016 at 1:03
  • If the Profile2 profile hasn't been created, you may need to create it with profile2_create Jul 26, 2016 at 1:25
  • I am unfortunately not gaining any traction on this.
    – Bestinc
    Jul 26, 2016 at 23:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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