I found great little function for enrolling User to a course here: https://moodle.org/mod/forum/discuss.php?d=266496
The problem is, I'm keep getting "invalid enrol instance" error message at the following line:
$enrol->enrol_user($instance, $userid, $roleid);
Stack trace is the following:
invalid enrol instance!' in enrollib.php:1641
enrol_plugin->enrol_user(Object(stdClass), '192', '5')
check_enrol('TT001', '192', '5', 'manual')
Moodle version is 3.3