Access codes enrolment

From MoodleDocs

Access codes enrolment is a method that allows admins to create multiple access codes that users can use to enrol themselves onto a course. Each access code can be used only once. The enrolment plugin needs to be installed and enabled by the site admin in Enrolment plugins and has to be enabled within the course.

Enabling access codes enrolment in a site

  1. In site administration, click the Plugins link from the navigation
  2. Click Manage enrol plugins under the Enrolments heading
  3. Open the "eye" icon next to the Access code enrolment method

Enabling access codes enrolment in a course

  1. In your course, click the Participants link from Course navigation
  2. From the dropdown, select Enrolment methods
  3. Open the "eye" icon next to the Access code enrolment method.


The following settings may be changed by clicking the edit (hand/pen) icon to the right of the Access code enrolment option in Administration > Course administration > Users > Enrolment methods:

Setting the enrolment period

Tick the "enable" box to the right of the Enrolment period and then choose your dates. This setting can be overridden at the codeset level.

Enrolment duration

Set the amount of time a user enrolment is valid, starting with the moment the user enrols themselves, if disabled, the enrolment duration will be unlimited. This setting can be overridden at the codeset level.

Notifying users when their enrolment expires

It is possible for students and/or teachers to be notified when enrolments expire by selecting either "Enroller only" or "Enroller and enrolled user" from the dropdown "Notify before enrolment expires" and a time in "Notification threshold".

If there is more than one user with the role of teacher, then the notification is only sent to the first user to be assigned the role of teacher (or other user with the capability to manage access code enrolment).

Editing individual enrolment times

It is possible to edit the date and hour of an individual's enrolment from Administration>Course administration>Users>Enrolled users by clicking the edit icon in the enrolment methods column for the user in question. This then brings up a screen where the date and time can be modified.

Unenrolling students who haven't been active on the course

Choose from the dropdown to the right of "Unenrol inactive after..."

Deciding the maximum number of users in your course

Type the maximum number of users you want in your course in "Max enrolled users". When this limit is reached, nobody will be able to enrol using an access code. If you leave the number at 0 then there will be no maximum number.

Allowing only cohort members to enrol

If you have cohorts set up, then you can restrict access code enrolment to particular cohorts by selecting the name of the cohort from the drop down box, A member of the cohort can enrol as normal (as long as they have a valid access code); whereas a non-member gets a message telling them they are not able to enrol.

Course welcome message

If enabled, users receive the following course welcome message via email when they enrol in a course using an access code:

Hi {$a->firstname}, you are enrolled in the course {$a->coursename}.

You can edit the text and change it as you wish. The following placeholders may be included in the message:

  • Course name {$a->coursename}
  • Link to course page {$a->courselink} (new in 5.0)
  • Link to user's profile page {$a->profileurl}
  • User email {$a->email}
  • User fullname {$a->fullname}
  • User first name {$a->firstname}
  • User last name {$a->lastname}
  • User course role {$a->courserole}

The welcome message may be sent from the course contact, or from the default no-reply address. If the course contact is chosen, and there is more than one user with the role, then the welcome message is sent from the first user to be assigned the role of course contact.

Note: An admin can customise the message for the whole site by editing the welcometocoursetext language string. See Language customisation for further details. However, if the welcometocoursetext language string is used, only the placeholders coursename and profileurl may be used.

Admin settings

The access code enrolment plugin may be enabled or disabled throughout the site in Administration > Site administration > Plugins > Enrolments > Manage enrol plugins.

Shared settings for all courses

The page Administration > Site administration > Plugins > Enrolments > Access code enrolment. contains options for defaults that admin can set:

  • Enrolment expiry action - specifies what happens when user enrolments reach expiration date. Please note that option "Unenrol user from course" purges grades, group memberships, preferences and other user related data from the courses.
  • Hour to send enrolment expiry notifications - specify hour for sending expiration notifications.

Default enrolment settings in new courses

These can be set in Administration > Site administration > Plugins > Enrolments > Access code enrolment but teachers in individual courses can alter them to suit their needs:

  • Add instance to new courses - if admin selects this, then any new course created will include the access code enrolment plugin.
  • Allow existing enrolments - if disabled all users enrolled via this method can not access course..
  • Allow new enrolments - if this is enabled then new users can enrol themselves with this method.
  • Default role assignment - normally, when users enrol, they have the student role. If necessary that role can be changed by default here - for example - if your Moodle has a dedicated role you wish to use instead.
  • Enrolment duration - this sets the default enrolment length for new courses (but again, may be altered by the course teacher or overridden at codeset level.)
  • Notify before enrolment expires - specifies if teacher or optionally students should be notified before the expiration.
  • Notification threshold - specify how many days should be users notified before the enrolment expiration.
  • Unenrol inactive after- this sets the default time after which a student will be unenrolled if they haven't accessed the courses. (Teachers may change this).
  • Max enrolled users - adding a number here will specify the maximum number of users who can enrol into new courses using this method. Teachers in the course can change this. If it is left at 0, there will be no maximum.
  • Send course welcome message - if this box is checked then newly enrolled users will receive a welcome message by default.

Access code enrolment method options

One course may contain multiple access code enrolment methods. Users may be enrolled once in each instance only.

  • Custom instance name - specify custom enrolment method name.
  • Enable existing enrolments - if disabled all users enrolled via this method can not access course.
  • Allow new enrolments - disable if you do not want to allow students to enrol using this method in the future.
  • Default assigned role - specify role to be assigned to users during enrolment, this can be changed manually after enrolment.
  • Enrolment duration - specify enrolment length, this can be manually changed after user enrolment.
  • Notify before enrolment expires - specifies if teacher or optionally students should be notified before the expiration.
  • Notification threshold - specify how many days should be users notified before the enrolment expiration.
  • Unenrol inactive after- specify time after which a student will be unenrolled if they haven't accessed the courses.
  • Max enrolled users - adding a number here will specify the maximum number of users who can enrol into this course using this method.
  • Only cohort members - optionally restrict this enrolment method to members of specified cohort.
  • Send course welcome message- if this box is checked then newly enrolled users will receive a welcome message by default.
  • Custom welcome message - specify custom message if necessary.

Managing codesets

Access codes are contained within a Codeset. To manage codesets navigate to Site administration > Courses > Manage access codes.

Existing codesets will be listed here, by default only codesets you have created will be displayed, if you have the enrol/accesscodes:manageallcodes capability you can toggle Show all on to show codesets created by all users.

Create a new codeset

Navigate to Site administration > Courses > Manage access codes and click Create codeset.

  • Codeset name - The name of your codeset.
  • All courses - Select Yes if codes in this codeset should work for all courses with the enrolment method enabled.
  • Valid course - If All courses is set to No, select the courses for which codes in this codeset are valid. Note, only courses with this enrolment method enabled can be selected here.
  • Expiry date - If enabled, access codes in this codeset can only be used before the date set.
  • Enrolment duration - In enabled, enrolments created with a code in this codeset will have the duration set here, this setting overrides the course level enrolment duration.
  • Number of codes - The number of codes to be generated. Note, number of codes in a codeset can't be reduced once created, but they can be increased.

View codes

Navigate to Site administration > Courses > Manage access codes and click View codes next to the correct codeset. From here you can see which codes have been used and for which courses, you can also download a .csv of the codes for easy distribution.