Update user meta on wp_logout hook

I’m looking to update user meta when the user logout, I’m using the wp_logout as a hook to add my user meta updated value when the user logs out.

This is how the user logs out on the front end:

<a href=”<?php echo wp_logout_url(get_permalink()); ?>”>Logout</a>

And this is the hook function:

<?php // Display for online and offline users

global $current_user;
$current_user_id = $current_user->ID;
$online_status = get_user_meta($current_user_id, ‘_online_status’, true);
add_user_meta($current_user_id, ‘_online_status’, ‘0’, true);
update_user_meta($current_user_id, ‘_online_status’, ‘1’, $online_status);
function status_offline(){
update_user_meta($current_user_id, ‘_online_status’, ‘0’, $online_status);
wp_redirect( home_url().’/?userid=’.$current_user_id );
add_action(‘clear_auth_cookie()’, ‘status_offline’);

Does anyone know why this isn’t working? As it’s still keeping the user meta value as ‘1’.


Read more here:: Update user meta on wp_logout hook

Leave a Reply

Your email address will not be published. Required fields are marked *