wp_ajax_destroy_sessions

Ajax handler for destroying multiple open sessions for a user.

Description

wp_ajax_destroy_sessions(); 

Usage

  1. if ( !function_exists( 'wp_ajax_destroy_sessions' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/ajax-actions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wp_ajax_destroy_sessions(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/ajax-actions.php  
  1. function wp_ajax_destroy_sessions() { 
  2. $user = get_userdata( (int) $_POST['user_id'] ); 
  3. if ( $user ) { 
  4. if ( ! current_user_can( 'edit_user', $user->ID ) ) { 
  5. $user = false; 
  6. } elseif ( ! wp_verify_nonce( $_POST['nonce'], 'update-user_' . $user->ID ) ) { 
  7. $user = false; 
  8.  
  9. if ( ! $user ) { 
  10. 'message' => __( 'Could not log out user sessions. Please try again.' ),  
  11. ) ); 
  12.  
  13. $sessions = WP_Session_Tokens::get_instance( $user->ID ); 
  14.  
  15. if ( $user->ID === get_current_user_id() ) { 
  16. $sessions->destroy_others( wp_get_session_token() ); 
  17. $message = __( 'You are now logged out everywhere else.' ); 
  18. } else { 
  19. $sessions->destroy_all(); 
  20. /** translators: 1: User's display name. */ 
  21. $message = sprintf( __( '%s has been logged out.' ), $user->display_name ); 
  22.  
  23. wp_send_json_success( array( 'message' => $message ) );