Guest User

Untitled

a guest
May 26th, 2016
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. add_action( 'wp_ajax_nopriv_ajax_login_func', 'ajax_login_func' );
  2. add_action( 'wp_ajax_ajax_login_func', 'ajax_login_func' );
  3. function ajax_login_func() {
  4. $username = sanitize_text_field($_POST['user']);
  5. $password = sanitize_text_field($_POST['password']);
  6.  
  7. $creds = array();
  8. $creds['user_login'] = $username;
  9. $creds['user_password'] = $password;
  10. $creds['remember'] = true;
  11. $user = wp_signon( $creds, false );
  12. if ( is_wp_error($user) ) {
  13. echo 0;
  14. die();
  15. }
  16.  
  17. $userID = $user->ID;
  18. wp_set_current_user( $userID, $username );
  19. wp_set_auth_cookie( $userID, true );
  20. echo 1;
  21. die();
  22.  
  23. }
Add Comment
Please, Sign In to add comment