Created
September 24, 2014 12:50
-
-
Save gicolek/3d2704f57c6481bb48a6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // the _3 prefix has to match the id of the form you have created | |
| add_filter( "gform_field_validation_3", "login_validate_field", 10, 4 ); | |
| function login_validate_field($result, $value, $form, $field) { | |
| // make sure this variable is global | |
| // this function is fired via recurrence for each field, s | |
| global $user; | |
| // validate username | |
| if ( $field['cssClass'] === 'username' ) { | |
| $user = get_user_by( 'login', $value ); | |
| if ( empty( $user->user_login ) ) { | |
| $result["is_valid"] = false; | |
| $result["message"] = "Invalid username provided."; | |
| } | |
| } | |
| // validate pass | |
| if ( $field['cssClass'] === 'password' ) { | |
| if ( !$user or !wp_check_password( $value, $user->data->user_pass, $user->ID ) ) { | |
| $result["is_valid"] = false; | |
| $result["message"] = "Invalid password provided."; | |
| } | |
| } | |
| return $result; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment