This is the main requirements of my project.
After a user login, logout should be done only if user click logout button or if user delete browser history.
When browser closing, then machine restarting, changing IP address should NOT logout the User.
Is this possible with WordPress? Is there any filter, action hook?
You can use the auth_cookie_expiration
filter to change the expiration time of the cookie WordPress sets to remember you. The user won’t be logged out unless they change browser or clear their cookies (normally part of clearing history).
The problem is that you can’t set a cookie to never expire, so you have to set a date in the far future. The furthest you can go is 19th January 2038, because of the Year 2038 problem.
The value of the auth_cookie_expiration
filter is added to time()
so if you want to set the longest possible time for the cookie, you need to get the maximum value (2147483647
according to this) and subtract time()
:
function wpse_287104_cookie_expiration( $length ) {
return time() - 2147483647;
}
add_filter( 'auth_cookie_expiration', 'wpse_287104_cookie_expiration' );