Last active
November 4, 2022 10:19
-
-
Save perezdans/792497128913e6c359f6cbd2262a6d7f to your computer and use it in GitHub Desktop.
Para limitar el acceso de una sesión por usuario. Cuando autenticamos en WordPress, se eliminan todas las sesiones anteriores del mismo usuario para que el que se loguea en ese momento sea la única sesión
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter('authenticate', 'jpd_single_login_authenticate', 0, 3); | |
function jpd_single_login_authenticate($user, $username, $password) { | |
$user = get_user_by('login', $username); | |
if( isset($user->ID) ){ | |
if(isset($user->roles) && is_array($user->roles)) { | |
//check for admins | |
if(in_array('administrator', $user->roles)) { | |
// admin can log in more than once | |
return $user; | |
} | |
} | |
// get all sessions for user | |
$sessions = WP_Session_Tokens::get_instance($user->ID); | |
// destroy everything since we'll be logging in shortly | |
$sessions->destroy_all(); | |
} | |
return $user; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment