//Your frontend javascript | |
var data = { | |
action: 'sign_in', | |
username:"<username>", | |
pass:"<password>" | |
}; | |
jQuery.post('/wordpress/wp-admin/admin-ajax.php', data, | |
function(response) { | |
alert("signed in successfully"); | |
}); |
//Your functions.php | |
add_action('wp_ajax_sign_in', 'ajax_sign_in'); | |
add_action('wp_ajax_nopriv_sign_in', 'ajax_sign_in'); | |
function ajax_sign_in() { | |
$creds = array(); | |
$creds['user_login'] = $_POST['email']; | |
$creds['user_password'] = $_POST['pass']; | |
$creds['remember'] = true; | |
$user = wp_signon( $creds, false ); | |
if ( is_wp_error($user) ) { | |
echo "error"; | |
} else { | |
echo "success"; | |
} | |
die(); // this is required to return a proper result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment