Skip to content

Instantly share code, notes, and snippets.

@gicolek
Created September 24, 2014 12:50
Show Gist options
  • Select an option

  • Save gicolek/3d2704f57c6481bb48a6 to your computer and use it in GitHub Desktop.

Select an option

Save gicolek/3d2704f57c6481bb48a6 to your computer and use it in GitHub Desktop.
<?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