# "Log Out Everyone" Button for Emergencies

> Adds a button under Tools > Log Out Everyone that ends every login session on the site except your own, useful after a suspected break-in or a staff change.

- Type: PHP
- Runs: Admin only
- Category: [Security](https://wpide.com/library/category/security/)
- Tags: sessions, emergency, users
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/sec-log-out-everyone/

## Code

```php
add_action( 'admin_menu', function () {
    add_management_page( 'Log Out Everyone', 'Log Out Everyone', 'manage_options', 'wpide-logout-all', function () {
        if ( isset( $_POST['wpide_logout_all'] ) && check_admin_referer( 'wpide_logout_all' ) && current_user_can( 'manage_options' ) ) {
            $count = 0;
            $ids   = get_users( array( 'meta_key' => 'session_tokens', 'fields' => 'ID', 'number' => -1 ) );

            foreach ( $ids as $id ) {
                $manager = WP_Session_Tokens::get_instance( (int) $id );
                if ( get_current_user_id() === (int) $id ) {
                    $manager->destroy_others( wp_get_session_token() );
                } else {
                    $manager->destroy_all();
                    $count++;
                }
            }

            printf( '<div class="notice notice-success"><p>%s</p></div>', esc_html( sprintf( 'Logged out %d user(s) and your other sessions.', $count ) ) );
        }

        echo '<div class="wrap"><h1>Log Out Everyone</h1><p>End all login sessions on this site except the one you are using now.</p>';
        echo '<form method="post" onsubmit="return confirm(\'Log out every user now?\');">';
        wp_nonce_field( 'wpide_logout_all' );
        submit_button( 'Log out everyone', 'primary', 'wpide_logout_all' );
        echo '</form></div>';
    } );
} );
```

## Notes

Users only need to log in again, so also change passwords if you suspect they were stolen.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find ""Log Out Everyone" Button for Emergencies" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
