Mastering Moodle Conditional Access: A Practical Guide for Course Designers
Learn how to enable, configure, and verify Moodle’s Conditional Access feature. This guide covers UI steps, a PHP API example, common pitfalls, and performance limits for adaptive course design.
24 Dec 2025, 23:30 UTC

What Conditional Access Does
Conditional Access in Moodle lets you hide or show an activity until a student satisfies a specific criterion – such as finishing another activity, achieving a grade threshold, or waiting until a certain date. The key benefit is that the course structure can adapt to each learner’s progress without manual intervention.
Enabling the Feature in the UI
1. Edit the target activity or resource.
2. In the right‑hand pane, click Conditional Access.
3. Click Add a rule and choose a rule type (e.g., Course completion, Grade, Time window).
4. Configure the rule parameters – for a course‑completion rule you’d set Required completion status: Completed and optionally Completion method: Automatic.
5. Save the activity. The activity will now appear as hidden until the rule is met.
Rule Logic: AND vs OR
When you add multiple rules, Moodle applies them with an AND logic by default – all rules must be satisfied. If you need an OR relationship, use the Rule group feature to combine rules.
Behind the Scenes: The PHP API
For developers who want to automate rule creation or integrate Conditional Access into custom plugins, Moodle provides a lightweight API. Below is a minimal example that applies a course‑completion rule to an existing activity.
// Assume $activityid is the ID of the activity module.
$access = new \core\access\conditional_access();
$access->set_rule('completion', [
'required' => true,
'method' => 'automatic',
]);
$access->apply_to_activity($activityid);
Place this code in a plugin’s lib.php or a custom script that runs with admin privileges. The apply_to_activity() method writes the rule into mdl_conditional_access and updates the activity’s visible flag.
Verification Steps
- Course View Test: Log in as a student, navigate to the course page, and confirm the activity is hidden. Complete the prerequisite activity and verify the hidden activity becomes visible.
- Show Hidden Toggle: In the course page, enable the Show hidden switch. The activity should appear regardless of rule status, confirming the rule is in place.
- Database Check:
- Query
mdl_course_modulesfor thevisibleflag – it should be0until the rule is satisfied. - Query
mdl_conditional_accessfor entries linked to the activity ID to inspect rule details.
- Query
- Debugging Log: Enable Moodle’s debugging mode (Site Administration → Development → Debugging). Look for messages like
Conditional access rule not satisfiedwhen the activity is accessed prematurely.
Common Pitfalls and How to Avoid Them
- Forgot to Enable Completion Tracking: Conditional Access rules that rely on activity completion will fail if the activity itself isn’t set to track completion. In the activity settings, enable Completion tracking and set the completion method.
- Hidden Loop: If Activity A requires completion of Activity B, and Activity B requires completion of Activity A, both will remain hidden. Carefully review dependencies and avoid circular references.
- Overusing Rules: Each rule adds a check on page load. Courses with dozens of Conditional Access rules can experience slower page rendering. Profile the course and consider consolidating rules where possible.
- Visibility Flag Misconfiguration: The activity must be marked as visible in the course format; otherwise, Conditional Access will not override it. In the course format, ensure the
visibleflag is set to1before applying the rule. - Rule Logic Confusion: When adding multiple rules, remember the default AND logic. If you intended an OR, group rules accordingly.
Limitations of Conditional Access
- Only applies to activities that support visibility toggling. Some legacy activities or custom modules may not honor the
visibleflag. - Cannot control navigation flow or hide entire sections of a course format. For that, consider using Course sections visibility settings.
- Complex rule combinations can increase database load and may not be evaluated efficiently on very large courses.
- Conditional Access rules are not inherited by child courses or copied modules; they need to be re‑created when duplicating content.
Practical Checklist Before Deploying
- Verify that all prerequisite activities have completion tracking enabled.
- Test the rule with a student account to ensure the activity remains hidden until the condition is met.
- Check the
visibleflag inmdl_course_modulesafter rule application. - Monitor course performance after adding several rules.
- Document each rule in the course syllabus so learners know what to expect.
Conclusion
Conditional Access is a powerful tool for adaptive learning paths in Moodle. By following the UI steps or leveraging the PHP API, course designers can create responsive courses that reveal content only when students are ready. Always validate the rules, watch for hidden loops, and keep an eye on performance to maintain a smooth learning experience.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.