How to manually create a user in Moodle?
authentication, moodle, php
Solution
User object should have the following values:
$user = new StdClass();
$user->auth = 'manual';
$user->confirmed = 1;
$user->mnethostid = 1;
$user->email = "email";
$user->username = "username";
$user->password = md5('password');
$user->lastname = "lastname";
$user->firstname = "firstname";
$user->id = $DB->insert_record('user', $user);
Please try this.
Problem
I am trying to create an authentication plugin, but I am having problems when the user does not exist in the moodle database. Therefore I am trying to find a way to manually create a user. I tried: ``` $user = new StdClass(); $user->username = $ucUser; $user->auth = 'ucauth'; $user->firstname = "First"; $user->lastname = "Last"; $user->id = $DB->insert_record('user', $user); ``` But it didn't work... I got an insert error. What else do I need in the `$user` object?