Skip to main content

Articles tagged with "users"

Recovering deleted content

7th Jul 2020

Drupal 7 introduced the brilliant feature of letting users cancel their own account and with it various options for what to do with content they've created when they are cancelled. One of these options is to:

Delete the account and its content.

Which can prove somewhat problematic if used incorrectly.

You see, Drupal is very good at the latter part: deleting all the content created by the user. It's not very good at warning someone that they are about to delete potentially a lot of important content.

The scenario

Let me set the scene for you. Someone had...

Read more

Drupal roles : Programatically Adding a role to a user in Drupal 7

20th Jan 2011

It used to be a bit of a chore to add a role a user in Drupal, but no longer!

All you need to do is this (in Drupal 7):


$uid = 123;// User ID of user that you want to add role to.
$role_name = 'Role to add'; // The name of the role to add.
if ($role = user_role_load_by_name($role_name)) {
  user_multiple_role_edit(array($uid), 'add_role', $role->rid);
}

Of course someone can still come along and screw up your code by changing the name of the role, so you might want to use the role ID directly, and not bother with the...

Read more