Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save firefly05/5782609 to your computer and use it in GitHub Desktop.
Save firefly05/5782609 to your computer and use it in GitHub Desktop.
bypass wordpress are you sure you want to logout screen when logging out of an already logged out account
// originally by Camden Ross. Thanks
/* bypass wordpress are you sure you want to logout screen when logging out of an already logged out account. */
function smart_logout() {
if (!is_user_logged_in()) {
$smart_redirect_to = !empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '/';
wp_safe_redirect( $smart_redirect_to );
exit();
} else {
check_admin_referer('log-out');
wp_logout();
$smart_redirect_to = !empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '/';
wp_safe_redirect( $smart_redirect_to );
exit();
}
}
add_action ( 'login_form_logout' , 'smart_logout' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment