I have created custom user roles 'teacher' and 'student' using members plugin. But they are unable to log in using wp_signon
but the admin and other roles are able to log in. I tried using my custom login page and wp-admin. It doesn't work.
function get_username($email) {
$user = get_user_by('email', $email);
return $user->data->user_login;
}
function ajax_login(){
// First check the nonce, if it fails the function will break
check_ajax_referer('ajax-login-nonce', 'security');
$login = get_username($_POST['email']);
$pass = $_POST['password'];
// Nonce is checked, get the POST data and sign user on
$info = array();
$info['user_login'] = $login;
$info['user_password'] = $_POST['password'];
$info['remember'] = true;
$user_signon = wp_signon( $info, false );
if ( is_wp_error($user_signon) ){
echo json_encode(array('loggedin'=>false, 'message'=>__('Wrong username or password.'), 'login'=>$login, 'pass'=>$pass));
} else {
echo json_encode(array('loggedin'=>true, 'message'=>__('Login successful, redirecting...')));
}
die();
}
// Enable the user with no privileges to run ajax_login() in AJAX
add_action( 'wp_ajax_nopriv_ajaxlogin', 'ajax_login' );
Can anybody help me?