3

i want to unenrol user from a course in moodle ,i want to know there is any in built function like

unenrol_user($userid,$courseid)
wordpresrox
  • 590
  • 11
  • 31

1 Answers1

5

Try this

$instances = $DB->get_records('enrol', array('courseid' => $courseid));
foreach ($instances as $instance) {
    $plugin = enrol_get_plugin($instance->enrol);
    $plugin->unenrol_user($instance, $userid);
}

Moodle supports multiple enrollment methods (e.g. 'manual', 'guest', etc.,) via plugins. This loops through the enrollment methods configured for the course and tries to unenroll the user using each.

Library: lib/enrollib.php

George Marian
  • 2,680
  • 20
  • 21
Russell England
  • 9,436
  • 1
  • 27
  • 41