I want an Ultimate Member action to be performed when I assign a particular role to a user. A role "old_member" exists. If I assign this role to a user, the account should deactivate itself with the Ultimate Member action "deactivate()". Unfortunately, it does not work with this code:
add_action( 'set_user_role', 'user_role_update', 10, 2);
function user_role_update( $user_id, $new_role ) {
if ($new_role == 'old_member') {
global $ultimatemember;
um_fetch_user( $user_id );
$ultimatemember->user->deactivate();
}
}
Here you can see the code of ultimate member: .php#L97
Can someone tell me what the mistake is?