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

Why WordPress not logout after I have close my browser?

I used this code in wordpress functions.php, to auto logout customer/user after payment in woocommerce or close the browser

function logged_in( $expirein ) {
   return 6; // 6 in seconds
}
add_filter( 'auth_cookie_expiration', 'logged_in' );

function wp_logout2() {
    wp_destroy_current_session();
    wp_clear_auth_cookie();

    /**
     * Fires after a user is logged-out.
     *
     * @since 1.5.0
     */
    do_action( 'wp_logout2' );
}

function wpse108399_change_cookie_logout( $expiration, $user_id, $remember ){
    if( $remember && user_can( $user_id, 'administrator' ) ){
        $expiration = 604800;// yes, I know this is 1 minute
    }
    if( $remember && user_can( $user_id, 'editor' ) ){
        $expiration = 604800;// yes, I know this is 1 minute
    }
    }
    return $expiration;
}
add_filter( 'auth_cookie_expiration','wpse108399_change_cookie_logout', 10, 3 );

/**
 * Bypass logout confirmation.
 */
function iconic_bypass_logout_confirmation() {
    global $wp;

    if ( isset( $wp->query_vars['customer-logout'] ) ) {
            wp_redirect( str_replace( '&', '&', wp_logout_url( wc_get_page_permalink( 'myaccount' ) ) ) );
        exit;
    }
}

add_action( 'template_redirect', 'iconic_bypass_logout_confirmation' );

A part of this code it’s for increase expiration time to administrators of wordpress or other kinds of user

function wpse108399_change_cookie_logout( $expiration, $user_id, $remember ){
    if( $remember && user_can( $user_id, 'administrator' ) ){
        $expiration = 604800;// yes, I know this is 1 minute
    }
    if( $remember && user_can( $user_id, 'editor' ) ){
        $expiration = 604800;// yes, I know this is 1 minute
    }
    }
    return $expiration;
}
add_filter( 'auth_cookie_expiration','wpse108399_change_cookie_logout', 10, 3 );

Related Posts:

  1. Login issue with subdomain installs
  2. Change WP-Login or WP-Admin
  3. I want to disable login of admin (/wp-admin) with email and make it accessible only with username
  4. How to Change The WordPress Login URL Without Plugin
  5. 404 redirect wp-login and wp-admin after changing login url [closed]
  6. Logout USER form backoffice after 30 minutes of inactivity [closed]
  7. Cookie Domain is preventing Admin login
  8. Where is function to prevents non logged users access wp-admin?
  9. Couple questions about .htaccess, login page, updates
  10. Can I rename the wp-admin folder?
  11. What’s the easiest way to stop WP from ever logging me out
  12. Removing username from the ‘wordpress_logged_in’ cookie
  13. How to redirect/rewrite all /wp-login requests
  14. Unable to login to my wordpress site. reauth=1 redirection loop
  15. How to Layer 7 Load Balance WordPress Backend and Frontend?
  16. Custom login redirects to wp-admin on wrong password
  17. What is the best method to close off the backend?
  18. Change Login URL Without Plugin
  19. How to fake a WordPress login?
  20. Share same domain for wp-admin but for different website
  21. How to allow users login to WP from external domain and make REST requests
  22. Securing wp-admin folder – Purpose? Importance?
  23. Can I rename the wp-admin folder?
  24. Users are redirected to homepage instead of wp-admin
  25. Options for restricting access to wp-admin
  26. Display sortable User meta column in admin panel user’s page
  27. How to move wp-admin login page to another location? [closed]
  28. Can’t access admin dashboard with wp-admin without /index.php after it
  29. How to change “wp-admin” to something else without search-replacing the core?
  30. Adding body class to login page?
  31. Edit a WordPress site without the username and password?
  32. comment_form – show all fields when logged in
  33. Block access to wp-admin
  34. How to get login data (session) outside WordPress?
  35. Cookie value cannot be read until I’ve logged into the WP admin
  36. Using /wp-admin works, using /login gives a 404. Why?
  37. Cannot log into WordPress Dashboard after removing/adding .htaccess
  38. Should I add the IP of the server that hosts my sites to the list of authorized IPs in the wp-admin/.htaccess?
  39. I cannot log into my wordpress site with my wp-login.php [closed]
  40. FORCE_SSL_ADMIN not working
  41. How do I set the homepage to the WordPress Admin Dashboard login?
  42. How to get session token of current user in wp_login hook?
  43. Can’t access WordPress as an admin – but I can log in as a user!
  44. Today, without warning, all admin panel logins redirect to home page after login. non-admin users logins work well
  45. Admin username and password
  46. Can’t login to Dashboard when changing site URL to HTTPS
  47. Detecting all admins that are logged in
  48. Limit access to wp_admin
  49. WordPress and bbPress Login conflicts?
  50. Website looks fine, but login to wp-admin yields a blank screen
  51. password reset link being sent as HTTP?
  52. cannot find the login page for local WordPress site
  53. Why a strange discrepency between get_current_user_id() when using AJAX versus output of document.cookie?
  54. Users disappeared from wp-admin
  55. Modify WP-Admin login fields
  56. display dynamic WP Site logo on wp-admin using CSS
  57. wp-admin – 404 after custom login form
  58. How to fix ‘WordPress redirection loop problem in wp-login.php page’?
  59. Logging into sandbox subdomain WP
  60. Having troubles connecting to WordPress login page using Mamp
  61. Do I have to face security problems if I changing default role to Contributor
  62. Sorry, you are not allowed to access this page
  63. WP Admin/ WP Login Redirect to themselves
  64. Hide username discovery
  65. Require Login Redirect to Login Page
  66. Cannot access WordPress login pages
  67. Cant login to wp-admin
  68. /wp-admin/ doesn’t work but /admin/ does
  69. Efficient way to check local WordPress php files and Database for malicious code? [duplicate]
  70. Renaming wp-admin without hard-coding it. Is it really possible?
  71. Why am I locked out of the system?
  72. Why can I log into wp-login.php and not wp-admin.php?
  73. Need help for WordPress User Session Management?
  74. Disable Admin CP authentication (or auto login)
  75. Session Cookie security questions
  76. firing function at login within class
  77. WP-admin or any other is redirecting me to (This page doesn’t seem to exist.)
  78. Developer/Designer asking for admin access
  79. wp-login not found – All usual solutions not working
  80. how can provide access to wp_admin page for non wp_users?
  81. Get current session in WP admin
  82. Can’t connect to WP-Admin, blank error message
  83. Blank page when viewing wp-admin
  84. One time login on 2 different WordPress sites
  85. GoDaddy hosting wp-admin problem
  86. WP Admin Login keeps redirecting to login
  87. Is WordPress secure enough for a multi-user article directory?
  88. CPU overload spam – redirect link to wp-admin and new post
  89. define two login page url
  90. How can I can I make changes to a WP project I pulled from GItHub?
  91. Get WordPress logged in username from root domain when WP is installed in a subfolder
  92. WordPress Admin Login Issue
  93. How to log into WordPress via GET/POST
  94. WordPress Admin login redirect to homepage
  95. Can I rename the wp-admin folder?
  96. wp-login.php entering password nothing happens
  97. Trying to login to my site redirects me to the first page
  98. CSRF attack to create USER
  99. Why does WordPress use cookies for /wp-admin and /wp-content/plugins for non-admin users [duplicate]
  100. stop customize.php redirect to login page if admin is not logged in
Categories wp-admin Tags cookies, login, security, session, wp-admin
how to open image gallery in a post/page?
pre_get_posts main_query not displaying after applying tax_query filters

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