Created
May 21, 2015 16:53
-
-
Save JudeRosario/2d73776f9e959deb524f to your computer and use it in GitHub Desktop.
Domain Mapping + Flush Sessions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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