Created
January 4, 2022 17:25
-
-
Save techjewel/7f68c2499b0d6efdeed7b7c39e8e09c0 to your computer and use it in GitHub Desktop.
Change User Role on Fluent Forms Submission
This file contains 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 | |
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