add_action('check_admin_referer', 'logout_without_confirm', 10, 2);
function logout_without_confirm($action, $result)
{
/**
* Allow logout without confirmation
*/
if ($action == "log-out" && !isset($_GET['_wpnonce'])) {
$redirect_to = isset($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : 'url-you-want-to-redirect';
$location = str_replace('&', '&', wp_logout_url($redirect_to));
header("Location: $location");
die;
}
}
/**
* Generates custom logout URL
*/
function getLogoutUrl($redirectUrl = ''){
if(!$redirectUrl) $redirectUrl = site_url();
$return = str_replace("&", '&', wp_logout_url($redirectUrl));
return $return;
}
/**
* Bypass logout confirmation on nonce verification failure
*/
function logout_without_confirmation($action, $result){
if(!$result && ($action == 'log-out')){
wp_safe_redirect(getLogoutUrl());
exit();
}
}
add_action( 'check_admin_referer', 'logout_without_confirmation', 1, 2);