回答:
すでにその投稿を見つけているので、コメントも必ず読んでください。役割の確認よりも許可の確認が推奨される理由を明確に説明しています。パーミッションを使用する場合、そのパーミッションを複数のロールに割り当てることができ、システムをより柔軟にします。また、ロールの名前を変更すると、コードが破損する可能性があることを忘れないでください。
ただし、役割を確認する場合は、次の操作を実行できます。
// Load the currently logged in user.
global $user;
// Check if the user has the 'editor' role.
if (in_array('editor', $user->roles)) {
  // do fancy stuff
}
現在のユーザーが単一のロールを持っているのか、複数のロールを持っているのかを確認するには、次の方法が最適です。
//can be used in access callback too
function user_has_role($roles) {
    //checks if user has role/roles
    return !!count(array_intersect(is_array($roles)? $roles : array($roles), array_values($GLOBALS['user']->roles)));
};
if (user_has_role(array('moderator', 'administrator'))) {
  // $user is admin or moderator
} else if(user_has_role('tester')){
  // $user is tester
} else{
  // $user is not admin and not moderator
}
Drupalバージョン> = 7.36の更新
Drupal API https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_has_role/7の関数user_has_roleを使用できます。
この例を試してください:
<?php
function MYMODULE_foo() {
  $role = user_role_load_by_name('Author');
  if (user_has_role($role->rid)) {
    // Code if user has 'Author' role...
  }
  else {
    // Code if user doesn't have 'Author' role...
  }
  $user = user_load(123);
  if(user_has_role($role->rid, $user)) {
    // Code if user has 'Author' role...
  }
  else {
    // Code if user doesn't have 'Author' role...
  }
}
?>
develモジュールをインストールして、dpm($ user)を実行できます。これにより、ユーザーロールを含むすべてのユーザー情報を含む配列が出力されます。
この配列から、「ロール」の配列位置を見つけ、モジュールでそれを使用してユーザーロールを見つけることができます。
ロール名が変更された場合に備えて、将来のために、データベースのロールテーブルにあるロールID(rid)を確認するのが最善です。
rid 16でロールを確認する場合は、次の操作を行います。
// Load the currently logged in user.
global $user;
// Check if the user has the 'editor' role, when 'editor' has role id 16
if (array_key_exists(16, $user->roles)) {
  // do fancy stuff
}
ベストプラクティスとして受け入れられた回答で言及されているコメントの実際のコードは次のとおりです
<?php
  function mymodule_perm() {
    return array('access something special');
  }
  function dosomethingspecial() {
    // For current user
    if (user_access('access something special')) {
      // Doing something special!
    }
    // For a specific user
    if (user_access('access something special', $theuser)) {
      // Doing something special!
    }
  }
?>