Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Wordpress ajax sign in
//Your frontend javascript
var data = {
action: 'sign_in',
};'/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