That action doesn’t pass that data:
function return_user_data_on_logout( $user ) {
Here, $user
will alway be undefined. Additionally, you need to tell add_action
how many parameters the function takes.
But..
do_action( 'clear_auth_cookie' );
No information is passed to begin with, that’s not how this particular event/action works.
So how do we get the current user being logged out? The answer is we remove the words “being logged out” from that question giving us a much easier question that is far more searchable:
How do we get the current user?
$user = wp_get_current_user();
It’s possible that this hook may be too early, and additionally it may not be the best hook to use.
For example, wp_logout
is a much better hook to use as it says on the tin what it does
So:
add_action( 'wp_logout', function() {
$user = wp_get_current_user();
// ...
});