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

Login to admin by frontend form?

What you have should work – although you should not use $_SESSION (as Tom already noted). Also ID, user_pass, and user_login are all top level in the user object.

Here’s what I would try:

$email = sanitize_email( $_POST['email'] );
$pass  = $_POST['password'];
$user  = get_user_by( 'email', $email );

if ( wp_check_password( $pass, $user->user_pass, $user->ID ) ) {
   wp_set_current_user( $user->ID );
   wp_set_auth_cookie( $user->ID );
   do_action( 'wp_login', $user->user_login );
   wp_safe_redirect( wp_get_referer() );
   exit();
}

Related Posts:

  1. How to Change the Default Home Page for the WordPress Dashboard?
  2. is_admin() returns true when using admin-ajax.php from front end script
  3. Are there any action like ‘init_frontend’
  4. Cannot access admin panel
  5. front end logo upload like happytables
  6. Conditional check for front-end which includes ajax
  7. Daily notices of failed login attempts for non-existent admin user
  8. Setting Login with User Name and Password default option for Jetpack Admin Login
  9. I keep getting logged out in Firefox
  10. Error thrown. Cannot create references to/from string offsets
  11. How to determine if an admin is logged in outside the loop
  12. front end editing using iFrames, best approach?
  13. Unable to login, old site with previous developer gone
  14. WordPress Frontend Check If Current User Is Administrator
  15. Using shared SSL for login/admin
  16. wp-login behind nginx reverse-proxy inaccessible — bad redirect?
  17. Can’t access dashboard as administrator, login as any other level works though
  18. WordPress Admin Login Redirect Problem
  19. Unable to Access WP Admin or Login buttons after Migration
  20. using rewrites to secure login page
  21. Client system for media review?
  22. How to disable accessing the custom post types from frontend via a link?
  23. WordPress administration Over SSL – To Force SSL Logins and SSL Admin Access
  24. Keep Logged in Users out of Admin Panel
  25. Unable to get to the admin panel
  26. I can’t access the login panel on my offline website
  27. Admin login not working
  28. Can’t login to my admin area
  29. Does deleting the table users prevent all logins?
  30. Locked out of WordPress website from wrong amount of login attempts
  31. current_user_can(‘administrator’) not working in custom login
  32. Send admin to a different login than users?
  33. Want to know who is login Admin/User
  34. Remove iPhone detection on login page
  35. Any known plugins for master admin login to edit all on front end?
  36. How to show WordPress admin dashboard forms on front-end?
  37. Error “Sorry, you are not allowed to access this page”
  38. I can’t access login page
  39. Can you check if https is enabled on frontend from admin
  40. Admins loggin in to our wordpress site default to the admin page
  41. Disabling “View” mentions from backend?
  42. WordPress login not working
  43. Login to Admin Dashboard Problem
  44. WordPress login process is hanging
  45. WordPress “Hide WP” Gives Me Error After Admin Login [closed]
  46. Editing post in admin panel
  47. Scripts are not called until I login from wordpress backend
  48. Disable wp-admin log on lightbox overlay
  49. Lock Display Name To Nickname
  50. How to cancel redirection to admin side
  51. Can’t access my wp admin: captcha images invisible, gives me error message
  52. 2FA for admin login only, is it doable?
  53. 500 error for regular users, not for admin
  54. What are the standard admin CSS id/class tags?
  55. Admin Ajax is returning 0
  56. Add custom column to Users admin panel
  57. wp_verify_nonce vs check_admin_referer
  58. Add a Separator to the Admin Menu?
  59. How to determine whether we are in add New page/post/CPT or in edit page/post/CPT in wordpress admin?
  60. how to know if admin is in edit page or post [duplicate]
  61. Modal window from within WordPress admin
  62. Where in WP can I check history or log of updates of plugins etc?
  63. Adding a custom admin page
  64. How does admin-ajax.php work?
  65. How to remove entire admin menu?
  66. How do I remove dashboard access from specific user roles?
  67. How can I speed up my WP admin section?
  68. How to pass parameters to admin_notices?
  69. Admin: very slow edit page caused by core meta query
  70. if admin is logged in
  71. Search posts by ID in admin
  72. Setting admin edit panels & metaboxes positions and visibility for ALL users and admins
  73. Find out which moderator approved comment?
  74. The website cannot display the page
  75. How To Remove WordPress Version From The Admin Footer
  76. Sort pages in loop by admin’s page attributes order field?
  77. Edit “thank you for creating with WordPress” in version 3.3.1
  78. Hide other users’ posts in admin panel
  79. Set Default Admin Colour For All Users
  80. Editor Styles and Typekit
  81. How to show ‘login error’ and ‘lost password’ on my template page?
  82. WordPress admin stylesheet
  83. This CSS Stuffing Works, But Is This A Good Practice?
  84. Is it possible to create a WordPress tour? V3.3.1
  85. Securing Admin Accounts – Username Discovery
  86. How to save dismissable notice state in WP 4.2?
  87. How do I optimize a custom post type admin page with 25,000 posts?
  88. Settings API – adding setting fields dynamically?
  89. Disable Media Uploads to non Admin Users
  90. How do I load a CSS style into WordPress admin area only?
  91. Allowing admin-ajax.php to receive “application/json” instead of “x-www-form-urlencoded”
  92. Can an admin check passwords of registered users?
  93. How can I target WordPress 3.8 new interface MP6 with CSS?
  94. Redirect user using the ‘wp_login_failed’ action hook if the error is ’empty_username’ or ’empty_password’
  95. Notification that the admin is online
  96. Does wordpress create activity, update logs?
  97. sort child pages on admin
  98. How-to make the admin area mobile friendly [closed]
  99. How to remove list view from media library?
  100. How to disable the “Your site has updated to WordPress x.y.z” admin email?
Categories admin Tags admin, front-end, login
Adding in additional pages into a custom theme
Can’t convert ACF datepicker value to DateTime oject – gives me a boolean

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