Best hook for when a user session ends?

I’m creating a backend feature that calculated user’s login sessions during the past 2 weeks.

This is easy enough to do by incrementing a custom user field when the user logs in using wp_login:

add_action(‘wp_login’, ‘calculate_login_sessions_custom’, 99, 2);

This works well, and I was able to program it so that it doesn’t count logins from the past 2 weeks. (The client only wants to see logins from the past 2 weeks).

The issue is, if someone logs out, I need to update these fields as well, or else someone will have the same login data for the past 2 weeks if they don’t log back in (to trigger the function to remove old logins).

I know there’s wp_logout, but what could I use if the user’s session just ends?

Read more here:: Best hook for when a user session ends?

Leave a Reply

Your email address will not be published. Required fields are marked *