Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Ensures only one user at a time can be logged into WordPress, ie, 2 people can't login using the same account.
Plugin name: Single user login
Plugin URI:
Author: Ben May
Author URI:
Version: 0.1
if( !class_exists( 'WPSingleUserLoggin' ) )
class WPSingleUserLoggin
private $session_id;
function __construct()
if ( ! session_id() )
$this->session_id = session_id();
add_action( 'init', array( $this, 'init' ) );
add_action( 'wp_login', array( $this, 'wp_login' ), 10, 2 );
function init()
if( ! is_user_logged_in() )
$stored_sess_id = get_user_meta( get_current_user_id(), '_wp_single_user_hash', true );
if( $stored_sess_id != $this->session_id )
wp_redirect( wp_login_url() );
function wp_login( $user_login, $user )
update_user_meta( $user->ID, '_wp_single_user_hash', $this->session_id );
new WPSingleUserLoggin();

This comment has been minimized.

Copy link

@twentyfortysix twentyfortysix commented Sep 20, 2013

I have tried this code but the user is always kicked out to login page.
And also I think the user who has to be kicked out is the previous one not the last (actual) one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.