I have a custom multi-step form which collects user data and other detailed information, in the last step it has 2 options for user,
1) asks user to enter login details and submit to save record
2) to sign up/register and on submit store data and auto create account.

For step 2, I have used wp_insert_user() to create user and $wpdb->insert to save other detailed information of that user in record.

Note: I'm doing my all code on the same page as I'm not good in using functions,
if ( $_POST['register_account'] ) { //wp_insert_user() //$wpdb->insert; }

For Step 1, I have tried to use wp_signon() but it gives me Warning: Cannot modify header information - headers already sent by.

All I need is a simple custom login query to logged in and after login shows the user selected information from the previous steps of this form and on Confirmation, save this record to this login usermeta.
if ( $_POST['login_account'] ) { //logged in and show data; }

1 Answer 1


I'd suggest to read how the filters and hooks work inside WordPress here, that's the easiest way (and the recommended one) to add/alter the site functionality.

The wp_insert_user() function returns the new created user ID so I wouldn't use a custom query for inserting user records since you can use add_user_meta(): see the docs here

You have to call wp_signon() before outputting any HTML, see the notes from the function docs: https://codex.wordpress.org/Function_Reference/wp_signon

  • This function sends headers to the page. It must be run before any content is returned
  • This function sets an authentication cookie. Users will not be logged in if it is not sent.
  • Many thanks @Pabamato. Can you please guide me how custom_login() [in reference link example] from wp_signon() works? If a user clicks on submit button from my custom mutistep form, how wp_signon() function will work and perform login?
    – Max
    May 21, 2018 at 23:18
  • HI @max can't provide feedback without seeing your code but the idea is that you perform server validation for the form step 1 and if valid then you can call the wp_signon() function and then redirect to page 2 of the form.
    – Pabamato
    May 22, 2018 at 0:24
  • Thanks @Pabamato it works like a magic, but I'm still wondering how it knows to run that function without having any submit name, i.e <input type="submit" name="login_account">
    – Max
    May 23, 2018 at 8:18
  • I have another situation. You can find the code below. Thanks
    – Max
    May 23, 2018 at 8:19
  • <form><input name="username" type="text" /><input name="password" type="password" /><input type="submit" name="login_account">. I have placed wp_signon() in functions file and its working and make user logged in. But I also want to hide form after login and show user info here. if ( $_POST['login_account'] ) { //show userinfo } else { //hideform } , but `$_POST['login_account']' check is not working.
    – Max
    May 23, 2018 at 8:21

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.