Skip to content

Instantly share code, notes, and snippets.

Last active November 1, 2023 10:13
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
* Code snippet to make login form with Fluent Forms WordPress Plugins
* Steps:
* 1. make a form with email and password (Make sure the name attribute is 'email' and 'password' for corresponding field)
* 2. Paste the shorcode in a page
* 3. Change the form id in the bellow code (23) with your created fluentform's form id and paste in your theme's functions.php file
* 4. That's it
* Note: In this example: No actual form submission will be happened as we are redirecting the user before inserting the data
add_action('fluentform_before_insert_submission', function ($insertData, $data, $form) {
if($form->id != 23) { // 23 is your form id. Change the 23 with your own login for ID
$redirectUrl = home_url(); // You can change the redirect url after successful login
if (get_current_user_id()) { // user already registered
'result' => [
'redirectUrl' => $redirectUrl,
'message' => 'Your are already logged in. Redirecting now...'
$email = \FluentForm\Framework\Helpers\ArrayHelper::get($data, 'email'); // your form should have email field
$password = \FluentForm\Framework\Helpers\ArrayHelper::get($data, 'password'); // your form should have password field
if(!$email || !$password) {
'errors' => ['Please provide email and password']
], 423);
$user = get_user_by_email($email);
if($user && wp_check_password($password, $user->user_pass, $user->ID)) {
/* user is not logged in.
* If you use wp_send_json_success the the submission will not be recorded
* If you remove the wp_send_json_success then it will record the data in fluentform
* in that case you should redirect the user on form submission settings
'result' => [
'redirectUrl' => $redirectUrl,
'message' => 'Your are logged in, Please wait while you are redirecting'
} else {
// password or user don't match
'errors' => ['Email / password is not correct']
], 423);
}, 10, 3);
Copy link

Hi, any ideas on how to do the same for user registration form, using Fluent Forms WordPress Plugins

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment