💾 Archived View for chirale.org › 2008-12-03_241.gmi captured on 2024-07-08 at 23:43:50. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2024-05-12)

-=-=-=-=-=-=-

Save user profile on Drupal

Tested on:

After you have created some user fields through Profile module provided by core, you can have the need to save value into the user object. Here a quick howto to do this.

On user creation:

/** create user profile ($new_user will be an user object) */ $new_user_array = array ( 'name' => "funnyusername", 'pass' => "MyVerySecurePassword", 'mail' => "info@example.gom", 'status' => 1, # status: active ); $new_user = user_save(NULL, $new_user_array, $category = 'account'); /bin /boot /dev /etc /home /init /lib /lib32 /lib64 /libx32 /lost+found /media /mnt /opt /proc /root /run /sbin /srv /sys /tmp /usr /var assign values to profile fields */ $new_user_edit =  array( 'profile_surname' => "Yumemiya", 'profile_name' => "Arika", ); /bin /boot /dev /etc /home /init /lib /lib32 /lib64 /libx32 /lost+found /media /mnt /opt /proc /root /run /sbin /srv /sys /tmp /usr /var create and save profile fields */ profile_save_profile($new_user_edit, $new_user, "Character ID");

Where “Character ID” is the category name for profile_surname e profile_name.

To load current user instead creating new one, you have to use

global $user;

instead a previously declared user object $new_user.

See also:

Update:

Problem:

Add a “cronbot” user with some privileges over user (“administer user”) to allow writing even on hidden Profile field.

Solution:

On a dedicated server, with a dedicated IP, you can automatically login by IP (by IP Login module for x and x) the cronjob using the server IP or loopback address (1) depending on server configuration (I use the first in production, the latter on local testing).

=> http://api.drupal.org/api/function/hook_cron/5 hook_cron

=> http://drupalmodules.com/module/ip-login IP Login module

Add an ip_login Profile field (single line text field, hidden field) Enable IP Login module Assign ip_login field to IP login by IP Login configuration screen Create a new role named “cronbots”, with “administer users” permission. Create a new user named “cronbot”, with “cronbots” role assigned Change the “IP login” field for “cronbot” to your server IP (1 or your static IP address as listed on ifconfig on \*nix servers)

On the next automatic cron run (not force it), you’ll see the “cronbot” user logging in. On Drupal logs, the cronjob execution pass from “Anonymous” to “cronbot”, and profile fields are rightly written.

The other way:

Just write profile field via db_query. (You don’t want to do a weird thing like that, right?=> https://swp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/72x72/1fpng 😉

)

https://web.archive.org/web/20081203000000*/http://api.drupal.org/api/function/profile_save_profile/5

https://web.archive.org/web/20081203000000*/http://api.drupal.org/api/function/profile_load_profile/5

https://web.archive.org/web/20081203000000*/http://api.drupal.org/api/function/hook_cron/5

https://web.archive.org/web/20081203000000*/http://drupalmodules.com/module/ip-login