Your Moodle version

Authentication: Autoenrol cohort

Maintained by Picture of Andrew Kama Andrew Kama
This Authentication plugin automatically enrol users into cohorts. Cohort name depends on user profile field.

This Authentication plugin automatically enrol users into cohorts.

Cohort name depends on user profile field.

How to use:

  1. Copy plugin into /moodle/auth directory
  2. Go to Site administration - Notifications page and install it
  3. Go to Plugins - Authentication and enable plugin
  4. Configure main rules (template for cohort name)
    second rule (replace empty field)
    and replacement array
  5. Enable unenrol option

Cohorts are created in CONTEXT_SYSTEM

See for details


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 (When field is empty this value used) 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 (1 replacement per line, old_value|new_value)

In our case: none - admin|Administrator


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


Screenshot #0
Screenshot #1
Screenshot #2


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

Comments RSS

Show comments
  • Floyd Saner - Tail of the Dragon, U.S. 129, NC
    Thu, Jul 17, 2014, 9:52 AM
    Also looking for a Moodle 2.7 version
  • Picture of Daniel Dubbeldam
    Mon, Aug 4, 2014, 5:09 PM
    okay. So I have this plugin working on Moodle 2.7.
    however, for now, i'm stuk with the following:

    I want to give people the option, to use checkboxes as customprofilefield.
    1 have to options: option1 and option2.

    my main template lines are

    even when just 1 checkbox is checked, student comes into 2 cohorts....
    what do I miss here? since checkboxes returns 0's and 1's... where should I add the "1" ?
  • Picture of Andrew C
    Thu, Aug 7, 2014, 9:26 PM
    Hi Andrew, in the php log of Moodle 2.6, I get the following PHP Warning: Creating default object from empty value in www\auth\mcae\auth.php on line 314. Although the warning presents no problem that I can see, would the following being added before 314 work to remove the warning?
    if (!isset($SESSION))
    $SESSION= new stdClass();
    Thanks, Andrew
  • Picture of Andrew Kama
    Sun, Aug 10, 2014, 10:13 PM
    Hi, Andrew. To remove the warning update plugin from github.
  • Picture of Francis Vendrell
    Wed, Aug 20, 2014, 2:50 PM
    Is this plugin compatible with Moodle 2.6 ?
  • Picture of Nathan Bruley
    Tue, Sep 9, 2014, 3:33 AM
    @Francis Seems to work in 2.6

    Does anyone know if it's possible to manually add people to a cohort created with this plugin? I'd like to add previous users that joined before adding the plugin who may not sign in.
  • Picture of Kyla Lacey-Davidson
    Wed, Nov 12, 2014, 7:52 PM
    We use this on our site to enrol staff and volunteers into different cohorts. We also enrol all of our staff and volunteers into cohorts based on which Directorate they work in. It would be great if you were able to enrol people into cohorts based on more than one condition. For example, 'Volunteer' in our Licence field AND Fundraising in our Directorate field. Is there any scope to develop this?
  • Picture of Annalise Duca
    Sat, Nov 15, 2014, 12:37 AM
    Not sure if I am using this plugin correctly. But what I would like to do is very simple. I would like to add those people who choose EN in a Cohort named English, those who choose Italian in a cohort named italian. I did many different versions but don't seem to be working correctly - the user is still going to both cohorts. What is wrong.


    New Registered EN %split(%language|,0 )
    New Registered IT %split(%language|,1 )

    What is wrong?
  • Picture of Blair A
    Sun, Feb 1, 2015, 10:01 PM
    If you add the hook for email registration to your theme in 2.6+, the loginas functionality will break. I added the following to the hook function in auth.php to ignore admins logged in as students.

    if (\core\session\manager::is_loggedinas()) {
    $SESSION->mcautoenrolled = TRUE;
    return true;
  • Picture of Deepak G
    Wed, Feb 18, 2015, 1:21 PM
    Hi there,

    Can you send a welcome message once a user is enrolled in a cohort and that cohort is enrolled in a course?
  • Picture of Chris Simpson
    Mon, Apr 20, 2015, 1:45 PM
    It worked great up to 2.7 but now wont function with 2.8. Is there any chance of an update??
  • Picture of Paul Perger
    Mon, May 4, 2015, 5:06 AM
    Yes, please, please udate! I love this plugin, it made things so much easier for me!
  • I sell cookies
    Sun, May 10, 2015, 2:04 AM
    I'd also love to see a 2.8 version - or even better, a 2.9 version. Can anyone share their updates if you've done this?
  • Picture of Dave Feasey
    Fri, May 29, 2015, 2:22 AM
    I would like (as with Kevin Treussier) to be able to use an enumerated list in a single field to separate users into multiple cohorts. For example user with a user field "isATP;isPartner" should go into two cohorts isATP and isPartner. I can't figure out how to define the separator and make this work.

    Using version 1.2 of the plugin (2014121815 1.2) with Moodle 2.8.3+ (Build: 20150219) Version 2014111003.03

  • Floyd Saner - Tail of the Dragon, U.S. 129, NC
    Thu, Aug 13, 2015, 5:05 AM
    I installed the latest GitHub pull on Moodle 2.8. The plugin works OK for standard accounts. I tried to use the plugin with email-based registration, but as documented in the readme file, extra code needs to be added. The problem is that the new Moodle Themes do not have a /layout/general.php or /layout/default.php file. Where should I insert the code? When will this plugin be updated for Moodle 2.8?
1 2 3 4
Please login to post comments