Skip to content

Instantly share code, notes, and snippets.

@fazlurr
Created June 23, 2014 05:26
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 fazlurr/9f9c7cac603e026bd03b to your computer and use it in GitHub Desktop.
Save fazlurr/9f9c7cac603e026bd03b to your computer and use it in GitHub Desktop.
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
}
});
<?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