Destroy user sessions based on user ID

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 … Read more

How to log out without confirmation ‘Do you really want to log out?”?

This happens because you are missing the neccessary nonce in the URL, which is being checked in wp-login.php case ‘logout’ : check_admin_referer(‘log-out’); … Use wp_logout_url in order to retreive the URL including the nonce. If you want to redirect to a custom URL, simply pass it as an argument. <a href=”https://wordpress.stackexchange.com/questions/67336/<?php echo wp_logout_url(“/redirect/url/goes/here’) ?>”>Log out</a> … Read more

Logout button php

Instead of a button, put a link and navigate it to another page Then in logout.php page, use