Created
February 5, 2018 04:31
-
-
Save MrVibe/a3ba4150db3011ffe8881dae0f12e4de to your computer and use it in GitHub Desktop.
Allow 5 users login using same account
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
add_filter( 'authenticate',function($user, $username, $password ) { | |
if(isset($user->allcaps['edit_posts']) && $user->allcaps['edit_posts']){ | |
return $user; | |
} | |
$sessions = WP_Session_Tokens::get_instance( $user->ID ); | |
$all_sessions = $sessions->get_all(); | |
if ( count($all_sessions) >= 5 ) { | |
$flag=0; | |
$previous_login = get_user_meta($user->ID,'last_activity',true); | |
if(isset($previous_login) && $previous_login){ | |
$threshold = apply_filters('wplms_login_threshold',1800); | |
$difference = time()-strtotime($previous_login) - $threshold; | |
if($difference <= 0){ // If the user Logged in within 30 Minutes | |
$flag=1; | |
}else{ | |
$token = wp_get_session_token(); | |
$sessions->destroy_others( $token ); | |
} | |
}else{ | |
$flag = 1; | |
} | |
if($flag) | |
$user = new WP_Error('already_signed_in', __('<strong>ERROR</strong>: 5 Users already logged in.','vibe-customtypes')); | |
} | |
return $user; | |
}, 30, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment