Moodle php code : To create a user in LMS

Create a user object and setup the values., you can setup more values.

    $user = new \stdClass();
    $user->firstname = $firstname;
    $user->lastname = $lastname;
    // Add missing required fields.
    $user = signup_setup_new_user($user);
    $user->username = $user->email;
    $user->password = $user->password;
    $user->confirmed = 1;
    $user->lang = current_language();

// custom profile field if you want
//    $user->profile_field_custom = 1;

    $auth_plugin = get_auth_plugin('email');
// password will be encrypted here
    $auth_plugin->user_signup($user, true);

    // Plugins can perform post sign up actions once data has been validated.
    core_login_post_signup_requests($user);

Leave a Reply

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