Clearing cookie on logout and session expiration

Try setting $experation to a negative integer: function myplugin_cookie_expiration( $expiration, $user_id, $remember ) { return $remember ? $expiration : -600; } add_filter( ‘auth_cookie_expiration’, ‘myplugin_cookie_expiration’, 99, 3 ); From the w3schools PHP page on cookies: <?php // set the expiration date to one hour ago setcookie(“user”, “”, time()-3600); ?>

Logout URL performing strange

This happens because of a missing nonce parameter in the URL. Every WordPress action, including login/logout, validates the nonce first, to make sure the request comes from a known source.

Logout redirect to current page – function

Using this code in the functions.php does the trick: function wpse_44020_logout_redirect( $logouturl, $redir ) { return $logouturl . ‘&amp;redirect_to=’ . get_permalink(); } add_filter( ‘logout_url’, ‘wpse_44020_logout_redirect’, 10, 2 ); Note – The above code works only on non-admin pages. To make this work on any page you should replace: return $logouturl . ‘&amp;redirect_to=’ . get_permalink(); With: … Read more

How change wordpress password without logout ( need for plugin )

If you are changing the password for the current logged-in user, it will log you out. You have to log in again: // Get current logged-in user. $user = wp_get_current_user(); // Change password. wp_set_password($new_password, $user->ID); // Log-in again. wp_set_auth_cookie($user->ID); wp_set_current_user($user->ID); do_action(‘wp_login’, $user->user_login, $user); Note that since you are setting a new log-in cookie (i.e. changing … Read more

Destroy user sessions based on user ID

OK, simple solution after digging in the WordPress code. // get all sessions for user with ID $user_id $sessions = WP_Session_Tokens::get_instance($user_id); // we have got the sessions, destroy them all! $sessions->destroy_all(); This will log the user with ID $user_id out of WordPress. Use case: My use case for this is when a user is approved … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)