Created
June 23, 2014 05:26
-
-
Save fazlurr/9f9c7cac603e026bd03b to your computer and use it in GitHub Desktop.
WP Ajax check is user logged in - http://wordpress.stackexchange.com/questions/69814/check-if-user-is-logged-in-using-jquery/69819#69819
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
var data = { | |
action: 'is_user_logged_in' | |
}; | |
jQuery.post(ajaxurl, data, function(response) { | |
if(response == 'yes') { | |
// user is logged in, do your stuff here | |
} else { | |
// user is not logged in, show login form here | |
} | |
}); |
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
<?php | |
function ajax_check_user_logged_in() { | |
echo is_user_logged_in()?'yes':'no'; | |
die(); | |
} | |
add_action('wp_ajax_is_user_logged_in', 'ajax_check_user_logged_in'); | |
add_action('wp_ajax_nopriv_is_user_logged_in', 'ajax_check_user_logged_in'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment