diff --git a/profile2.module b/profile2.module index badcfa9..5fffc9a 100644 --- a/profile2.module +++ b/profile2.module @@ -416,13 +416,24 @@ function profile2_attach_form(&$form, &$form_state) { } } $form['#validate'][] = 'profile2_form_validate_handler'; - $form['#submit'][] = 'profile2_form_submit_handler'; - // Insert another submit callback just before the 'user_register_submit' execution. + // Search for key of user_register_submit() callback. $submit_key = array_search('user_register_submit', $form['#submit']); if ($submit_key !== FALSE) { + + // Insert submit handler right after the registration submit, so + // the user profile will be created as early as it is possible. + array_splice($form['#submit'], $submit_key + 1, 0, array('profile2_form_submit_handler')); + + // Insert another submit callback right before the + // user_register_submit() callback is executed. array_splice($form['#submit'], $submit_key, 0, array('profile2_form_prepare_submit_handler')); } + else { + // Fallback if some contrib removed user_register_submit() + // callback from form submit functions. + $form['#submit'][] = 'profile2_form_submit_handler'; + } } /**