0

In Drupal 7, I have a role named as "blogger". When user goes to blog site and created an account then a role should set by default as "blogger" rather than "authenticated user". How to do this? Any Suggestions please.

  • 1
    If every user is a blogger then the easiest way I see is not to have it as a separate role at all; instead assign similar permissions to authenticated user. – AjitS Feb 21 '13 at 6:36
2

Adding my comment as answer. If every user is a blogger then the easiest way I see is not to have it as a separate role at all; instead assign similar permissions to authenticated user.

Or you could change the role of the user by implementing hook_user_insert():

function MODULE_user_insert(&$edit, $account, $category) {
  $account->role = 'blogger';
  user_save($account, $edit = array(), $category = 'account');
}
|improve this answer|||||
  • Thanks for u r reply. I have another user also in this user table, it is not only one blogger. It is not the matter as for now. I kept the code as below two ways in user.module page, but it is not inserting as "blogger" role... what I need to do. 1) function hook_user_insert(&$edit, $account, $category) { $account->role = 'blogger'; user_save($account, $edit = array(), $category = 'account'); } 2) function hook_user_insert(&$edit, $account, $category) { db_insert('users')->fields(array( 'role' => 'blogger', ))->execute(); } – J Sinha Feb 21 '13 at 7:19
  • 1
    It is not recommended to hack core. You should implement the code in a custom module. See Module developer's guide for details. – AjitS Feb 21 '13 at 7:24
0

I found the solution from this Auto Assign Role Module - http://drupal.org/project/autoassignrole .

In congifuration settings, We can assign for automatic role.

|improve this answer|||||
0

I found that you need to add the role name - together with its key - into the new user's 'roles' array. In the example below, the role 'teacher' has a rid of 8:-

function MODULE_user_insert(&$edit, $account, $category){
  $account->roles[8]='teacher';
}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.