• Resolved saadies

    (@saadies)


    Hey, I’m struggling to set role of a user after registration depending on a custom field.

    echo $ultimatemember->user()->get_role();
    Wroks fine and I already tried using UM() instead of $ultimatemember and get_role(id,role) It’s still undefined for set role….

    
    add_action( 'um_after_save_registration_details', 'workflow_mail', 10, 2 );
    
    function workflow_mail( $user_id, $submitted ) {
        
    	global $ultimatemember;
    	
    	if( empty( $user_id ) ) {
    		$user_id = get_current_user_id();
    	}
    	echo $taetigkeit = get_user_meta( $user_id, 'taetigkeit', true);
    	
    	um_fetch_user($user_id);
    	
    	echo $ultimatemember->user()->get_role();
    	
    	if($taetigkeit == '1'){
    		$ultimatemember->user()->set_role('um_1');
    	}else{
    		$ultimatemember->user()->set_role('um_2');
    	}

    Thank you for helping

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Towhid

    (@cryptex_vinci)

    Hi @saadies

    The $ultimatemember global variable is deprecated. Please use UM() instead. set_role() is a method of Roles_Capabilities class.

    Here’s a sample code that changes a user role in UM 2.0+:

    $user_id = 123;
    $role_name_slug = "subscriber";
    UM()->roles()->set_role( $user_id, $role_name_slug );

    Thanks

    • This reply was modified 4 years, 5 months ago by Towhid.
    Thread Starter saadies

    (@saadies)

    Thanks a lot, it works perfectly ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Call to undefined method um\core\User::set_role()’ is closed to new replies.