User Tools

Site Tools


drupal

This is an old revision of the document!


Drupal Tips

Some hints, tips and code samples for managing and extending Drupal.

Cron

Directory Structure

Externally Managing Users & Roles

Moving A Site

Programmatically create Drupal user and then store UID of new user

While looking for a means of extracting a userid from an account I came across the following article:

From the article I came up with the following PHP to obtain a uid from a name. The delete_user needs a uid so this was my way of getting the uid.

   $account = user_load_by_name($name);
   $uidn = $account->uid;

Updating Custom User fields

I added a custom field to the user object and needed a way to programmatically put data into that field. I found the following code on Drupal:

   $user_fields = user_load($user->uid);    
   $user_fields->field_points['und'][0]['value'] = $points;
   user_save($user_fields);
   

This comes from the following Drupal page:

The actual code that worked retrieved a user, updated the field and then saved it back follows. The field name is 'field_lname.

   $field_data = 'Glembocki';
   $name = 'tomg';
   $user_fields = user_load_by_name($name);
   $user_fields->field_lname['und'][0]['value'] = $field_data;
   user_save($user_fields);
drupal.1512393081.txt.gz · Last modified: 2017/12/04 08:11 by tomgle