It’s annoying to be signed out in the middle of your work. The default keeps you logged in for 2 weeks, and a lot of suggestions for changing this time use a multiple of 24 hours… so you’re always trapped in a cycle of getting logged out during working hours. (Say you log in monday at 9am, you’ll be booted out between 9-10am the next week, and so on…)
The code below will log people out on sunday 4am, using timezone set in wordpress. Once they log in again, they will then be set for the whole week.
add_filter( 'auth_cookie_expiration', function( $seconds_from_now, $user_id, $remember ){ if ( $remember ) { $datetime = new DateTime( 'sunday 4am', wp_timezone() ); $seconds_from_now = $datetime->getTimestamp() - time(); } return $seconds_from_now; }, 10, 3 );
You could change it to ‘sunday 4am +1 week’ to make it a week from next sunday, so roughly 2 weeks (depending when they log in).
If you want this to take effect immediately, you can force everyone to re-authenticate right away by replacing the salts in wp-config.php with new ones. Generate them here: api.wordpress.org/secret-key/1.1/salt