Skip to content

Instantly share code, notes, and snippets.

@stevenmunro
Last active January 2, 2017 23:09
Show Gist options
  • Save stevenmunro/37eae83a9b5aaff261b687f99fc02106 to your computer and use it in GitHub Desktop.
Save stevenmunro/37eae83a9b5aaff261b687f99fc02106 to your computer and use it in GitHub Desktop.
<?php
add_filter( 'gform_field_validation_3', 'login_validate_field', 10, 4 );
function login_validate_field( $result, $value, $form, $field ) {
global $user;
if ( strpos( $field['cssClass'], 'email' ) !== false ) {
$user = get_user_by_email( $value );
if ( empty( $user->user_login ) ) {
$result["is_valid"] = false;
$result["message"] = "Sorry, we do not recognise that email address.";
}
}
if ( strpos( $field['cssClass'], 'password' ) !== false ) {
if ( !$user or !wp_check_password( $value, $user->data->user_pass, $user->ID ) ) {
$result["is_valid"] = false;
$result["message"] = "Incorrect Password.";
}
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment