One of our clients would like users with one specific user role to stay logged in for two weeks. He would like to automatically select the 'remember me' checkbox when logging in.
I have been able to solve this problem for 90% using the https://developer.wordpress.org/reference/hooks/auth_cookie_expiration/ function and by adding some JS to automatically select the 'remember me' checkbox on the login page.
My problem:
- the cookie seems to be set on logging in for the first time (correct)
- but when I return the next day, the cookie isn't updated
- e.g. If I login on Jan 1st, I should stay logged in until Jan 15th
- When I login on Jan 2nd, the cookie should be refreshed / extended until Jan 16th
Do you have any idea if and how this extension is possible?
My problem seems to be similar to this one on how to change session expire time in wordpress:
See one the last comments: "I believe this solution will NOT address the 'inactivity' part of the question. This method will change cookie expiration but the user will be logged out regardless of whether or not they were active. WP does not seem to update the cookie expiration on user activity - it is set once on login"