Restrict user access to several actions in function
In your hook_menu call you can use different access arguments, to make sure only administrators access the callback function. For example,

'access arguments' =&gt; array('administer users'), // usually Administrators have this permissions


If users with some other roles try to access the menu, they'll get the Access Denied message by default.

If you want your users to access the function and restrict only certain part, you can check the user role in that case:

if ($user_id == NULL) {
  $user_id = $user-&gt;uid;
}
else {
  if(in_array('administrator', array_values($user-&gt;roles))) {
    //apply your exit function logic here
  }
}