Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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