Add a ‘Logout’ button under a Parent Menu
Add a ‘Logout’ button under a Parent Menu
Add a ‘Logout’ button under a Parent Menu
We assume that the cookie should no longer allow re-login once wp user session destroy –all has been executed. Is this assumption wrong? The cookie has nothing to do with re-logging in, the command will destroy their current active sessions, and has nothing to do with future sessions. A user can create new sessions by … Read more
I also tested the code on a local sandbox WP and it worked as expected. As Howdy_McGee commented this is probably a conflict with 3rd party code. If disabling theme and plugins is not an option, you can try changing the priority of the actions – i.e. the third parameter to add_action(). By default priority … Read more
The wp_login hook you are using only triggers when a user login, while we need to trigger function when user changed their role. The correct for this will be set_user_role hook. Please update your code with the given code so User will logout on changing the role. function logout_pending_users( $user_id, $new_role, $old_roles ) { // … Read more
Nonce verification problem when logging in after a logout
Logout and redirect WordPress user id without he refresh the page
After a bit of research I’ve fixed the problem I had with the redirect after logout. I’ve added this code to my functions file and it will use two filters to modify the default beahviour of wordpress after an user do the logout /* Logout URL Fix */ function custom_logout_url( $logout_url, $redirect ) { $logout_url … Read more
I think the article’s logout hook is wrong on two or three counts: it needs ?action=logout, similar to the lost password link it needs a generated nonce too it doesn’t respect the $redirect argument. Here’s a new version based on the current wp_logout_url() code: add_filter( ‘logout_url’, ‘my_logout_page’, 10, 2 ); function my_logout_page( $logout_url, $redirect ) … Read more
If you are just trying to logout a user and redirect them back to the homepage, could you just use the wp_logout() function? So instead of this: if ( is_page_template( ‘templates/template-logout.php’ ) ) { $logout_url = wp_logout_url( home_url() ); wp_safe_redirect( $logout_url ); // Logout and Redirect to homepage exit; } Your logic could just be: … Read more
You can use wp_logout_url() function for logout link. It will automatically add nonce to the url. Try this code: add_action(‘template_redirect’, function() { if (empty($_SERVER[‘REQUEST_URI’])) return; $uri = $_SERVER[‘REQUEST_URI’]; if (preg_match(‘#^/log-out/?$#’, $uri, $matches) === 1) { $logout_url = str_replace(‘&’, ‘&’, wp_logout_url()); wp_safe_redirect($logout_url); die; } }); If you do not want to use wp_logout_url(), then try to … Read more