Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
T5 Custom Log-out URL Create a custom log-out URL in WordPress.
<?php
/**
* Plugin Name: T5 Custom Log-out URL
* Description: Create a custom log-out URL.
* Plugin URI: http://wordpress.stackexchange.com/questions/76161/masking-logout-url
* Version: 2012.12.14
* Author: Thomas Scholz
* Author URI: http://toscho.de
* Licence: MIT
* License URI: http://opensource.org/licenses/MIT
*/
add_filter( 'logout_url', 't5_custom_logout_url', 10, 2 );
add_action( 'wp_loaded', 't5_custom_logout_action' );
/**
* Replace default log-out URL.
*
* @wp-hook logout_url
* @param string $logout_url
* @param string $redirect
* @return string
*/
function t5_custom_logout_url( $logout_url, $redirect )
{
$url = add_query_arg( 'logout', 1, home_url( '/' ) );
if ( ! empty ( $redirect ) )
$url = add_query_arg( 'redirect', $redirect, $url );
return $url;
}
/**
* Log the user out.
*
* @wp-hook wp_loaded
* @return void
*/
function t5_custom_logout_action()
{
if ( ! isset ( $_GET['logout'] ) )
return;
wp_logout();
$loc = isset ( $_GET['redirect'] ) ? $_GET['redirect'] : home_url( '/' );
wp_redirect( $loc );
exit;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment