Your Moodle version

Enrolment: Enrol by user profile fields

Maintained by Picture of Nicolas Dunand Nicolas Dunand
This plugin allows users to be enrolled according to any value stored in their user profile.

This plugin allows users to be enrolled according to any value stored in their user profile. If you use an external authentication scheme (LDAP, Shibboleth), you can store values in hidden user fields of the users' Moodle profile, and then use these values to automatically enrol users if some courses.


Screenshot #0


Picture of Nicolas Dunand
Nicolas Dunand (Lead maintainer)
Please login to view contributors details and/or to contact them

Comments RSS

Show comments
  • Picture of Andras Koharek
    Thu, Aug 4, 2016, 3:40 AM
    Dear Nicolas,

    I added and set up the plugin (latest version), and have an issue. As you can see from your debug message your plugin finds two cases when the the enrolment should happen:

    sqlquery= SELECT DISTINCT FROM mdl3_user u RIGHT JOIN mdl3_user_info_data d1 ON d1.userid = WHERE (d1.fieldid = 4 AND ( = 'aaaaa' OR LIKE '%;aaaaa' OR LIKE 'aaaaa;%' OR LIKE '%;aaaaa;%' ))
    line 102 of \enrol\attributes\edit.php: call to debugging()
    countusers= 2
    line 104 of \enrol\attributes\edit.php: call to debugging()

    However when I push the force enrollment button nothing happens, even when a user log in no enrolment is happening. When the loged in user wants to enroll manualy Moodle says: you can not enrol yourself ... which is right as your plugin is the only one added to the course.

    Please help what is going wrong.

  • Picture of Andras Koharek
    Thu, Aug 4, 2016, 4:21 AM
    just one think to add: when I hit the force enrollment button an ajax window pops up stating this will (re)enroll all users corresponding to this rule. I push OK and nothing happens. When I hit the "purge enrollments" just to test same pop up comes and when I push the ok few sec later an other pop up comes stating, "ok, enrollments are purged". Hope this help to solve the issue.
    thanks in advance
  • Picture of Nicolas Dunand
    Thu, Aug 4, 2016, 3:01 PM
    Hi Andras,

    I've just sent you a private message to sort this out. Once this is sorted I'll post back here if some relevant info came up for other users of this plugin.
  • Picture of Nicolas Dunand
    Thu, Aug 4, 2016, 8:50 PM
    To people using this plugin on a Moodle where the database type is Oracle or MSSQL, be aware that there is a known bug that prevents the enrollments to occur properly.

    I'm currently working on this, and will hopefully provide a new release addressing this issue soon.

    For more information, see
  • Picture of Narissa Bayler
    Mon, Aug 8, 2016, 12:24 PM
    It appears the plugin doesn't take into account that not all Moodle databases use the old mdl_ prefix. I'm getting an error saying that table 'moodle.mdl_user' doesn't exist which is correct, we have never used the mdl_ prefix. I have edited your source code to get it working so far but it would be good if this could be fixed in the plugin. Cheers
  • Picture of Nicolas Dunand
    Mon, Aug 8, 2016, 5:22 PM
    Hi Narissa,

    Thanks, but this has been corrected in recent versions. Which version of the plugin are you using?
  • Picture of Fidel Leon
    Sat, Sep 3, 2016, 1:18 AM

    A *VERY* silly question: does this plugin automatically enrols anyone matching conditions, or is it "enroling as user accesses" - kind of the Self Enrolment builtin plugin? Because I believed it was the second option, and unfortunately all my students share the same extended profile field value ("Student") so all of sudden, in every course that uses your plugin, we have around 3,000 people enroled, to my teacher's dismay lol!
  • Picture of Juergen Kappus
    Sun, Sep 18, 2016, 3:00 PM
    It would be perfect if this plug-in would work with any profile field, not only custom fields.
  • Picture of Nicolas Dunand
    Tue, Sep 20, 2016, 4:38 PM
    Hi Fidel,

    It is :

    - enrol as user logs into Moodle (if it matches, obviously)
    - enrol during cron job, every 6 hours
  • Picture of Nicolas Dunand
    Tue, Sep 20, 2016, 4:38 PM
    Hi Jürgen,

    Thanks for your feedback – yeah it would be great, I really have to look into this as soon as I have a moment.
  • Picture of Andras Koharek
    Wed, Sep 21, 2016, 12:07 AM
    Hi Nicolas!

    let me join Jürgen's idea, and hope you will have that moment soon smile

  • Picture of Dietmar Grasböck
    Wed, Sep 21, 2016, 2:17 PM
    Hi Nicolas!

    great plugin that saves our trainer some time smile

    It would really be great, if it would work with the standard Moodle profile fields as well wink

    Regards, Dietmar
  • Picture of Blair F.
    Thu, Sep 22, 2016, 4:23 AM
    I agree with Jürgen that it would be great if other fields could be used, as well. In fact, my wish is just slightly more complicated: I would like to be able to use the email domain or subdomain. For example, all of our students emails end in and our employees end in I'd love to be able to auto-enrol students and teachers. We've got a custom "usertype" field (for some reason unknown to me), but I don't know how to populate it automatically, so it's not useful with this plugin, unless we manually enter the data.
  • Picture of Dietmar Grasböck
    Fri, Sep 23, 2016, 5:49 PM
    Hello Nicolas,

    you mentioned, that the enrolment happens in two ways:
    - enrol as user logs into Moodle (if it matches, obviously)
    - enrol during cron job, every 6 hours

    I have the problem, that my users cannot login anymore, when i define many (more than 20) criterias with the "OR" operator, to enrol in one course. It seems that during the login process some SQL querries run in infinite loop preventing the login going on. Only when the Admin purges the SQL queries users can continue to login.

    We use Moodle 2.9.2+ with 4.800 Users.

    Any ideas?

    As the enrolment triggered by the cron job seems to work without problems, is there a way to exclude the enrol process as user logs into Moodle? Where would I have to make changes?

    Best regards, Dietmar

  • Picture of Nicolas Dunand
    Fri, Sep 23, 2016, 7:30 PM
    Hello Dietmar,

    Thanks for reporting this.

    Indeed it seems that you are hitting performance limits – these can arise when the number of users is high (not so much in your case) or the complexity of the rules increase.

    As a first step, you could prevent the execution of the login hook by modifying the code as follows, in the file enrol/attributes/lib.php . After the function declaration `public static function process_login`, on the next line, simply add a line that contains `return true;` (without the quotes).

    I hope this helps, le me know!

1 2 3 4 5 6 7
Please login to post comments