Sign in to unlock all code snippets and resources
100% tested and verified code snippets
New here? Register for free to get started
© Copyright – 2025 – All Rights Reserved. Created by SuperWP
If you have developed an online ecommerce website using WooCommerce Plugin, during the logout time you might have came across these call to action message that say “Are you sure you want to log out?”
check_admin_referer
action, which WordPress uses to verify security nonces (unique tokens) for various actions, including user logout.Breakdown:
add_action('check_admin_referer', 'logout_without_confirm', 10, 2);
logout_without_confirm
to be executed whenever the check_admin_referer
action is triggered.10
is the priority of the function, meaning it will be executed after other functions with lower priorities for the same action.2
indicates that the logout_without_confirm
function expects two arguments: $action
and $result
.function logout_without_confirm($action, $result)
logout_without_confirm
function that will be called by WordPress.$action
: A string representing the action being performed, which in this case should be "log-out"
.$result
: A boolean value indicating whether the nonce verification passed (true) or failed (false).Core Logic:
Allow log out without confirmation
.if
statement checks two conditions:
$action == "log-out"
: This ensures the function only executes when the action is indeed log-out.!isset($_GET['_wpnonce'])
: This condition checks if the _wpnonce
parameter (which contains the security nonce for log-out) is not set in the URL. This scenario would typically occur if the user bypassed the standard WordPress log-out process, potentially through a custom link that doesn’t include the nonce.$redirect_to
: A variable is initialized to hold the URL where the user will be redirected after logging out. It checks for a redirect_to
parameter in the request ($_REQUEST
) and uses it if provided, otherwise it defaults to an empty string.$location
: The wp_logout_url
function is used to generate a secure log-out URL, optionally including a redirect URL ($redirect_to
). The str_replace('&', '&', ...)
part ensures that any &
entities in the URL are correctly converted back to &
symbols.header("Location: $location");
: A header is sent to the browser instructing it to redirect the user to the $location
URL.die();
: The script execution is halted to prevent any further code from running after the redirect.By implementing this new feature, we’ve significantly improved [benefit 1] and [benefit 2] for our users. This will ultimately lead to [positive outcome]. We’re excited to see how this enhances the overall experience and [positive impact on users or business].
Here are some specific examples you can replace the bracketed text with:
Stay UpTo Date with Latest Post And news: