johnbillion / user-switching

WordPress plugin that provides instant switching between user accounts.
https://wordpress.org/plugins/user-switching/
GNU General Public License v2.0
187 stars 49 forks source link

Is there a way to distinguish user switching from regular logins? #69

Closed therealgilles closed 3 years ago

therealgilles commented 3 years ago

I would like to keep tracks of regular user logins and filter out user switching logins. Is there a way to do that? Thanks for any advice :)

johnbillion commented 3 years ago

Yep this is possible. If you use the authenticate filter or the wp_login action then those only fire when a user actually logs in, not when a user switches.

If you use the set_auth_cookie action then that will also fire when a user switches. In that case I don't believe you can determine at that point whether the user is logging in or switching because the corresponding $_COOKIE values won't be updated at that point.