Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'wp_ajax_nopriv_ajax_login_func', 'ajax_login_func' );
- add_action( 'wp_ajax_ajax_login_func', 'ajax_login_func' );
- function ajax_login_func() {
- $username = sanitize_text_field($_POST['user']);
- $password = sanitize_text_field($_POST['password']);
- $creds = array();
- $creds['user_login'] = $username;
- $creds['user_password'] = $password;
- $creds['remember'] = true;
- $user = wp_signon( $creds, false );
- if ( is_wp_error($user) ) {
- echo 0;
- die();
- }
- $userID = $user->ID;
- wp_set_current_user( $userID, $username );
- wp_set_auth_cookie( $userID, true );
- echo 1;
- die();
- }
Add Comment
Please, Sign In to add comment