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
- Cookies vs. sessions
- How to fix org.hibernate.LazyInitializationException – could not initialize proxy – no Session
- How to access Session variables and set them in javascript?
- How to log out without confirmation ‘Do you really want to log out?”?
- WordPress and PHP Sessions – Security and Performance
- Does wp_logout_url() destroy a session? (Logging out question)
- Masking logout URL
- handling login/logout redirects
- Logout via Subdomain, non-wordpress page on a different server?
- Ajax function returns -1
- Using Sessions to Filter Posts – bad thing?
- how to create and show sessions in word press?
- Woocommerce cart is a non-object inside `admin_post` action [closed]
- Logout redirects to a broken page(home URL is omitted)
- How does WordPress handle sessions?
- homepage redirects to login page when user session expires
- Logout redirects to /forums/
- wp_mail is sending two emails when used after retrieving session data
- Hook to change Logout url
- External Authentication, session_tokens not destroyed on logout
- WordPress as webapp login session
- How to: PHP Log Out Link?
- Login/logout in header
- Logout USER form backoffice after 30 minutes of inactivity [closed]
- Session destroyed on page redirect
- Large Session Tokens
- captcha not working in my custom plugin
- WordPress error on log out ‘Not Permitted’ and can’t log out
- Can I Set Up Session in WordPress Custom Page
- Add logout link when logged in, make it disappear when logged out?
- Session Cookie security questions
- Force Users To Relogin
- Turning on output buffering in a wordpress plugin
- Can’t Access Sessions or Variables through pages
- wp_logout hook never triggered
- How to Extend login session times to a Month
- keep a variable for all pages in memory from the url
- Logout redirects to default page
- How to Show Different Menus to Logged in Users in WordPress [duplicate]
- WordPress Login/Logout Single Menu Only
- Strange admin-ajax / CSS / $_SESSION issue
- How to read and write session data?
- Multiple use wp_logout_url() on page cause ‘header already sent’ error after submit form
- Form Post / Session Variables not Working in Query with Pagination
- Are there any drawbacks on opening a session_start in functions.php and header.php?
- Log out without confirmation request (nonce)
- Problem with is_user_logged_in() function in some pages
- How to add Loginout to Sub-menu
- wordpress login loop and session problem
- Trying to configure cron to get next value from array on each run
- $_SESSION Not working after X amount of page views
- Redirection of wp-login.php results in non working of Logout process
- Add class when more page is visited
- Custom, conditional redirect on logout
- Sessions in plugin development?
- White screen after login attempt
- Changing user_login ends current session
- Need edit profile link in the menu for logged in users
- PHP $_session is not work in wordpress
- Create a Custom Login System in WordPress [closed]
- Inconsistent login state
- How to transfer session after being redirected to other page
- Logout button in menu without “wp” in links