Skip to content

Instantly share code, notes, and snippets.

@JudeRosario
Created May 21, 2015 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JudeRosario/2d73776f9e959deb524f to your computer and use it in GitHub Desktop.
Save JudeRosario/2d73776f9e959deb524f to your computer and use it in GitHub Desktop.
Domain Mapping + Flush Sessions
function logout_shortcode( $atts, $content = null, $shortcode_name = null ) {
$defaults = array(
'text' => __( 'Log out' ),
'redirect' => '',
);
if ( ! is_user_logged_in() ) {
return '';
}
$atts = shortcode_atts( $defaults, $atts );
$atts['redirect'] = $atts['redirect'] ? $atts['redirect'] : get_the_permalink();
return '<a href="' . admin_url('admin-ajax.php?action=custom_logout_action') . '" >Log Out</a>';
}
add_shortcode( 'logout', 'logout_shortcode' );
add_action("wp_ajax_custom_logout_action", "custom_logout_action");
function custom_logout_action() {
session_start();
wp_clear_auth_cookie();
if(isset($_COOKIE[session_name()])):
setcookie(session_name(), '', time()-7000000, '/');
endif;
session_destroy();
$current_url = $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
wp_redirect($current_url) ;
exit() ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment