Skip to content

Instantly share code, notes, and snippets.

@mattwatsoncodes
Last active January 18, 2019 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattwatsoncodes/a041241f714b2fbd76c09c10cb52ebde to your computer and use it in GitHub Desktop.
Save mattwatsoncodes/a041241f714b2fbd76c09c10cb52ebde to your computer and use it in GitHub Desktop.
Login one user instance
<?php
/**
* Login One User Instance
*
* Only allow one instance of a user to be logged in at any one time.
* Other browser sessions will be logged out other than the latest user to
* sign in with that username.
*/
function mwtsn_example_login_one_user_instance() {
global $sessions;
$sessions = WP_Session_Tokens::get_instance( get_current_user_id() );
$sessions->destroy_others( wp_get_session_token() );
}
add_action( 'setup_theme', 'mwtsn_example_login_one_user_instance', 0 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment