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

WordPress custom login form using Ajax

A few issues I can see but no guarantee it’ll entirely fix the problem(s) –
can you ensure WP_DEBUG and WP_DEBUG_LOG are defined as true in your wp-config.php – any errors during runtime should then appear in wp-content/debug.log.

  1. You have ! isset( $_POST ) as a conditional to check the request, but this will always be false because the $_POST superglobal is always set – it’s just empty unless there is POST’ed data. Instead, use $_SERVER['REQUEST_METHOD'] !== 'POST'
  2. I can’t see any need for the wp_setcookie call. The function is deprecated and is just a wrapper for wp_set_auth_cookie, which is called & handled by wp_signon anyway.
  3. If you send a redirect server-side (i.e. via PHP), the AJAX client (your browser) will silently follow the redirect and then return the response of said redirect for your callback (in your case, the homepage HTML). You would be better to send back JSON & instruct your JavaScript to do the redirect client-side (e.g. window.location = responseData.redirectUrl)

Related Posts:

  1. Admin username and password
  2. User registration followed by automatic login
  3. esc_attr() right way and use
  4. Enforcing password complexity
  5. Adding “Remember Me” in custom login
  6. Does My Child-Theme Functions.php Need if{die} Security In It? [duplicate]
  7. How to change the wp-login.php page title?
  8. How build a custom login/register form with error handling?
  9. How Attackers write script into my php files?
  10. Change the footer text on the login page
  11. Changing user_nicename
  12. Renaming wp-content folder dynamically
  13. How do I create a WP user outside of WordPress and auto login?
  14. Security – Ajax and Nonce use [closed]
  15. Which ways can be used to log in to WordPress?
  16. Can I write ‘RewriteCond’ using ‘functions.php’?
  17. Is it unsafe to put php in the /wp-content/uploads directory?
  18. WordPress 4 invalid username special charachters issue
  19. How to place login logout link on menu that redirects users back to current page?
  20. How to turn off redirection from ‘domain.com/login’ to ‘domain.com/wp-login.php’
  21. How to resolve error “Cookies are blocked due to unexpected output.”?
  22. Using a nonce in a Custom Login Form
  23. Constructing a custom login form using ajax
  24. automated tests as a user?
  25. Sanitize get_query_var() url parameters
  26. Remove username in emails or swap username for email
  27. woocommerce and is_user_logged_in() if not redirect to homepage
  28. When must I use and verify nonce?
  29. Check if user is logged in when clicking certain links on certain pages
  30. Hiding WordPress Plugin Source Code
  31. Is this code malidcous
  32. PHP If user is logged in & on home page redirect
  33. WordPress shows registration link for non logged users
  34. Creating login session via CURL
  35. Evaluations of two wordpress security plans against php code injection attack
  36. Recovering WP Login Credintials in Code?
  37. Is it necessary to sanitize wp_set_password user input?
  38. How to give new users two specific user role options upon WordPress user registration
  39. Wp-login appears White Screen, Error: Cannot modify header information
  40. How to: PHP Log Out Link?
  41. Login/logout in header
  42. Why is my cookie not unsetting upon logout? [closed]
  43. User management system similar to wordpress one?
  44. Detect session/cookie variable in wordpress to prevent access to documents
  45. Is there any risk setting WordPress file permissions and FS method to ‘direct’ on localhost?
  46. SQL Injection blocked by firewall
  47. How to prevent XSS alter custom global javascript object & methods in WordPress
  48. Programmatic Login from 3rd Party site
  49. Cannot access wp-admin/wp-login.php (WordPress backend) anymore, what could be wrong?
  50. How to debug my custom login form looping intermittently
  51. Generating an nonce for Content Security Policy and all scripts – How to make it match/persist for each page load?
  52. getting logged in user info (wp-load.php) from parent directory
  53. Cannot execute php files in wp-content
  54. How do I get around “Sorry, this file type is not permitted for security reasons”?
  55. Problem with login form
  56. Login to wordpress by clicking a link and specifying usernaname and password in url
  57. Security: blocking direct access of php files
  58. Log in / Log Out Custom Button
  59. Should `wp_login` be used since it’s deprecated?
  60. How to redirect users based on role and content of redirect_to?
  61. Correct and safe way to include php content in my page
  62. Change CSS based on is_user_logged_in
  63. How to display login form anywhere, when user isn’t logged in, without redirecting?
  64. How can I open up my administrative panel to everyone?
  65. Password minimum length in personal subscription [closed]
  66. How to add API security keys into JS of wordpress securely
  67. Is it best to avoid using $wpdb for security issues?
  68. Hardening uploads folder in IIS breaks images
  69. Troll the hackers by redirecting them
  70. Security updates to 3.3.2
  71. how to prevent wordpress admin from logging in via woocommerce my-account page
  72. malware undetectable by multiple scans
  73. How can I add a new row in a separate database when someone registers via WordPress?
  74. Decoded malware code [closed]
  75. One account with multiple logins
  76. Lost in trying to create user database system
  77. Shortcode to log user into current URL
  78. PHP getting error when trying to access WP-Admin Dashboard
  79. I installed WordPress locally now how do I login?
  80. If user is logged in not working
  81. Change homepage content if user is logged in – BuddyPress
  82. Updating From Mobile App – Exposing Site to Hacking
  83. Show login greeting above sub-menu links?
  84. is_user_logged_in returning nothing on custom page
  85. security concerns if using html data-* attribute for l10n?
  86. Help with accessing wp-admin page and resolving error messages
  87. How to correctly escape an echo
  88. Reject all malicious URL requests functions.php
  89. portfolio site – about this site section – is it safe to post some code
  90. Removing “There is no account with that username or email address.” error message in “/wp-login.php?action=lostpassword”
  91. Can’t log in to WordPress wp-admin after adding code to functions.php
  92. Check if user had autologin & if so, logout
  93. echo cutom css code to WordPress page template file ? is this safe?
  94. Admin Panel 404 Error after login
  95. PHP warning – Use of undefined constant ‘FORCE_SSL_LOGIN’ ‘FORCE_SSL_ADMIN’ on wp-config.php
  96. How to block specific user id in custom login form?
  97. Log out without confirmation request (nonce)
  98. Having trouble creating two shortcodes, one for logged in user and one for visitors
  99. Call WP Rest-Api to GET /users/me returned NOTHING in console
  100. How to secure my php forms
Categories PHP Tags login, php, security
How to insert a Button or custom text on twentyseventeen header
How to stop featured image thumbnail [set as background image] on blog index page just repeating same image across all posts

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