Enrolment: Enrol by user profile fields

Maintained by Picture of Nicolas DunandNicolas Dunand
This plugin allows users to be enrolled according to any value stored in their user profile.
1629 sites
80 fans
Current versions available: 5

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)
Picture of RISET Université de Lausanne
RISET Université de Lausanne: Supporting institution
Please login to view contributors details and/or to contact them

Comments RSS

Show comments
  • Picture of Marta Semeniuk
    Mon, Jul 1, 2019, 4:21 PM
    Nicolas, thank you very much for the response! You are right, I didn't check Enrolments page! It works now.
  • Don
    Wed, Jul 17, 2019, 11:52 PM
    My install was not working, not appearing in Enrolment methods. Solved by removing special characters I had put into the field name. Yes, " / " does mess things up.

    I removed the slashes and everything works as hoped. Love this plugin and than you Nicolas
  • Don
    Thu, Jul 18, 2019, 2:55 AM
    Nicolas, I need to add the exact same enrollment by profile field(s) to a huge list of courses. Any of 3 profile choices using the "or" variable. Is there a cli script or SQL query I could use to populate multiple courses? Wishing I could use it at the Category Enrollment level but I don't see that working
  • Picture of Nicolas Dunand
    Mon, Jul 22, 2019, 5:43 PM

    Thanks for your feedback.

    1. I could not reproduce the problem you mention in your first post.

    2. Using SQL, you could use `SELECT * FROM mdl_enrol WHERE enrol = 'attributes' AND courseid = ` to get the values, and then use `INSERT` to insert similar rows for other courses – but there is no easy way to do this. The rule itself is a JSON string contained in the `customtext1` field.
  • Picture of Chad Jemison
    Wed, Aug 14, 2019, 3:15 AM
    I have installed this plugin on our Moodle 3.7 install. I am not sure I am seeing all the options correctly. I can only set the following settings from Dashboard - Site Administration - Plugins - Enrolments - Enrol by user profile fields: Default User, Default behaviour after attributes expiration, and Enrol users immediately at login. I have enabled the plugin, but am not able to choose it as an enrolment method in a quiz.
  • Picture of Nicolas Dunand
    Wed, Aug 14, 2019, 12:26 PM
    Hi Chad,
    You probably have to set at least one custom user profile field (see https://docs.moodle.org/37/en/User_profile_fields), then a new setting would appear in the plugin setting.
  • Picture of Chad Jemison
    Wed, Aug 14, 2019, 8:11 PM
    Thank you. That was what I needed. Is there a how-to guide available that I'm missing as well?
  • Picture of Gary Prosser
    Mon, Sep 2, 2019, 7:12 PM
    Hi Nicholas - your plugin is working well on our Moodle 3.6. In our case we allow certain users to update their own custom profile field(s) and enrolments take effect on next login. We would like that such changes take immediate effect. I thought that adding an additional array to $observers in db/events.php like

    'eventname' => '\core\event\user_info_field_updated',
    'callback' => 'enrol_attributes_plugin::process_enrolments',
    'includefile' => '/enrol/attributes/lib.php',
    'internal' => true,
    'priority' => 9999,

    but I suspect that is the wrong approach ! Can you offer any suggestions please ?
  • Picture of Nicolas Dunand
    Mon, Sep 2, 2019, 7:39 PM
    Hi Gary,

    Thanks for your feedback. Yes this would be possible, but please note that this could have a performance impact, as then all rules would have to be evaluated each time a user updates such a field.

    I had to add a feature to optionally disable the processing of all rules at login (see https://github.com/ndunand/moodle-enrol_attributes/commit/f395ff5eebbd), as this had a serious performance impact on our installation. This is due to the fact that we have almost 100k users and some complex enrolment rules – this results in a 100k^n join SQL query (where n is the number of rule components).

    Therefore we now rely on the scheduled task, which does process all enrolments every full hour, but you could also change the delay in the Moodle administration setup to make it run more often.
  • Picture of altan ahmet
    Mon, Nov 4, 2019, 12:00 AM
    Hi Nicolas

    I want to restrict my course to users with a gov.uk email address

    1. In User profile fields, do I define the extra profile field in text input field or text area ?
    2. Can you help with how I should be defining what I want , i.e. users with a gov.uk address ? Is it a case of simply adding free text or do I have to define an algorthim, such as " if email address ends in gov.uk " in the text area ? I am not a code writer so I would need advice on how to do the latter

  • Picture of Nicolas Dunand
    Wed, Nov 6, 2019, 6:41 PM
    Hi Altan,

    1. The extra profile field should be a text input.
    2. As of now the plugin only allows to check for exact values, not intervals or "value ending in", so changes should be made in the code to allow for this.
  • Picture of altan ahmet
    Wed, Nov 6, 2019, 11:14 PM
    Thanks Nicolas
  • Picture of Leslie Chukwunweike
    Sat, Nov 9, 2019, 4:24 AM
    Hi, Nicolas

    I'm using the latest build of your plugin (2018092300) with the latest build of Moodle 3.7 "Enrol users immediately at login" is checked. "Force enrolments" is not working well but "Purge enrolments" is working well, but executing the scheduled task "processenrolments_task" failed because of database write error! This process has never run since i installed the plug The other task "invalidatecache_task" is working smoothly.

    I have tried changing the faildelay value of the process through database table, but it keeps adjusting to 60seconds after each failed run. cron runs well. Any tips you can give me?
    Kind regards,
  • Picture of Nicolas Dunand
    Mon, Nov 25, 2019, 4:33 PM
    Hi Leslie,

    Sorry about the late reply. What I can suspect is that there is a timeout on the scheduled task. This can happen because the "Force" and "Purge" act on one enrollment (course), but the scheduled task acts on all defined rules in all courses.

    Do you run the cron by Web (page call) or CLI (command-line) ? I would recommend to try and run the cron by command line and see whether there still is a timeout and if so whether any more specific error is displayed.

  • Picture of Dillon Esterhuizen
    Fri, Jan 24, 2020, 9:08 PM
    Hey Nicolas

    I installed your plugin on a Moodle 3.4 site. When I go to Enrolled Users, I can see the info, cog and bin icons for users that I've enrolled using other enrollment methods, but not by users that have been enrolled using this plugin. If I select the user and then below the list go to "With selected user..." and select "Delete selected user enrolments", it just reloads the page and gives me a message "No users selected".

    Do you perhaps know how I can delete one specific user enrollment when the user was enrolled using your plugin?

    Kind regards,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Please login to post comments