Authentication: Autoenrol cohort

Maintained by Picture of Dan MarsdenDan Marsden, Picture of Catalyst ITCatalyst IT
This Authentication plugin automatically assigns users into cohorts based on information in their user profile fields.
646 sites
49 fans
Current versions available: 6

PLEASE NOTE - this plugin has been deprecated and replaced by:


Auto cohort authentication plugin

This authentication plugin automatically assigns users into cohorts.

Cohort name depends on user profile field.

Cohorts are created in CONTEXT_SYSTEM.


  • Download the archive and extract the files, or clone the repository from GitHub
  • Copy the 'mcae' folder into your_moodle/auth
  • Visit Site administration - Notifications page and follow the instructions


Template for cohort name

1 template per line.

In the template you may use any characters (except '{' and '}') and profile field values. To insert a profile field value, use {{ field_name }} tag.

An email field have 3 variants:

  • {{ email.full }} - full email
  • {{ email.username }} - only username
  • {{ email.domain }} - only domain
  • {{ email.rootdomain }} - root domain

By default moodle provides this fields

{{ id }}, {{ auth }}, {{ confirmed }}, {{ policyagreed }}, {{ deleted }}, {{ suspended }}, {{ mnethostid }}, {{ username }}, {{ idnumber }}, {{ firstname }}, {{ lastname }}, {{ email.full }}, {{ email.username }}, {{ email.domain }}, {{ email.rootdomain }}, {{ emailstop }}, {{ icq }}, {{ skype }}, {{ yahoo }}, {{ aim }}, {{ msn }}, {{ phone1 }}, {{ phone2 }}, {{ institution }}, {{ department }}, {{ address }}, {{ city }}, {{ country }}, {{ lang }}, {{ calendartype }}, {{ theme }}, {{ timezone }}, {{ firstaccess }}, {{ lastaccess }}, {{ lastlogin }}, {{ currentlogin }}, {{ lastip }}, {{ secret }}, {{ picture }}, {{ url }}, {{ descriptionformat }}, {{ mailformat }}, {{ maildigest }}, {{ maildisplay }}, {{ autosubscribe }}, {{ trackforums }}, {{ timecreated }}, {{ timemodified }}, {{ trustbitmask }}, {{ imagealt }}, {{ lastnamephonetic }}, {{ firstnamephonetic }}, {{ middlename }}, {{ alternatename }}, {{ lastcourseaccess }}, {{ currentcourseaccess }}, {{ groupmember }}

Additional tags become available if you have some custom profile fields. For example if you create custom profile fields

  • checkboxtest - type Checkbox
  • datetimetest - type Date/Time
  • droptest - type Dropdown menu
  • textinputtext - type Text input
  • and textareatest - type Text area

You be able to use this tags: {{ profile.checkboxtest }}, {{ profile.datetimetest }}, {{ profile.droptest }}, {{ profile.textinputtext }}, {{ profile_field_checkboxtest }}, {{ profile_field_datetimetest }}, {{ profile_field_droptest }}, {{ profile_field_textareatest.text }}, {{ profile_field_textareatest.format }}, {{ profile_field_textinputtext }}

> Note: Profile field templates is case sensitive. {{ username }} and {{ UserName }} are two different fields!

Split arguments: Synopsis: %split(fieldname|delimiter)

Returns multiple cohorts, each of which is formed by splitting field on boundaries formed by the delimiter.


  • fieldname - Profile field name. The same as tag, but without '{{' and '}}'
  • delimiter - The boundary string. 1 - 5 signs.


User John set custom profile field "Known languages" to "English, Spanish, Chinese"

Main template contains string "Language - %split(knownlanguage|, )"

John will be enrolled in 3 cohorts: Language - English, Language - Spanish and Language - Chinese

Replace empty field

If profile field is empty then it's replaced with this value.

Replacement array

You can change the cohort name after it's generation.

1 replacement per line, format - old value|new value

very long cohort name|shortname

Note: The name must not be longer than 100 characters or it will be stripped


Unassign users from cohorts after profile change.

To use an unassign feature:

  • Go to Plugins - Authentication - Autoenrol cohort and enable unenrol function
  • Go to yourmoodle/auth/mcae/convert.php and convert cohorts you want to "auth_mcae".

Convert only cohorts that are created by the "auth_mcae" module!

At yourmoodle/auth/mcae/convert.php page you may view, delete or convert cohorts into "manual" or "auth_mcae" mode.

Ignore users

List of users to ignore. Comma separated usernames.


Usage example

You have a custom profile fields "status" (student, teacher or admin) and "course".

You wnat to enrol many users into cohorts like "course - status" than enrol cohorts into courses.

At configuration page set:

Main template to {{ profile_field_course }} - {{ profile_field_status }}

Empty field text to none


  • When 1st course student logins, he enrol to cohort named "1 - student"
  • When 1st course teacher logins, he enrol to cohort named "1 - teacher"
  • When admin logins, he enrol to cohort named "none - admin" (Course not set, status - admin)

To rename "none - admin" cohort to "Administration" you must set a replacement array field at the configuration page In our case: none - admin|Administrator


When admin logins, he enrol to cohort named "Administrator"


Screenshot #0
Screenshot #1
Screenshot #2


Picture of Dan Marsden
Dan Marsden (Lead maintainer)
Picture of Andrew Kama
Andrew Kama: Previous maintainer
Please login to view contributors details and/or to contact them

Comments RSS

Show comments
  • Picture of Francis Vendrell
    Tue, Aug 8, 2017, 6:57 PM
    Version mcae 3.1 (2016022900) doesn't seem to work with Moodle 3.3.1.
    Is the Github version compatible with Moodle 3.3.1?
  • Picture of Bas Harkink
    Tue, Aug 15, 2017, 11:46 PM
    We are setting up a Moodle site where a user makes their own account through a version of the email self registration. In this form the user choses a cohort that we have setup beforehand. (create cohort, than convert to mcae cohort using /mcae/convert.php).

    At first that process seemed to work perfectly. Now we are noticing that mcae is creating new cohorts with the same name and assigning users in that cohort instead of the cohort we setup beforehand (and added to courses as a enroll method). Do you have any idea what could be the problem?

    And thank you for taking the time to maintain this plugin, Dan!
    Best, Bas Harkink
  • Picture of Luka Torby
    Sat, Jan 13, 2018, 8:15 AM
    I have github version and Moodle 3.4. All is ok but the cohort's name. Why the cohort's name is wrong? It seem that doesn't recognizes the any field, and it uses the empty field text. Thank you.
  • Picture of Dan Marsden
    Mon, Jan 15, 2018, 3:38 AM
    @Luka - it's not clear what your issue is - you could try asking for help in the community forums where you can also include screenshots - alternatively you purchase support from your local Moodle Partner who might also be able to help further.
  • Ricardo Caiado
    Tue, Mar 13, 2018, 10:03 PM

    Is it compatible with Moodle 3.4?

  • Picture of Dan Marsden
    Wed, Mar 14, 2018, 5:12 AM
    @Ricardo - it should work ok, but I haven't tested it on anything other than 3.1 myself. Feel free to report any issues you have with it to the issues tracker. Thanks.
  • Picture of Dan B.
    Wed, Oct 3, 2018, 3:50 AM
    OK, I need a hand here, I am running 3.5.2 Moodle, and got the latest plug's doesn't break anything, the forms work as expected and all that, then I go into the "plugins overview" and it shows the plugin as "disabled".

    Is this plug incompatible with 3.5.x, or am I missing something, I see nowhere to "enable".

    BTW, relatively new to Moodle, but not CMS or PHP Development, so any guidance would be helpful.
  • Picture of Dan Marsden
    Wed, Oct 3, 2018, 5:10 AM
    @Dan - this plugin is an authentication plugin - so you need to enable it under Admin > Plugins > Authentication > Manage authentication.

    I inherited this plugin from someone else that originally wrote it and would like to eventually change it to being an admin tool plugin as it now uses events and doesn't need to hook into the authentication code. thanks.
  • Picture of Dan B.
    Wed, Oct 3, 2018, 8:37 PM
    That did it, thanks!
  • Picture of Dan B.
    Sat, Oct 6, 2018, 2:54 AM
    OK, it's enabled, but not working properly (as I believe should be proper operating...)

    I have three cohorts, Coach, Athlete and RSO.

    I have three checkboxes as custom profile fields labels Coach, Athlete and RSO, Moodle checkboxes are 0 or 1 it appears.

    My templates are:
    Coach-{{ profile_field_Coach }}
    Athlete-{{ profile_field_Athlete }}
    RSO-{{ profile_field_RSO }}

    My Replace Array is:

    I have a 0 (zero) in as empty field replacement.

    I have tried all three delimiters, though I develop on Mac, it should be just LF I believe.

    Any tips on this?
  • Picture of A Guy
    Tue, Mar 26, 2019, 9:39 AM
    I set up my autoenroll cohort to enroll in users in a course that have a particular value in the profile "Department" field. I created two cohorts. For example, one "Sales" and one "Customer Service". I added them as enrollment methods to the desired courses. I created a manual user with a username/password and "Sales" as the department. I logge din as him and I am enrolled in the "Sales" courses. Good so far. Then I have a user that is created and logins in via SAML/SSO. His department is also "Sales". His profile gets created with "Sales" as the department. But for whatever reason when I log in as him he is not enrolled in the courses. So do you know where I am going wrong here? Is this plugin only for a particular type of account--manual accounts? Do I need to alter the code? The plugin settings? I don't see a way to do that. Thanks.
  • FX
    Wed, Jun 12, 2019, 6:53 AM
    I have the exact same problem of A Guy. Is there a way to make it work using SAML2 ?
  • Picture of Martin Greenaway
    Mon, Jul 1, 2019, 7:08 PM
    Hi, does anyone know if there is a known issue with Autoenrol Cohort not firing the first time a user logs in, *if* the User Tours are activated? We're finding users have to log out after the tour and back in again for the Autoenrol Cohort process to happen - wondering if anyone else has seen this?
  • Stefano Guglielmetti
    Wed, Nov 6, 2019, 5:20 PM
    I'm looking for a plugin like that but I'm using Moodle 3.5.3... any ideas?
  • Picture of Dan Marsden
    Thu, Nov 7, 2019, 10:17 AM
    @stefano - the latest version of this plugin is here:

    we have refactored it into a local plugin so it is more efficient -
    If you have a small number of known cohorts, you might find this plugin useful too:
1 2 3 4 5 6
Please login to post comments