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
- How to invalidate wordpress_logged_in cookie via backchannel logout
- PHP Unset Session Variable
- How to share cookies and sessions between domain and subdomain?
- How to use wp-login.php page only for logout?
- Should I store my Facebook access tokens?
- How to get login data (session) outside WordPress?
- wp_logout() changes in WordPress 5.1.1
- integrating external php library into wordpress- the right way
- WP_Session not acting with AJAX
- Force logout ALL users at a certain time
- Auto redirect after session expire, but only for one user
- Pagination with $_POST and $_SESSION
- Custom post type search using $_SESSION and pre_get_posts
- Why is the session clearing after wp_safe_redirect?
- WordPress Multisite logout conflict
- 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?
- Having Issue on Redirecting With Session in WordPress
- Set Short Automatic Logout Time for One User
- Session Cookie security questions
- Force Users To Relogin
- Can’t Access Sessions or Variables through pages
- wp_logout hook never triggered
- How to hook a logout funtion for specific usr role in wordpress?
- How to Extend login session times to a Month
- Logout redirects to default page
- How to Show Different Menus to Logged in Users in WordPress [duplicate]
- Can we stop session reset if page reloads?
- login logout menu changes in wordpress [closed]
- Where is function to prevents non logged users access wp-admin?
- WordPress Login/Logout Single Menu Only
- How to redirect logged out users to specific page?
- Deleting expired session tokens in WordPress
- PHP: $_SESSION destroyed after page reload for my custom session
- 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
- Problem with is_user_logged_in() function in some pages
- How to add Loginout to Sub-menu
- wordpress login loop and session problem
- Get WordPress logged in username from root domain when WP is installed in a subfolder
- Unable to update plugins or log out
- How to redirect returning users who previously logged in?
- logging out with/without confirmation – single site, multisite
- Logout user if click on a custom page link
- Trying to configure cron to get next value from array on each run
- $_SESSION inside php function executed by AJAX
- $_SESSION Not working after X amount of page views
- Redirection of wp-login.php results in non working of Logout process
- Looking to load a different template part on every load/refresh
- wp_logout problem
- Sessions in plugin development?
- White screen after login attempt
- Session alternative for plugins (due to caching)
- Changing user_login ends current session
- WP Logs me out after updating anything on dashboard
- 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]
- Sessions in word press [duplicate]
- Inconsistent login state
- PHP – Having $_SESSION as an array and adding $_SESSION to array