Skip to content

Instantly share code, notes, and snippets.

@techjewel
Created January 4, 2022 17:25
Show Gist options
  • Save techjewel/7f68c2499b0d6efdeed7b7c39e8e09c0 to your computer and use it in GitHub Desktop.
Save techjewel/7f68c2499b0d6efdeed7b7c39e8e09c0 to your computer and use it in GitHub Desktop.
Change User Role on Fluent Forms Submission
<?php
add_action('fluentform_submission_inserted', function ($insertId, $formData, $form) {
if($form->id != 23) { // 23 is your target form id
return;
}
$userId = get_current_user_id();
if(!$userId) {
return;
}
$user = get_user_by('ID', $userId);
$roles = (array) $user->roles;
$newUserRole = 'subscriber'; // Add your role name here
if(in_array($newUserRole, $roles)) {
return; // role already attached
}
$user->add_role( $newUserRole ); // new role attached to the user
}, 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment