How to create a user programmatically in Drupal ?

Why would you need to load or create a Drupal user from your PHP script ? Because you can associate processes and node importations with a user to identify them quickly into the Drupal content administration ! Then, it’s faster to create it programmatically¬†if it doesn’t exist.

If you want to create or retrieve a Drupal user from your PHP Script, pretty simple:

This snippet will load the existing username. If it doesn’t exist, it will create it and load it.

Later you will associate your node with this user:

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Post Navigation