Skip to content

Instantly share code, notes, and snippets.

@bremercreative
Last active February 19, 2024 17:00
Show Gist options
  • Select an option

  • Save bremercreative/5bf99122f3c80765cc3d8f71a0bd1192 to your computer and use it in GitHub Desktop.

Select an option

Save bremercreative/5bf99122f3c80765cc3d8f71a0bd1192 to your computer and use it in GitHub Desktop.
voxel - logout confirmation
/////////// Step 1 ///////////
- deactivate default wordpress confirmation page with the following php snippet
function custom_logout_without_confirmation() {
if (isset($_GET['appout'])) {
wp_logout();
wp_redirect(home_url());
exit();
}
}
add_action('init', 'custom_logout_without_confirmation');
/////////// Step 2 ///////////
- add a logout link to your menu/layout with the following href:
"?appout=true"
/////////// Step 3 ///////////
- add the following js code
window.addEventListener("load", function () {
document.addEventListener("click", function (e) {
var link = e.target.closest('a[href*="?appout=true"]');
if (link) {
// prevent the default link behavior
e.preventDefault();
// Check if Voxel is defined and show the alert
if (typeof Voxel !== "undefined") {
Voxel.alert("Would you like to log out?", "info");
// Wait until the DOM is updated with the alert box
setTimeout(function () {
// Find the close alert button and customize it
var closeAlertBtn = document.querySelector(
".ts-btn.ts-btn-4.close-alert"
);
if (closeAlertBtn) {
closeAlertBtn.textContent = "Log out now";
closeAlertBtn.addEventListener(
"click",
function (event) {
event.preventDefault();
window.location.href =
link.getAttribute("href");
}
);
}
}, 0);
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment