Hi @pete2650
You can try the following code snippets to your theme/child-theme’s functions.php file or use the Code Snippet to run the code:
add_action( 'profile_update', function( $user_id, $old_user_data ){
if( is_admin() ) return;
$keys = array_keys( $_REQUEST );
if( ! class_exists('UM') ) return;
$user = get_userdata( $user_id ); // get the user data
$user_roles = UM()->roles()->get_all_user_roles( $user_id ); // get all user roles
foreach ( $user_roles as $role ) {
$user->remove_role( $role ); // remove all roles
}
foreach( $keys as $k ){
if( get_user_meta( $user_id, 'drivers_license', true ) ){
$role_slug = 'um_member-patreon'; // User Role slug
UM()->roles()->set_role( $user_id, $role_slug ); // Set the new role
}else{ // if no driver's license, assign the subscriber role.
$role_slug = 'subscriber'; // User Role slug
UM()->roles()->set_role( $user_id, $role_slug ); // Set the new role
}
}
UM()->user()->remove_cache( $user_id ); // remove cache
}, 9999, 2 );
The above code will assign a role um_member-patreon
when there’s a driver’s license uploaded in the profile form. If there’s no uploaded image file, it will assign a subscriber
role to the user. The assigning of roles occurs when you submit the Profile Form. Please take note that it will remove all roles of a user and then assign a new role to the user when updating the role so make sure that you test it with another non-administrator account.
Regards,
-
This reply was modified 3 years, 4 months ago by Champ Camba.