Skip to content

Instantly share code, notes, and snippets.

@thefuxia
Created December 14, 2012 20:49
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save thefuxia/4288531 to your computer and use it in GitHub Desktop.
Save thefuxia/4288531 to your computer and use it in GitHub Desktop.
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