Add User Role: Pre-saved in User-Meta [SOLVED]

That’s because you’re not passing an actual ID to get_user_meta, but merely a string of id:

$get_portal_number = get_user_meta('id', 'portal_number', false);

In addition, the third parameter is set to false, which will return an array. You’re passing that value straight to $user->add_role, but that expects a string.

You either have to loop over your post meta results, or return the role as a single value by passing true as the third parameter.

Try this:

add_action('um_after_save_registration_details', 'custom_after_new_user_register', 10, 2);

function custom_after_new_user_register($user_id) {

$user = get_user_by('id', $user_id);
$get_portal_number = get_user_meta($user_id, 'portal_number', true);
if (!in_array('subscriber', $user->roles)) {
    $user->add_role($get_portal_number);
    
  }}