Check for User Role http://ryanszrama.com/blog/10-25-2007/checking-if-drupal-user-has-role

Public

Use the following simple snippet to check if a user (in this example, it's the logged in user since I'm getting the global $user) has been assigned a certain role on your site:

</> CopyGet raw version
php
  1. global $user;
  2.  
  3. // Check to see if $user has the administrator role.
  4. if (in_array('administrator', array_values($user->roles))) {
  5. // Do something.
  6. }

Replace 'administrator' with whatever role it is you're trying to check against. Alternatively, if you keep a helper module for use on your projects, go ahead and drop this function in it:

</> CopyGet raw version
php
  1. /**
  2.  * Check to see if a user has been assigned a certain role.
  3.  *
  4.  * @param $role
  5.  * The name of the role you're trying to find.
  6.  * @param $user
  7.  * The user object for the user you're checking; defaults to the current user.
  8.  * @return
  9.  * TRUE if the user object has the role, FALSE if it does not.
  10.  */
  11. function user_has_role($role, $user = NULL) {
  12. if ($user == NULL) {
  13. global $user;
  14. }
  15.  
  16. if (is_array($user->roles) && in_array($role, array_values($user->roles))) {
  17. return TRUE;
  18. }
  19.  
  20. return FALSE;
  21. }

It might be better to add a user access permission and then use that instead of just checking if they're part of that role:

</> CopyGet raw version
php
  1. function mymodule_perm() {
  2. return array('access something special');
  3. }
  4.  
  5. function dosomethingspecial() {
  6. // For current user
  7. if (user_access('access something special')) {
  8. // Doing something special!
  9. }
  10.  
  11. // For a specific user
  12. if (user_access('access something special', $theuser)) {
  13. // Doing something special!
  14. }
  15. }

There is...
http://api.drupal.org/api/function/user_access/5

</> CopyGet raw version
php
  1. $u = user_load(array('uid' => 12'));
  2. if (user_access('Administer Nodes', $u)) {
  3. return t('User 12 does have access to this');
  4. }
  5. else {
  6. return t('User 12 does not have access to this');
  7. }
  8.  
  9.  
  10.  
  11. if (user_access('Administer Nodes')) {
  12. return t('Current User does have access to this');
  13. }
  14. else {
  15. return t('Current User does not have access to this');
  16. }