Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Problem with logging in WP users automatically

In the end, wp_signon() was the solution, as the cookie was apparently not set with the code I was using.
I followed this solution
https://gist.github.com/iandunn/8162246
to circumvent a need for password and added these functions to functions.php.

I also moved the autologin code from ‘init’ to template where it executes before any headers are sent or any html is output (above wp_head() ).

So now it looks like this:

if (!is_user_logged_in()) :
    if (isset($_GET['user_redirect'])) :
    $user_login_string = intval($_GET['user_redirect']);
    /* Fancy user id retrieval stuff */ 
    $user_data = get_userdata($decrypted_user_id);
    if ($user_data) :
      $user_login = $user_data->user_login;
      $loggedin = programmatic_login( $user_login ); // <--- Gist function
      if ($loggedin) :
        wp_redirect('/userpage');
        exit();
      endif;
    endif;
  else :
    wp_redirect(wp_login_url());
    exit;
  endif;
endif;

And it works, wie, yay, happy dance.

Related Posts:

  1. How to customise wp-login.php only for users who are setting a password for the first time?
  2. Correct passwords keep appearing as incorrect
  3. How to invalidate `password reset key` after being used
  4. Chosen user password in registration is not being accepted on Login
  5. Separate registration and login for different roles
  6. SSO / authentication integration with external ‘directory service’
  7. How to prefill WordPress registration with social details
  8. Check for correct username on custom login form
  9. Woocommerce registration page [closed]
  10. WordPress registration message
  11. How to remove the WordPress logo from login and register page?
  12. Login email after registration never sent or received
  13. Add Confirm Password field in wp-login.php Password Reset page
  14. I want to disable E-Mail verifcation / activation when a user signs up for my WordPress site
  15. How do I check if a post is private?
  16. Receiving “This content cannot be displayed in a frame” error on login page
  17. Give visitor access to password protected page/post via external script
  18. Send reset password link to user from custom lost password form
  19. What hooks should I use for pre-login and pre-registration actions?
  20. How can I retrieve the username and password from my WordPress installation?
  21. password protect individual pages
  22. Is there any good tutorial to write custom login, registration and password recovery forms? [closed]
  23. Change register form action url
  24. Is it possible a one click user registration with Facebook or Twitter (or other Social Networks)?
  25. Register/Login using only phone number?
  26. How to determine if a user has not changed default generated password
  27. Right practice to edit WP reset password email
  28. Force users to register in order to view website [duplicate]
  29. How do I force “users must be registered and logged in” on subsites?
  30. auto login after registeration for wp-members plugin
  31. How To Change Wp Register/Login URL Permanently To My Custom Page
  32. Private page protected with username and password
  33. reset password link redirect to login page
  34. Password protect media attachment – share across guests
  35. Password reset – Disabled for LDAP accounts
  36. How to modify the action attribute of the wp-login.php?action=register form?
  37. Why wp_update_user doesn’t update user_activation_key on users with apostrophes in their email?
  38. Forgot Password/ Password Reset Page does not exist
  39. Forgot password needs to redirect from wp-login to a custom page
  40. Disabling standard registration login with username/email and password?
  41. Login form doesn’t log in
  42. Get the url of custom login page in the registration page
  43. By registering always make uppercase the first letter of the login
  44. Show reCaptcha on Custom Frontend Login & Register Form [closed]
  45. Best option to implement external register/login to WP from self-made API
  46. Auto Login After Registration
  47. How can I change the email sender name from wordpress to (myblogname) on the “lost password” email?
  48. Disable all other page except index,register,login till user login
  49. How to password-protect everything except the logo
  50. What speaks against using a custom login.php / register.php to wordpress?
  51. Is there anyway to get the inputted password string from the login form?
  52. How can I password protect a WordPress site without requiring users to log in?
  53. How do I add Login fields and registration link to the header?
  54. How to make a user be able to register if such a login already exists?
  55. Password not resetting on wordpress?
  56. autocomplete=”off” WordPress Login
  57. WordPress not logged in locally with correct username and password
  58. wordpress login without password just email address (NO 2 factor authentication with email)
  59. Sending new registration meta values to admin by email
  60. Are login functions considered part of the WP backend?
  61. WordPress registration page template
  62. Can I protect a type of content site-wide with a single password?
  63. Removing “public” user registration without completely turning it off?
  64. Password recovery URL has error – but not found in code or db
  65. Disable registration on certain condition
  66. what is the best and safest way to allow users to register to site
  67. Temporally disable password to login with empty password?
  68. I need to find which is the file that checks the DB for correct login (username, password)
  69. Updated : how to make email optional while user registration using default wordpress form
  70. Problem in auto login after registration
  71. Login form does not store/remember/suggest users password
  72. WordPress password reset not working
  73. New user password confirmation sending wrong URL
  74. Locked out of WordPress admin area [closed]
  75. Global login to password protected pages
  76. Disable / Remove Password for Login WordPress
  77. How to password protect pages in WordPress
  78. Updating usermeta from login redirect to billing address
  79. WordPress auto login user after registration only from a specific page
  80. User account activation links are lacking query strings
  81. User login without username, only password
  82. Login user after registration programmatically
  83. wp_lostpassword_url not escaped
  84. How to get rid of the username of registration form in theme my login wp plugin?
  85. Where do I find “log in” and “register” link which are located on the top right corner?
  86. How to force login after user browses for a few minutes or browses a few pages?
  87. Registration and Login form
  88. Trouble logging in and/or changing password
  89. WordPress and Magento: let WordPress manage user registration and logins?
  90. Cannot login with correct username and password anymore
  91. Cant login, Password MUST be reset error, after reset
  92. how to add custom word press regisration form in word press 3.5 with out module [closed]
  93. Click on banner to register to the blog
  94. How to put Login, Register and newsletter widget on the same page?
  95. make a login system for site visitors
  96. How to create a fully functional user registration in WordPress?
  97. Change password reqts with NO plugin without breaking resetpass link?
  98. Log in a user upon password reset?
  99. Customize From and email address on password reset
  100. In Django, how do I know the currently logged-in user?
Categories login Tags login, password, user-registration
Scheduling posts in database
Changing admin sub-domain in WordPress multisite

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress