Log Out Without the Confirmation Screen
Logs users out right away from plain logout links (for example in menus) instead of showing "Do you really want to log out?".
Opens WPIDE on
Code
add_action( 'check_admin_referer', function ( $action, $result ) {
if ( 'log-out' !== $action || $result || ! is_user_logged_in() ) {
return;
}
wp_logout();
$target = isset( $_REQUEST['redirect_to'] ) ? wp_validate_redirect( wp_unslash( $_REQUEST['redirect_to'] ), home_url( '/' ) ) : home_url( '/' );
wp_safe_redirect( $target );
exit;
}, 10, 2 );
Notes
Without the confirmation step, another site could log your users out with a link; that is an annoyance, not a data risk.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.