Skip to content

Instantly share code, notes, and snippets.

@gicolek
Created August 2, 2019 15:13
Show Gist options
  • Save gicolek/3cf496d070ab185066c87b15d33aac8e to your computer and use it in GitHub Desktop.
Save gicolek/3cf496d070ab185066c87b15d33aac8e to your computer and use it in GitHub Desktop.
Login user based on the Gravity Form Submitted Data
<?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