Last active
May 21, 2016 13:41
-
-
Save moafzalmulla/5ce3413c8055b8d28c526390f1b1afc4 to your computer and use it in GitHub Desktop.
Revisions
-
moafzalmulla revised this gist
May 21, 2016 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,6 @@ // You must set the css classes of both input fields to username and password respectively for this to work // Code forums - cant remember exactly link // the _3 prefix has to match the id of the form you have created add_action( "gform_after_submission_20", "login_form_after_submission_20", 10, 2 ); function login_form_after_submission_20($entry, $form) { -
moafzalmulla created this gist
May 21, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ // the _3 prefix has to match the id of the form you have created add_action( "gform_after_submission_20", "login_form_after_submission_20", 10, 2 ); function login_form_after_submission_20($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_20", 10, 4 ); function login_validate_field_20($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; }