Support » Plugin: User Session Control » kill previous session if the same user logged in again wordpress

  • Resolved subair.tc

    (@subairtc)


    Any option to destroy all other user session after login a user. i fount an option for destroying sessions as

    // get all sessions for user with ID $user_id
        $sessions = WP_Session_Tokens::get_instance( $user->ID );
        // we have got the sessions, destroy them all!
        $sessions->destroy_all();
    

    it can use on authenticating a user, but i am using social login plugin for authenticating using social media, so need to hack the plugin for achieving the same. so let me know any option to destroy the session on or after “wp_login” action.

    • This topic was modified 2 years, 6 months ago by subair.tc.
Viewing 1 replies (of 1 total)
  • Resolved it!!. destroy_all() will destroy all the sessions so when we are use this in wp_login hook it will destroy the current session too, instead we can use destroy_others() function. The final code shown below

    
        function your_function( $user,$user_id) {
            $sessions  = WP_Session_Tokens::get_instance( get_current_user_id() );
            $token = wp_get_session_token();
    
            $sessions->destroy_others( $token  );
        }
        add_action('wp_login', 'your_function',10,2);
    
    
Viewing 1 replies (of 1 total)
  • The topic ‘kill previous session if the same user logged in again wordpress’ is closed to new replies.