// ++++++++++++ 1st form - id 17 ++++++++++++++ // the _3 prefix has to match the id of the form you have created add_action( "gform_after_submission_17", "login_form_after_submission", 10, 2 ); function login_form_after_submission($entry, $form) { // get the username and pass $username = $entry[1]; $pass = $entry[2]; $creds = array(); // create the credentials array $creds['user_login'] = $username; $creds['user_password'] = $pass; // sign in the user and set him as the logged in user $sign = wp_signon( $creds ); wp_set_current_user( $sign->ID ); } // the _3 prefix has to match the id of the form you have created add_filter( "gform_field_validation_17", "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; } // ++++++++++++ Second form : id 20 ++++++++++++++ // the _3 prefix has to match the id of the form you have created add_action( "gform_after_submission_20", "login_form_after_submission", 10, 2 ); function login_form_after_submission($entry, $form) { // get the username and pass $username = $entry[1]; $pass = $entry[2]; $creds = array(); // create the credentials array $creds['user_login'] = $username; $creds['user_password'] = $pass; // sign in the user and set him as the logged in user $sign = wp_signon( $creds ); wp_set_current_user( $sign->ID ); } // the _3 prefix has to match the id of the form you have created add_filter( "gform_field_validation_20", "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'] === 'usernamelogin' ) { $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'] === 'passwordlogin' ) { if ( !$user or !wp_check_password( $value, $user->data->user_pass, $user->ID ) ) { $result["is_valid"] = false; $result["message"] = "Invalid password provided."; } } return $result; }