Advertisement
Guest User

Untitled

a guest
May 21st, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1.  
  2.  
  3. // the _3 prefix has to match the id of the form you have created
  4. add_action( "gform_after_submission_20", "login_form_after_submission_20", 10, 2 );
  5. function login_form_after_submission_20($entry, $form) {
  6. // get the username and pass
  7. $username = $entry[1];
  8. $pass = $entry[2];
  9. $creds = array();
  10. // create the credentials array
  11. $creds['user_login'] = $username;
  12. $creds['user_password'] = $pass;
  13. // sign in the user and set him as the logged in user
  14. $sign = wp_signon( $creds );
  15. wp_set_current_user( $sign->ID );
  16. }
  17.  
  18.  
  19. // the _3 prefix has to match the id of the form you have created
  20. add_filter( "gform_field_validation_20", "login_validate_field_20", 10, 4 );
  21. function login_validate_field_20($result, $value, $form, $field) {
  22. // make sure this variable is global
  23. // this function is fired via recurrence for each field, s
  24. global $user;
  25. // validate username
  26. if ( $field['cssClass'] === 'username' ) {
  27. $user = get_user_by( 'login', $value );
  28. if ( empty( $user->user_login ) ) {
  29. $result["is_valid"] = false;
  30. $result["message"] = "Invalid username provided.";
  31. }
  32. }
  33. // validate pass
  34. if ( $field['cssClass'] === 'password' ) {
  35. if ( !$user or !wp_check_password( $value, $user->data->user_pass, $user->ID ) ) {
  36. $result["is_valid"] = false;
  37. $result["message"] = "Invalid password provided.";
  38. }
  39. }
  40. return $result;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement