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.
profile2_save($profile);
}
}
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!