Last active
January 6, 2025 19:22
-
-
Save dknauss/fdd1d74304b278edcffc36c186fe9632 to your computer and use it in GitHub Desktop.
Expire Idle WordPress Sessions (JavaScript)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script type="text/javascript"> | |
| var logoutUrl = '<?php echo htmlspecialchars_decode( wp_logout_url() ); ?>'; | |
| var timeout; | |
| document.onload = resetTimeout; | |
| document.onmousemove = resetTimeout; | |
| document.onkeypress = resetTimeout; | |
| function resetTimeout() { | |
| clearTimeout( timeout ); | |
| timeout = setTimeout( function () { | |
| window.location.href = logoutUrl; | |
| }, 600000 ); // 10 minutes | |
| } | |
| </script> | |
| // Note: This cannot be considered a secure method because the client can always see and manipulate the code in the DOM. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment