Moodle local plugins for site-specific customisation

Local plugins let an organisation add its own Moodle behaviour through events, scheduled tasks and admin pages while core stays untouched. This page covers when that is the right tool and what keeps it upgrade-safe.

On this page

When a Moodle local plugin is the right place for site-specific behaviour

When a team needs a rule Moodle does not ship, such as a nightly report, a sync step with the HR system or a check that runs when a course is completed, a Moodle local plugin is usually the right home for it. The local plugin type exists for organization-specific code that sits outside core and outside the theme, so it can carry that behavior without edits to Moodle's own files. Moodle documents more than 50 plugin types in its developer docs, and the plugin types reference is the place to confirm which type a given feature belongs to before any code is written.

A local plugin is good at logic and administration: event observers that react to user or course events, scheduled tasks, admin pages and settings, and small integration points. It is not the place for markup changes, which belong in a theme, and it is not a substitute for a new activity type, which needs its own module structure with gradebook, backup and privacy support. If the rule must be callable by an external system, the right answer is usually a web service function on top of the same logic, so confirm with the integration owner whether the consumer needs an API or only a scheduled job. Ask your developers to write down the reason for each choice in the plugin's documentation so the next maintainer can see why it is not a theme or module.

Which mechanism fits which site-specific requirement

This table compares the main ways a local plugin changes Moodle behaviour: event observers, scheduled tasks, admin pages and settings, and custom pages with lib callbacks, plus the cases where a block, theme override or web service function fits better. Read each row against the requirement you have, then check the upgrade and testing columns before choosing a mechanism.

MechanismBest fit and triggerUpgrade and testing effort
Event observerReacts to a Moodle event such as course completion or user creation, with no user action needed to runLow to moderate. Depends on the event names and fields used, so check them on each Moodle release and test with real event data
Scheduled taskRuns on a timetable through cron, for syncs, reminders or clean-up jobs that are not tied to one user actionModerate. Needs test runs under cron, checks of run frequency and locking, and a review of the logs after each upgrade
Admin page and settingsGives administrators a place to set site-specific values, such as API endpoints or policy switches, without code editsLow. Uses the admin settings API, so review settings pages after upgrades and confirm each setting still saves
Custom page with lib callbacksAdds a new page or hooks into core features through callback functions in lib.php, for narrow behaviour that observers cannot reachHigher. Callbacks depend on core signatures that can change, so review every callback in the upgrade test plan
Block pluginShows site-specific content in page regions, such as a status panel or a personal summaryModerate. Blocks depend on page layouts and rendering, so check them on each theme change and layout update
Theme template overrideChanges markup or wording in a page the user sees, without changing behaviour or dataModerate. Overrides must be tracked when core templates change, so confirm each one during every upgrade
Web service functionExposes or accepts data for an external system through the External API, with capability checks and parameter validationModerate. Function definitions and service lists must be re-tested, and consumers need notice of any change
ReversibilityObservers, tasks and settings can usually be disabled without data loss, while schema changes and stored data are much harder to undoAsk the developer to state exactly which data each mechanism writes and how to roll it back before go-live

How to build and roll out a local plugin safely

This sequence takes a site-specific requirement from a written need to a tested local plugin running in production with a tested way back. Each step closes with a check, so the team knows when to move on and when to stop. The output is a plugin that sits outside core, can be upgraded with the platform, and can be removed without leaving data or behaviour behind.

  1. Confirm the requirement and existing options

    Write down the business behaviour the site needs, who triggers it, and what data it reads or writes. Search the Moodle plugins directory and the core settings and reports for an existing answer, and check whether an existing plugin of a different type already covers the need. The step is done when the team can state in one sentence why no existing core setting or directory plugin meets the requirement, and the owner has signed that decision.

  2. Choose the Moodle, PHP and database targets

    Pick the Moodle version the site runs or will move to, then confirm the PHP and database versions that release requires. Check the release notes for the target version, since requirements change between releases, and confirm that the plugin's supported versions include that target. The check is a written matrix of Moodle, PHP and database versions that the plugin will be built and tested against, approved by the platform owner.

  3. Scaffold the plugin with version.php and language strings

    Create the plugin folder in the correct plugin type location, with a version.php file that declares the component name, plugin version and the minimum Moodle version it requires. Add a language file for every user-facing string so wording can change without code edits. The check is that Moodle detects the plugin on the Site administration upgrade screen and installs it cleanly on a development copy, with no undefined string errors.

  4. Add event observers and scheduled tasks

    Register event observers in the events file for the Moodle events the behaviour depends on, and keep each observer short so it calls a class with testable logic. Define any scheduled tasks in the tasks file with a clear schedule, and make each task safe to run twice. The check is that triggering each event on the development copy runs the expected handler once, and that a manual run of each task produces the logged result the requirement describes.

  5. Add settings, admin pages and capabilities

    Declare site-level settings in the settings file and any admin pages the site administrators need, and define capabilities in the access file with sensible default roles. Only grant the capabilities the requirement needs, and check every page and external call against them. The check is a role test: a user without the capability cannot view the page, change the setting or trigger the behaviour, and a user with it can, both confirmed on the development copy.

  6. Test on a staging copy with a database backup

    Restore a recent copy of the production database and moodledata to a staging environment that matches production's Moodle, PHP and database versions. Take a database backup of staging before the plugin is installed, then install the plugin, run the upgrade and exercise the main flows with realistic test accounts. The check is a written test log covering install, upgrade, each event and task, permissions and uninstall, with the staging backup kept so the test can be repeated.

  7. Deploy with a rollback path

    Deploy the code to production during an agreed change window, after taking a full database and moodledata backup and noting the previous plugin version. Verify the upgrade completes, check the Moodle logs and the scheduled task log, and confirm the behaviour on a test account. The rollback path is a documented procedure for restoring the code and the database backup, rehearsed on staging, and the step closes when the team can show the restored state works before they call the deployment finished.

Security and operational risks of custom local code

A local plugin runs with the same privileges as Moodle core, so a weakness in it can expose the whole site. The risks below cover access control, data integrity, failure handling, secrets and review, and each one has a mitigation you can check before a plugin reaches production.

Missing capability checks on admin pages

An admin page that renders without a capability check, or that checks only the site admin role, can be reached by users who should not see it, often by typing the URL directly. Every page should call require_login and require_capability in the context that owns the data, and every action should verify sesskey through the form or confirm mechanism. Ask for a test that logs in as a user without the capability and confirms a direct request is refused.

Unvalidated input reaching queries and output

Form values, URL parameters and web service arguments should be declared with the required_param or optional_param helpers using the correct PARAM_ type, then passed to $DB with placeholders. Output built in templates should go through Moodle's escaping so that a value entered by one user cannot run script in another user's browser. Review any string concatenation into SQL and any raw use of $_POST or $_GET.

Direct database writes that skip APIs

Writing straight to tables with $DB->update_record or raw SQL bypasses the events, grade updates, cache resets and logging that core functions trigger. The result is data that looks correct in one table while the gradebook, completion or audit trail disagrees with it. Where a core API exists, such as enrol, grade or user update functions, the plugin should use it, and direct writes should be documented and justified in review.

Scheduled task failures that go unnoticed

A scheduled task that throws an exception may fail on every cron run without any visible change to users, so an integration can stop syncing for weeks. Tasks should catch expected errors, return clear status, use mtrace for progress, and set sensible timeouts for external calls. Ask who receives alerts when a task fails and how the site checks the task's last run time in the scheduled tasks report.

Secrets stored in plugin settings

Plugin settings are stored in the configuration tables and are visible to anyone with access to the database or config backups, so API keys and passwords entered as plain text settings are a common exposure. Prefer external secret stores or environment variables read at runtime, mark sensitive settings clearly, and check that they do not appear in logs, exported backups or support bundles. Confirm that no secret is hardcoded in the repository.

Code review and logging before production

Local code should pass a peer review that covers the capability, input, database and secrets points above, and a tested upgrade path before deployment. Logging should record who changed a setting or triggered an integration action, without writing personal data or secrets into the log. Ask for the review checklist, the named reviewer and the record of the Moodle version the code was tested against.

Latest LTS version
5.3

Keeping local plugins upgrade-safe across Moodle releases

A local plugin stays upgrade-safe only if it depends on Moodle's published APIs and is tested against each target release before production. Moodle changes internal functions, renderer classes, database helpers and JavaScript modules between major releases, so code copied from core or called through undocumented internals is the usual reason a customisation breaks during an upgrade. Use the supported entry points instead: the Moodle core APIs for database access ($DB), events and observers, the Task API for scheduled tasks, the Settings API and admin pages, and the Output API for any templates. Each of these is documented in the developer docs, and a plugin that uses only these surfaces has far fewer places to fail when core moves.

Every local plugin declares its requirements in version.php, and those declarations are the first thing to check on each upgrade. The $plugin->requires value sets the minimum Moodle version, and $plugin->component and $plugin->version must match the install record. Moodle 5.1 requires 64-bit PHP 8.2 or later (8.3 and 8.4 are supported) and PostgreSQL 15, MySQL 8.4, MariaDB 10.11 or Microsoft SQL Server 2017 or later. Moodle 5.3 raises the floor to 64-bit PHP 8.3 or later (8.4 supported), PostgreSQL 17, MariaDB 11.4 and SQL Server 2019 or later. A plugin tested only on the older stack can fail on the newer one, so run your test suite against the full target matrix, not just the Moodle version. From Moodle 5.1 the web server document root must point to /public, which is an environment change, not a plugin change, but it belongs in the same upgrade test plan. Confirm the exact requirements with the release notes for your target before you pin anything.

Pin the plugin to a tested release and treat deprecations as work items, not warnings. Read the deprecation notices for the target release, search the plugin for every deprecated call, and run the Moodle code checker and PHPUnit or Behat tests against the target branch in a staging copy built from a production backup. Record which Moodle version each plugin release was tested on, and keep the plugin's source in your own version control so a rollback is a checkout, not a rebuild. Ask anyone who maintains the plugin for the Moodle versions they test against, and plan the work to remove any deprecated call before the release that removes it, because the removal date is set by Moodle, not by your project.

Limits to confirm before writing a local plugin

A local plugin is cheap to start and expensive to keep if the target release, server stack or hosting setup does not fit. The items below are the checks to finish before any code is written, because each one can change the design or rule out the plan.

Moodle version and support window

Confirm which Moodle release your site runs now and which release it will move to, then check how long that release receives general and security support. A local plugin written for a release that leaves support during your project means a second upgrade cycle. Current supported releases include 5.1, which has security support until 19 April 2027, and 5.2, which has security support until 4 October 2027. Confirm the dates on the releases page before you set the target version.

Moodle releases

PHP and database for the target release

Each Moodle release sets its own minimum PHP and database versions, and a local plugin can only use what the target release accepts. Check the 5.1 and 5.3 requirements for PHP, PostgreSQL, MySQL, MariaDB and SQL Server against your current servers. If your target is 5.3, confirm whether your site must first move to Moodle 4.4 or later to upgrade. Ask your platform team which of these versions they can actually deploy.

Moodle 5.3 release notes

Existing plugins that already cover the need

Before writing code, search the plugins directory and the core features for a plugin that already does the job. Many site-specific needs such as enrolment sync, notifications or reporting already have maintained options. A custom local plugin then becomes a maintenance commitment that you own indefinitely. Record which plugins you checked, their supported versions and their last maintenance activity, so the decision can be reviewed later.

Hosting limits on cron and tasks

Scheduled tasks and event-driven logic depend on how your hosting runs Moodle's cron. Confirm that the server or container can run cron at the interval the task needs, that a single cron run can finish within your timeouts, and that someone monitors failed runs. Shared or serverless hosting often restricts background processes, which can rule out a design before it starts. Ask your operations team who owns cron in production.

Privacy API declaration

Find out whether the plugin stores, reads or exports personal data. If it does, it needs a privacy API provider so that Moodle's data request and deletion tools can include its records. Decide this early, because it defines which tables the plugin writes and how they are linked to users. Your compliance lead should confirm whether the data is in scope for your privacy process before the schema is fixed.

Questions buyers ask about Moodle local plugin work

What drives the cost of a Moodle local plugin?

The cost follows the number of behaviours the plugin must add, how many Moodle systems it touches, and how much testing the site needs before go-live. A plugin that only adds an admin settings page costs far less to build than one that reacts to course events, calls an HR system, and writes to the gradebook. Ask any quote to break the work into design, build, test, documentation and handover, and to state which parts are one-time and which recur, such as upgrade testing for each Moodle release. Also ask who pays for the staging site, test data and any third-party API access, because those costs are often left out of a build estimate.

How long does a local plugin build and test cycle take?

