Created
August 2, 2019 15:13
-
-
Save gicolek/3cf496d070ab185066c87b15d33aac8e to your computer and use it in GitHub Desktop.
Login user based on the Gravity Form Submitted Data
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 | |
/* part of a PHP Class */ | |
public function login_form_after_submission($entry, $form) { | |
// get the username or email and pass | |
$username_or_email = $entry[1]; | |
$pass = $entry[3]; | |
$creds = array(); | |
// create the credentials array | |
if( email_exists($username_or_email) ){ | |
$user = get_user_by( 'email', $username_or_email ); | |
$creds['user_login'] = $user->user_login; | |
} | |
else { | |
$creds['user_login'] = $username_or_email; | |
} | |
$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 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment