Roles Machine name instead of role id I have custom module code that check the user role and based on user role, user fields updated,

for example 

if(array_key_exists(12,$user-&gt;roles)) {
    //Manger
    $role =  array(8=&gt;8);
} elseif (array_key_exists(13,$user-&gt;roles) ) {
    // super Manger
    $role =  array(14=&gt;14);
} elseif (array_key_exists(11,$user-&gt;roles)) {
    //section manager 
    $role =  array(14=&gt;14,8=&gt;8);
}


so when I want to move this module to other site and import roles using feature, the ids will changed.

so how can I use machine name for roles instead of ids.

Regard,
just make sure when you move your roles that you spell them the same!
then you can use the traditional

// Load the currently logged in user.
global $user;

// Check if the user has the 'editor' role.
if (in_array('editor', $user-&gt;roles)) {
  // do fancy stuff
}


or the more flamboyant

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']-&gt;roles)));
};

if (user_has_role(array('moderator', 'administrator'))) {
  // $user is admin or moderator
}


see here for more answers to the simple question Check if a user has a role