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)
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)
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