Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save adis-io/20a924a6c5eab116ac28 to your computer and use it in GitHub Desktop.
Save adis-io/20a924a6c5eab116ac28 to your computer and use it in GitHub Desktop.
// 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