# Active Sessions Column With "Log Out Everywhere"

> Shows how many devices each user is logged in on, with a link to end all of that user's sessions from the Users screen.

- Type: PHP
- Runs: Admin only
- Category: [Users](https://wpide.com/library/category/users/)
- Tags: users, sessions, security
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/active-sessions-users-column/

## Code

```php
add_filter( 'manage_users_columns', function ( $columns ) {
    $columns['wpide_sessions'] = 'Sessions';

    return $columns;
} );

add_filter( 'manage_users_custom_column', function ( $output, $column, $user_id ) {
    if ( 'wpide_sessions' !== $column ) {
        return $output;
    }

    $count = count( WP_Session_Tokens::get_instance( $user_id )->get_all() );

    if ( ! $count ) {
        return '0';
    }

    $output = (string) $count;

    if ( current_user_can( 'edit_user', $user_id ) && get_current_user_id() !== (int) $user_id ) {
        $url     = wp_nonce_url( admin_url( 'admin-post.php?action=wpide_end_sessions&user_id=' . (int) $user_id ), 'wpide_end_sessions_' . (int) $user_id );
        $output .= '<br><a href="' . esc_url( $url ) . '">Log out everywhere</a>';
    }

    return $output;
}, 10, 3 );

add_action( 'admin_post_wpide_end_sessions', function () {
    $user_id = isset( $_GET['user_id'] ) ? absint( $_GET['user_id'] ) : 0;

    if ( ! $user_id || ! current_user_can( 'edit_user', $user_id ) ) {
        wp_die( 'You are not allowed to do this.' );
    }

    check_admin_referer( 'wpide_end_sessions_' . $user_id );
    WP_Session_Tokens::get_instance( $user_id )->destroy_all();

    wp_safe_redirect( add_query_arg( 'wpide_sessions_ended', 1, admin_url( 'users.php' ) ) );
    exit;
} );

add_action( 'admin_notices', function () {
    if ( isset( $_GET['wpide_sessions_ended'] ) ) {
        echo '<div class="notice notice-success is-dismissible"><p>The user was logged out on all devices.</p></div>';
    }
} );
```

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Active Sessions Column With "Log Out Everywhere"" 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/
