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

Infinite loop when logging out using custom login form

I am speculating here after reviewing your logic/comments above, yet let’s try as follows

Possible issue:

During login, although you are setting the auth cookie, you are not setting the current user and this is potentially the cause of the break-down upon logout due to is_user_logged_in returning a false-positive/negative result.

Possible resolution:

In your validation-room.php add a call to wp_set_current_user, as when entering your callback mb_page_redirects on the template_redirect hook, you are relying on is_user_logged_in to function correctly, which itself checks the state of the global $current_user variable.

Under the hood is_user_logged_in calls wp_get_current_user which calls _wp_get_current_user which fires a filter determine_current_user that calls two internal callbacks wp_validate_auth_cookie and wp_validate_logged_in_cookie.

It is possible that the initial improper validation and later subsequent calls to wp_logout and wp_set_current_user are somehow causing an issue.

$mb_field_room  = ( isset( $_POST[ 'mb_field_login' ] ) ? $_POST['mb_field_login'] : null );

if( $mb_field_room || wp_verify_nonce( $mb_field_room, 'mb_action_login' ) || !empty($mb_field_room) ) {
    $mb_meeting_log = isset($_POST['log'])  ? $_POST['log'] : null;
    $mb_meeting_pwd = isset($_POST['pwd']) && $_POST['pwd'] == '{mb_login_password}' ? 'password' : null;

    $user = get_user_by('login', $mb_meeting_log);

    wp_clear_auth_cookie(); // let's be sure about it...
    wp_set_auth_cookie( $user->ID, true, true );
    wp_set_current_user( $user->ID, $user->user_login );
}

Related Posts:

  1. Adding “Remember Me” in custom login
  2. How build a custom login/register form with error handling?
  3. How to redirect users to custom lostpassword page?
  4. WordPress 4 invalid username special charachters issue
  5. How to turn off redirection from ‘domain.com/login’ to ‘domain.com/wp-login.php’
  6. PHP If user is logged in & on home page redirect
  7. Wp-login appears White Screen, Error: Cannot modify header information
  8. Problem with login form
  9. How to redirect users based on role and content of redirect_to?
  10. Removing “There is no account with that username or email address.” error message in “/wp-login.php?action=lostpassword”
  11. Need help with AJAX login to call php in functions.php to handle redirects based on user cap (role)
  12. wp-login.php?redirect_to=https problem
  13. Redirect users not logged in to the standard login page (and back) from some posts and pages
  14. wp_login_url always redirects me to wp-admin
  15. wp-login – unable to redirect user to a custom login url
  16. Redirect to current URL and append specified URL parameter on unsuccessful login through Elementor login form widget
  17. Login to wordpress by clicking a link and specifying usernaname and password in url
  18. Log in / Log Out Custom Button
  19. Set Cache-Control header for 301 redirects
  20. Should `wp_login` be used since it’s deprecated?
  21. Moving code from theme header to functions.php
  22. Change CSS based on is_user_logged_in
  23. How to display login form anywhere, when user isn’t logged in, without redirecting?
  24. How can I open up my administrative panel to everyone?
  25. Showing latest post without 301 redirect
  26. Having Issue on Redirecting With Session in WordPress
  27. Using a $GET parameter from a URL, to redirect to a URL (WordPress)
  28. WordPress redirect redirecting too many times or not at all
  29. how to prevent wordpress admin from logging in via woocommerce my-account page
  30. How to hook a logout funtion for specific usr role in wordpress?
  31. Using Argument from Function to Re-Direct Visitor (WordPress)
  32. I am receiving a pluggable.php warning sign on my only http:// page
  33. How can I add a new row in a separate database when someone registers via WordPress?
  34. Login redirect. Check user meta and redirect accordingly
  35. Where to insert redirect code based on http_referer?
  36. Is this a correct usage of ob_start() in my WordPress project?
  37. How to allow download url redirection only if user logged in WordPress site?
  38. How do I create a function that modifies a message in the wp-login.php file?
  39. One account with multiple logins
  40. Lost in trying to create user database system
  41. Shortcode to log user into current URL
  42. PHP Redirect condition
  43. PHP getting error when trying to access WP-Admin Dashboard
  44. I installed WordPress locally now how do I login?
  45. If user is logged in not working
  46. Change homepage content if user is logged in – BuddyPress
  47. Manually Create PHP Page For A Redirect
  48. redirect doesn’t work while using example code
  49. Show login greeting above sub-menu links?
  50. Redirect to current user page upon link click
  51. Ajax URLs without #!, how to prevent falling into single.php on load or reload?
  52. is_user_logged_in returning nothing on custom page
  53. Writing a link cloaking plugin
  54. WordPress permalink issue
  55. WP insert post Redirect after function has executed
  56. Help with accessing wp-admin page and resolving error messages
  57. How to redirect non logged in mobile users to page on same site?
  58. How to define a rule in functions.php that ONLY disables the default wp functionality that undesirably changes ‘&’ to ‘#038;’?
  59. Download file and redirect to page or vice versa
  60. Add more user roles to a PHP logout redirect function [closed]
  61. Disable redirect to homepage after successful Login, Stay on Current Page
  62. Can’t log in to WordPress wp-admin after adding code to functions.php
  63. 404 on old link after changing post url
  64. Custom Login page, redirection and restrictions
  65. WordPress url By country code?
  66. Check if user had autologin & if so, logout
  67. wp_login_form() redirect same page
  68. how can i redirect dynamic URL in worpress base on ID in htaccess or wp-config or function.php
  69. Admin Panel 404 Error after login
  70. PHP warning – Use of undefined constant ‘FORCE_SSL_LOGIN’ ‘FORCE_SSL_ADMIN’ on wp-config.php
  71. How to block specific user id in custom login form?
  72. Log out without confirmation request (nonce)
  73. Implementing a multilingual WordPress site by installing several instances of WordPress and redirecting
  74. WordPress on Ubuntu – “File not Found” for home.php – Trying to Redirect to Root Folder
  75. Having trouble creating two shortcodes, one for logged in user and one for visitors
  76. Call WP Rest-Api to GET /users/me returned NOTHING in console
  77. Determine user destination on wp-login.php
  78. Remove all feeds and return custom 404 page
  79. Restrict wordpress access to logged users only
  80. Menu not updating for logged in users after redirect
  81. how to use auth_redirect() redirect visitor to login page if they are not login when they click account and order page?
  82. Issues adding Recaptcha v3 to WordPress Registration
  83. Redirect User when they click Menu Option
  84. Display specific page if user signed in
  85. Change Login or Logout text based on status
  86. WordPress: Redirect Main Site to Subsite in Multisite Where user is NOT logged in
  87. Refresh page after login with litespeed cache
  88. Redirect after login depending on the URL
  89. Redirect after login when WordPress in subdirectory
  90. Redirecting the lost password page request when using a custon login page
  91. How do I send a POST request with params with WordPress REST API
  92. Login redirects to home page and doesn’t log in
  93. is_user_logged_in() not working in homepage
  94. ERR_TOO_MANY_REDIRECTS / To Force SSL Logins and SSL Admin Access
  95. WordPress Redirect / Add_Rewrite_Rule – Non Index.php Page
  96. Check if a user is logged into my WordPress site which is on a different server
  97. Override 404 when navigating to single php file
  98. Newbie question. Login/Registration. New PHP page
  99. Submit to itself don’t work
  100. Adding a sidebar to wp-login.php
Categories PHP Tags login, php, redirect, wp-login-form
How to mark only one post as Featured post?
Display latest comments (global) with replies on a page

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