OK, simple solution after digging in the WordPress code.
// 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();
This will log the user with ID $user_id
out of WordPress.
Use case: My use case for this is when a user is approved moderation, but then the situation changes and they are declined, they will be ‘kicked’ from the system if they have any active login sessions.
Related Posts:
- PHP 7.2 – Warning: count(): Parameter must be an array or an object that implements Countable
- Sticky and NON-Sticky sessions
- Session timeout in ASP.NET
- Authentication: JWT usage vs session
- How to use my own custom session value in WordPress?
- How reduce wordpress login session timeout time?
- achieving login implementation without using sessions
- Enable WordPress Sessions
- Clearing cookie on logout and session expiration
- How to log out everywhere else, destroy all sessions “all other devices”?
- share login/logout sessions across two installs?
- Where is the wordpress session stored?
- how to logout user on browser tab or window closes
- Custom Connect to Facebook, problem logging in/logging out
- Share session between my site and WP blog [closed]
- Disconnect automattically after X minutes
- How to get outside login data (session) in WordPress?
- WordPress Keeps Logging Out – What Tests Can I Run to Solve This?
- Session Experies and Get Logged Out Within Few Minutes
- Disallow second login session
- Session problem in PHP – trying to create a simple CAPTCHA
- Multi-instance WordPress usingn Memcached to handle sessions requests login every time a requests is handled by a different server
- Would this be achieveable?
- Using session in WP without trouble with the API REST
- Re-use Nonce in Repeating Event Signup Buttons
- add class to element if user is not logged in [closed]
- Plugin is attempting to start a session with WordPress. WP Session Manager will not work! DomPdf
- logout users with specific role after close browser tab
- Session is not working properly
- Retrieve parameter from url
- Session constantly resets variable
- sharing the same cookie session with multiple wordpress installs on the same domain?
- How to check if the user was redirected?
- Session stays active until page update in dashboard
- Parsing session info between WordPress and non-WordPress
- how to manage Session in WordPress using custom login?
- $_SESSION dosent’t work
- Session destroy on browser close in wordpress
- How to invalidate wordpress_logged_in cookie via backchannel logout
- Form submission: PHP S_SESSION statements within a foreach loop
- S_SESSION variable (user role) not recognised
- Cookies vs. sessions
- ASP.NET Why are sessions timing out, sessionstate timeout set
- How to fix org.hibernate.LazyInitializationException – could not initialize proxy – no Session
- What are sessions? How do they work?
- How to use cURL to send Cookies?
- “Cannot send session cache limiter – headers already sent”
- How to declare session variable in C#?
- How do I expire a PHP session after 30 minutes?
- How to access Session variables and set them in javascript?
- PHP Unset Session Variable
- How to fix the session_register() deprecated issue?
- proper way to logout from a session in PHP
- PHP sessions that have already been started
- Undefined variable: $_SESSION
- How to access Session variables and set them in javascript?
- Session variables not working php
- Logout button php
- How to set session timeout in web.config
- How to store and receive variables in WP sessions?
- How to log out without confirmation ‘Do you really want to log out?”?
- Preventing session timeout
- Logout redirect to home page
- Removing username from the ‘wordpress_logged_in’ cookie
- How to share cookies and sessions between domain and subdomain?
- Extend WordPress (4.x) session and nonce
- Ban a user and end their session
- Are transients private or public?
- Is it possible to transfer a WordPress session to a different browser via query string?
- WordPress and PHP Sessions – Security and Performance
- Disable WordPress 3.6 idle logout / login modal window / session expiration
- How to change the default logout link on WordPress Admin
- How to pass users back and forth using session data?
- How change wordpress password without logout ( need for plugin )
- Allow up to 5 Concurrent Login Sessions
- Logout redirect to current page – function
- How should you hook a session_start() when authoring a plugin?
- How to fake a WordPress login?
- Does wp_logout_url() destroy a session? (Logging out question)
- Does using set_transient() function can lead to MySQL problems?
- Logout URL performing strange
- Masking logout URL
- handling login/logout redirects
- Logout/login redirect CSS issue
- Find out what is using PHP sessions in WordPress
- Display message once per session to users with a specific role
- Why does $_SESSION only work when I am logged in?
- SESSION in WordPress Plugin Development
- wp_logout Not Logging Me Out
- Change “You are now logged out” text
- Set Session Time Limit for Password Protected Posts
- Handling nonces for actions from guests to logged-in users
- How can I get logged in user’s session data from admin-ajax?
- Logout via Subdomain, non-wordpress page on a different server?
- Add a logout menu link [duplicate]
- WordPress Nonce Issue for Ajax Login and Logout
- wp_logout action not working
- Get wp_logout_url function to work on external (non-WordPress) page
- WordPress failure when logging out
- How can I test the login for an expired session?