WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to perform some cleanup after a user logged out, so I added a wp_logout action hook. Problem is, wp_get_current_user() already returns null if called from within the wp_logout action hook. How do I get the logging out users userid inside a wp_logout action hook?

share|improve this question
up vote 8 down vote accepted

How about hooking 'clear_auth_cookie' with the cleaning you need to do? If you need even more depth, you can outright replace wp_clear_auth_cookie(), but that can get into issues where it will conflict with other plugins, so avoid that if possible.

share|improve this answer
Thank you very much! This is exactly what i was looking for. – Davos Seaworth Jan 22 '12 at 17:26
This worked perfectly. I have used this hook for a custom audit plugin, to record the logout event. Thank you. – julianm Feb 6 '15 at 16:44

I know this is a little late.... but i ran into this problem my self. This is how i resolved the issue.

Add the following to your functions.php

function logout_redirect765(){
  $current_user = wp_get_current_user(); 
  wp_redirect( home_url().'/?userid='.$current_user->ID ); 

This basically stores the userid in a url parameter when the user logs out.

Then simply get the parameter with the following:


I hope this helps someone in the future who finds this post.

share|improve this answer
add_action('wp_logout', 'user_id');

function user_id()

use this in plugin main file

share|improve this answer
As the OP states 'wp_get_current_user() already returns null if called from within the wp_logout action hook' -- so this won't work. – marfarma Sep 24 '12 at 6:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.