Created
January 25, 2024 08:28
-
-
Save moxet/2002f035159aed4ec167d5f5de37443f to your computer and use it in GitHub Desktop.
Wordpress Logout without Confirmation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'] : 'https://yoursite.com'; | |
| $location = str_replace('&', '&', wp_logout_url($redirect_to)); | |
| header("Location: $location"); | |
| die; | |
| } | |
| } |
Author
This version can be used to avoid fix logout url
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'])) {
// Always redirect to home page
$redirect_to = home_url('/');
$location = str_replace('&', '&', wp_logout_url($redirect_to));
wp_safe_redirect($location);
exit;
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is very Helpful, really appreciate