Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to unenroll user programmatically

Tags:

moodle

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)
like image 678
wordpresrox Avatar asked Jul 15 '26 10:07

wordpresrox


1 Answers

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

like image 162
Russell England Avatar answered Jul 22 '26 14:07

Russell England



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!