Duration depends on scope: the number of events observed, scheduled tasks, settings pages and external systems involved, along with how many test rounds your stakeholders need. A small, well-defined plugin with one observer and one settings page moves through build and test faster than a plugin that changes enrolment or grading logic. No duration figure is given here because it depends on your requirements. Ask the partner to show the phases, the review points and the test exit criteria in the written scope before work starts, and to confirm how many staging test cycles are included.

What must our team provide before a local plugin build starts?

Three inputs matter most: written requirements, representative test data, and a staging site that matches production closely enough to test real behaviour. Requirements should name each trigger, such as a course completion or user creation event, what the plugin must do in response, and what must never change. Test data should include edge cases like users with multiple roles, suspended accounts and courses in hidden categories. The staging site should run the same Moodle version, database engine, PHP version and authentication setup as production. Confirm early who owns each input and who signs off the requirements.

Can an internal developer maintain a Moodle local plugin?

Yes, if the developer knows PHP, Moodle's plugin APIs and the Moodle upgrade process, and if the code is documented and covered by tests. The harder part is ongoing ownership: someone must review each new Moodle release, run the plugin's tests, and fix anything that depends on a changed API. Before handover, confirm that the internal team can read the event observers, scheduled tasks and settings code, that the plugin has a clear owner, and that the upgrade test steps are written down. If no one on the team has that skill set, a retainer for upgrades and testing is a reasonable option to price alongside the build.

How are local plugins kept safe through Moodle upgrades?

A local plugin stays upgrade-safe when it uses Moodle's documented extension points, such as event observers, scheduled tasks, admin settings and the plugin's own database tables, rather than editing core files. Each Moodle release should be tested on staging with the plugin enabled before production is upgraded. Moodle 5.1 changes the web server document root to the new /public directory, so server configuration must be checked alongside the plugin. Moodle 5.3 requires newer PHP and database versions, so plugin code should be tested against those requirements too. Ask the partner to state the upgrade test checklist and how plugin version numbers are managed.

When should we use an existing plugin instead of building a local plugin?

Use an existing plugin when it covers the requirement with little or no code change, is actively maintained, supports your Moodle version and passes a security and privacy review. Build a local plugin when the behaviour is specific to your organisation, such as a rule tied to your HR codes or a custom admin report, or when no maintained plugin does the job safely. Before choosing, check the plugin's supported Moodle versions, maintainer activity, privacy API support and overlap with core features. Vetting a third-party plugin is a separate task that should be scoped and priced on its own.

Does a local plugin change how Moodle is secured or audited?

Yes. Every local plugin adds code that runs with Moodle's privileges, so it becomes part of your attack surface and your change record. Its capability checks, input handling and database queries should be reviewed like any other code, and its settings should not expose secrets in plain text. Keep the plugin in version control, record which Moodle version it was tested against, and document what data it reads and writes so your compliance and security teams can review it. DeployOpen can test the security of a deployed Moodle site and prepare evidence for a compliance assessment, but independent auditors issue any audit report.

How DeployOpen scopes and delivers Moodle local plugins

DeployOpen approaches site-specific Moodle behaviour as a written, fixed-scope build that lives in a local plugin and leaves core untouched. We scope the observers, scheduled tasks and admin pages with your team, build them in your infrastructure, and hand over documentation and an upgrade check so the customisation survives future Moodle releases.

How we scope

  • Map each required behaviour to a trigger: an event observer, a scheduled task, an admin page or a setting.
  • Confirm which Moodle version and PHP and database stack the plugin must support before design starts.
  • Agree the written scope, deliverables and timeline in writing before any build work begins.

How we build

  • Create the local plugin with a version.php, capability definitions and language strings, kept separate from core code.
  • Test observers and scheduled tasks on a staging copy of your production data, with logs reviewed for each run.
  • Run the plugin through a Moodle upgrade rehearsal on staging before anything reaches production.

How we hand over

  • Deliver the source in your version control, with install, configuration and rollback steps written for your operations team.
  • Document each event, task and setting so administrators know what the plugin changes and why.
  • Walk your engineers through the upgrade checklist for the plugin, including the tests to rerun after each Moodle release.

How we support

  • Offer ongoing support, upgrades and continuous testing for the plugin as a retainer, if your team wants it.
  • Recheck the plugin against each Moodle minor release and the next major release you plan to adopt.
  • Confirm with your team what support window, response expectations and change process apply before signing.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.