Title: delete_user_meta function with wp_clear_auth_cookie?
Last modified: August 30, 2016

---

# delete_user_meta function with wp_clear_auth_cookie?

 *  [amybill1978](https://wordpress.org/support/users/amybill1978/)
 * (@amybill1978)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/delete_user_meta-function-with-wp_clear_auth_cookie/)
 * So I have a little hack I made to add the user’s PHPSESSID to the wp_usermeta
   table when a user logs in (which is working perfectly). I’ve been trying for 
   several hours to delete the same info when a user logs out, and can’t seem to
   get the dang thing to work. I’m wondering now if the wp user object isn’t available
   anymore after you click logout? I read elsewhere that I should be able to use
   wp_clear_auth_cookie(), but no luck there either. Any insights would be great.
 *     ```
       function create_session_id($user_login){
   
           if(!session_id()) {
                   	session_start();
       		$user_obj = get_user_by('login', $user_login );
       		$user_id = $user_obj->ID;
       		$session_id = session_id();
       		add_user_meta( $user_id, 'session_id', $session_id);
       	}else{
       		$user_obj = get_user_by('login', $user_login );
       		$user_id = $user_obj->ID;
       		$session_id = session_id();
       		add_user_meta( $user_id, 'session_id', $session_id);
       	}
       }
       add_action('wp_login', 'create_session_id');
   
       function delete_session_id(){
   
       		$current_user = wp_get_current_user();
       		$user_id = $current_user->ID;
       		delete_user_meta( $user_id, 'session_id', '');
       }
       add_action('wp_clear_auth_cookie()', 'delete_session_id');
       ```
   

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Dion](https://wordpress.org/support/users/diondesigns/)
 * (@diondesigns)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/delete_user_meta-function-with-wp_clear_auth_cookie/#post-6438351)
 * FYI…WordPress added session support in 4.0, so your code is unnecessary. You’ll
   find the session information in the _session\_tokens_ meta key for each user.
   The session ID is the array key, the remaining information is in the array values.
   You can view the (serialized) format using phpMyAdmin on the _\_usermeta_ table.
 *  Thread Starter [amybill1978](https://wordpress.org/support/users/amybill1978/)
 * (@amybill1978)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/delete_user_meta-function-with-wp_clear_auth_cookie/#post-6438368)
 * Hi and thanks for the reply. I needed the session ID in raw format to share it
   with a .Net application – and also needed the session ID to be removed once a
   user logs out (which WP doesn’t seem to do for some reason). Its a weird setup,
   but I actually figured out how to fix my own problem. I just changed ‘wp_clear_auth_cookie()’
   to ‘clear_auth_cookie’ and now it works. Go figure!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘delete_user_meta function with wp_clear_auth_cookie?’ is closed to new
replies.

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 2 replies
 * 2 participants
 * Last reply from: [amybill1978](https://wordpress.org/support/users/amybill1978/)
 * Last activity: [10 years, 9 months ago](https://wordpress.org/support/topic/delete_user_meta-function-with-wp_clear_auth_cookie/#post-6438368)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
