The clear_auth_cookie WordPress action fires just before the authentication cookies are cleared.
Usage
add_action('clear_auth_cookie', 'your_custom_function');
function your_custom_function() {
// your custom code here
}
Parameters
- None
More information
See WordPress Developer Resources: clear_auth_cookie
Examples
Log when authentication cookies are cleared
Log a message to a custom log file when the authentication cookies are cleared.
add_action('clear_auth_cookie', 'log_cookie_clearing');
function log_cookie_clearing() {
error_log('Authentication cookies cleared');
}
Remove custom session data
Remove custom session data related to the user when the authentication cookies are cleared.
add_action('clear_auth_cookie', 'remove_custom_session_data');
function remove_custom_session_data() {
// Remove custom session data
unset($_SESSION['custom_data']);
}
Invalidate custom cache
Invalidate custom cache when authentication cookies are cleared, to ensure that user-specific data is not served to other users.
add_action('clear_auth_cookie', 'invalidate_custom_cache');
function invalidate_custom_cache() {
// Invalidate custom cache
custom_cache_invalidate();
}
Notify external service
Send a notification to an external service when authentication cookies are cleared, to track user logouts.
add_action('clear_auth_cookie', 'notify_external_service');
function notify_external_service() {
// Send notification to external service
external_service_notify('user_logged_out');
}
Run custom analytics
Run custom analytics code when authentication cookies are cleared, to track user logouts in your analytics system.
add_action('clear_auth_cookie', 'run_custom_analytics');
function run_custom_analytics() {
// Run custom analytics code
custom_analytics_track('user_logged_out');
}