$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>logout - Destroy user sessions based on user ID|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

logout - Destroy user sessions based on user ID

matteradmin7PV0评论

I want to programatically log a specific user out of our WordPress system based on their user ID much like the 'Log Out of All Sessions' button in the WordPress user editor section.

How am I able to do this?

I want to programatically log a specific user out of our WordPress system based on their user ID much like the 'Log Out of All Sessions' button in the WordPress user editor section.

How am I able to do this?

Share Improve this question edited Apr 14, 2015 at 13:39 Howdy_McGee 20.9k24 gold badges91 silver badges177 bronze badges asked Apr 14, 2015 at 10:25 ChrisChris 4092 gold badges5 silver badges14 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 19

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.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far