When Moodle plugin development is the right answer
A custom Moodle plugin is justified only when the behavior you need cannot be met by core configuration or by a contributed plugin that you have checked and rejected. If you are reading this, your site probably needs something core and the existing plugins do not provide, such as a course activity with your own grading logic, a block that pulls data from an internal system, or a report that your compliance team has asked for. Before writing code, document the requirement, test the settings in core, and search the Moodle plugins directory for an existing solution. Each rejected option should have a written reason, because that record is what a future reviewer will ask for.
Plugins are harder to keep working than they look. Moodle ships a new major release every six months, and each release can change the PHP and database floors, so a plugin that runs on today's site may block an upgrade next year. Moodle 5.1 also moved the web server document root to the /public directory, which affects how plugin files and web entry points are reached, so your deployment and any path assumptions in your code need checking at every upgrade. Confirm the current requirements in the Moodle 5.1 release notes and the Moodle 5.3 release notes before you choose a target version.
Moodle core is licensed under GPL-3.0, so plugins you distribute must be released under a license compatible with it. Ownership and licensing should be settled before the build starts, including who holds the code if the plugin is later shared with other institutions. The real cost is maintenance: a plugin needs a named owner, a test suite that runs against each supported Moodle version, and a plan for each six-monthly release. Ask any partner to price that ongoing work as part of the scope, not only the first build.
Which Moodle plugin types cover common extension needs
Moodle documents more than 50 plugin types, and each one has its own API, install location and upgrade behavior. The six types below cover most custom requirements, and the right choice usually depends on where the feature must appear and who uses it.
Activity modules
An activity module adds a new activity type that teachers place inside courses, such as a custom assessment or a structured submission workflow. It stores its own data, handles grading and backup and restore, and must implement the course module APIs correctly or it will break course copy and migration. Check how grades and completion are reported back to the gradebook before you commit to this type.
Plugin types docsBlock plugins
A block is a small component placed in course or dashboard sidebars, often used for progress summaries, announcements or quick links. Blocks are lightweight, but their visibility and configuration depend on page context and capabilities, so test them with each role. Confirm how the block behaves on the dashboard and inside courses for every role you support.
Local plugins
Local plugins are the general-purpose home for site-specific code that does not fit another type, such as custom pages, scheduled logic or integration endpoints. Because they have no fixed page structure, they are the easiest place to drift away from core APIs. Keep business logic behind core functions and document every hook you rely on.
Report plugins
A report plugin builds an analytical view over course, user, grade or log data for administrators or teachers. Reports depend heavily on database queries, so review them for performance on large tables and for capability checks that prevent data exposure. Confirm that queries use the core database API and that the report respects course and category permissions.
Enrolment plugins
Enrolment plugins decide how users join courses, for example through an HR feed, a payment flow or a code-based self-enrolment. They control role assignment and enrolment end dates, which makes them sensitive to data accuracy and to deprovisioning. Test suspension and removal paths as carefully as enrolment, because those paths drive access control.
Admin tools
Admin tools are administrative utilities that run under the site administration area, such as data cleanup, bulk operations or compliance exports. They carry high risk because they can change data at scale, so restrict them to the right capabilities and log every action. Themes and authentication plugins are separate concerns with their own guidance, so check those references before choosing a type.
Decisions to settle before writing code
This table compares the four decisions a team faces before a Moodle plugin build starts: plugin type, custom build versus a contributed plugin, release targeting, and external web services. Read each row for when the option fits and what it costs to run afterward, since most of the long-term cost comes from maintenance and testing rather than the first build.
| Decision | When it fits | Operational cost to plan for |
|---|---|---|
| Plugin type: activity module | Learners complete a new kind of graded or tracked task inside a course | Module must follow the activity API, gradebook and completion hooks, so each upgrade needs regression tests across those paths |
| Plugin type: block or local | A dashboard element, course widget or site-level feature that does not need its own course activity | Blocks are tied to page layouts and themes, so theme changes can break rendering; local plugins often hold custom pages that need their own access checks |
| Plugin type: report or admin tool | Staff need data extracts, audits or maintenance tasks that sit outside the learning flow | Reports read large tables, so query cost and privacy review grow with the data they expose |
| Plugin type: enrolment or authentication | Users or enrolments must come from an external source such as an HR or student system | Ongoing sync jobs, error handling and deprovisioning rules must be owned and monitored by someone |
| Custom build versus contributed plugin plus configuration | Configuration alone cannot meet the requirement, or a maintained plugin already does most of the job | Custom code adds a permanent upgrade and security patch burden; contributed plugins add dependence on a third-party maintainer's release timing |
| Target a single release or LTS lines | Site is pinned to one version for a defined period, or must run on the current major | Each targeted release line adds a test environment and a compatibility check at every six-monthly major release; confirm the supported lines in the Moodle releases page |
| Need for external web services | Other systems must read or write Moodle data, or a mobile or external app is involved | Service tokens, scopes and endpoint versions must be managed, and every exposed function becomes part of the security review scope |
| Source and dependency control | Code will be maintained by a team other than the author | Requires documented coding standards, code review, automated tests and a packaged release process so later maintainers can work safely |
How to build a Moodle plugin in sequence
This sequence takes a plugin from a written requirement to a package that installs cleanly and upgrades predictably. Each step closes with a check, so problems surface while they are still cheap to fix.
Define requirements and data ownership
The product owner and a Moodle developer write down what the plugin must do, which users and roles use it, and what data it creates, changes or reads from other parts of Moodle. Record which data lives in the plugin's own tables and which belongs to core or another plugin, along with how long it is kept. The step is done when the requirements list has an owner, each feature has a testable acceptance statement, and the data ownership table is agreed. Confirm the list with the client's privacy and records owners before any code is written.
Select the plugin type
Match the requirement to a plugin type. An activity module suits gradable or interactive course content, a block suits a dashboard element, a local plugin suits site-specific code that has no better home, a report plugin suits read-only analysis, and an enrolment plugin suits rules that grant course access. Moodle documents more than 50 plugin types, so check the official plugin types list before settling on one. The step closes when the choice is written down with the reason it fits and the reasons other types were rejected.
Scaffold the component with version and frankenstyle naming
Create the component directory under the correct type location, with a
version.phpfile that declares the component name, the plugin version, the minimum Moodle version it requires, and the maturity level. Use frankenstyle naming, where the component name is the plugin type prefix followed by an underscore and the plugin name, for example alocal_prefix for a local plugin. Confirm the name is unique in the plugins directory. The check is that Moodle detects the plugin on the admin notifications page without errors when it is copied into a development instance.Define the schema and install and upgrade scripts
Declare database tables in
db/install.xmland write the upgrade steps indb/upgrade.php, one block per version change, using the Moodle database API and the XMLDB editor rather than raw schema changes. Every schema change gets its own upgrade step with a version number that increases. The verification is twofold: install the plugin on a clean database that matches a supported Moodle and database combination, then install an earlier plugin version and run the upgrade to the new version. Both paths must finish without errors and leave the schema matchinginstall.xml.Implement capability checks and forms
Declare capabilities in
db/access.phpwith sensible default roles, then enforce them in every page, web service and callback withrequire_capabilityor context-aware checks. Build user input with the Moodle forms API so validation, CSRF protection and sesskey handling come from core. Use the output and templating APIs for rendering instead of concatenating HTML. The check is a role test: create a user for each role with and without each capability and confirm that every page and action grants or denies access as the requirements state.Add automated tests
Write PHPUnit tests for business logic and database interaction, and behat tests for the main user journeys such as creating an activity, submitting a form or viewing a report. Keep tests in the plugin's
testsdirectory so they travel with the code. Run the suite against the Moodle versions the plugin claims to support, since core API changes between releases can break tests silently. The step closes when the suite passes on each targeted version and the tests fail when a deliberately broken capability check is introduced.Run code review and security review
Have a second developer review the code against Moodle coding guidelines and the requirements list, checking the use of core APIs, input handling, output escaping, file upload controls, external API exposure and data retention. Run the Moodle code checker and PHP static analysis on the codebase. Record each finding, its fix and the retest result in the review log. The step is done when no open finding is rated as blocking and the reviewer signs the log. Plugins that touch personal data should also receive a review against the client's privacy requirements.
Package for distribution and document the upgrade path
Build a versioned archive that contains only the plugin code, with a changelog, install notes, the minimum and tested Moodle versions, and the license. Remove development files, test fixtures with real data and credentials. Install the packaged archive on a fresh site using the standard plugin installer and on a site running the previous package version, then record that both succeed. Document the upgrade path so the team that runs the site knows what to test before each Moodle major release, which keeps the plugin upgrade-safe across releases.
How a plugin moves from requirement to supported release
The path starts with a business requirement that is tested against configuration and contributed plugins before any code is written. If custom code is needed, the team picks the plugin type that matches the job, builds on core APIs rather than copying core internals, and runs automated tests. Before release, the plugin is code reviewed and upgrade tested against the previous Moodle version, then packaged. Maintenance continues for each new Moodle release, because the plugin is only as durable as its last compatibility check.
Decision and delivery path for a custom Moodle plugin, from requirement to maintenance.
How Moodle plugin development keeps code upgrade-safe
The most reliable way to keep a custom plugin working across releases is to build it on the APIs Moodle already provides, not on edits to core files or direct SQL against core tables. Where an API exists, use it: the database API ($DB) for queries, the forms API for input handling and validation, the output and renderer layer for HTML, the capability and role system for access control, the events system for reacting to user actions, and the privacy API for declaring and exporting or deleting personal data. These are the interfaces Moodle HQ maintains across releases, so a plugin that uses them has a much smaller surface that can change underneath it. Start by reading the plugin types documentation at Moodle plugin types to identify which APIs apply to your plugin type, whether it is an activity module, block, local, report or enrolment plugin. Then confirm how each API behaves in the specific release you are targeting, because the documentation is versioned and behavior changes between releases.
A plugin that edits core files, copies core code into its own folder, or queries undocumented internal tables will break on the next release that touches that code. Such breaks are often silent until a user hits the affected path, and they are not limited to rare releases. Moodle ships major releases every six months, in April and October, plus minor point releases on a bimonthly schedule, so every unsupported dependency on internals is exposed to change at a frequency that makes manual repair a standing cost. The practical decision for your team is to write down which core functions, classes and tables the plugin touches, mark any that are not part of a documented API, and either replace them with an API call or accept that they will need a fix before each upgrade. Ask the developer to show the list during code review.
Upgrade safety also depends on what happens before the upgrade. Run the plugin's automated tests and its install and upgrade paths against each target release on a staging copy, and include the privacy and capability checks in that run, not only the feature itself. Ask for a written record of the Moodle versions and PHP versions the plugin was tested on, and for the upgrade path from each prior version of the plugin, since a broken db/upgrade.php step can block a site from moving forward at all. Review the scope of any plugin that changes core behavior through observers or overrides, because those are the points most likely to conflict with a later core change. These checks are easier to schedule than to repair in production during an upgrade window.
What drives Moodle plugin development effort
This table lists the factors that most change how much work a custom Moodle plugin takes, from screen count to the number of Moodle releases you must support. Read each row as a lever: the middle column explains why it matters, and the right column shows how to keep it under control before the build starts.
| Driver | Why it changes effort | How to keep it down |
|---|---|---|
| User-facing screens | Each page needs capability checks, templates, forms, language strings and accessibility testing, so screen count scales the build and review work directly. | Limit version one to the screens that solve the core need, and reuse core forms, tables and renderers rather than building bespoke interfaces. |
| Data model complexity | New database tables, foreign keys, upgrade steps and backup or restore behavior all need design, and each schema change adds upgrade risk. | Store data in existing core tables where possible, use the Moodle database API, and keep custom tables to a small number of well-defined entities. |
| Integrations with external systems | Web services, scheduled syncs and API credentials add authentication, error handling, retries and monitoring that the plugin must own. | Confirm which system is the source of truth, prefer an existing enrolment or authentication plugin where one fits, and agree the data contract before coding. |
| Roles and capabilities | Each capability needs definitions, default role assignments, context checks and tests for every role that can reach the feature. | Reuse standard roles and existing capabilities, and define new capabilities only for actions that core cannot already express. |
| Supported Moodle releases and test matrix | Every supported major and minor release, plus each PHP and database combination, multiplies the regression and CI runs needed before release. | Narrow the supported range to the releases your organization runs, confirm the PHP and database versions per release in the release notes, and drop unsupported combinations early. |
| Plugin type and scope | Choosing an activity module, block, local plugin, report or enrolment plugin changes the APIs, lifecycle hooks and upgrade surface you depend on. | Pick the plugin type that matches the job and keep it to one type, adding a second only when a specific requirement forces it. |
| Accessibility and language requirements | Keyboard navigation, screen reader support, contrast checks and translatable strings all add design and test cycles, and each new language adds translation handling. | Build on core accessible components, use language string identifiers from the start, and agree the target languages and accessibility standard in writing. |
| Compliance evidence needed | Assessors may ask for code review records, test reports, change logs, vulnerability scans and documented access controls, which takes extra time to produce and keep current. | Ask early which evidence the assessor expects, set up CI test output and review sign-off as part of normal work, and keep documentation with the code. |
Security controls every custom plugin needs
Most Moodle plugin security problems come from code that skips a check the core framework would have made for it. The cards below cover the controls every custom plugin needs in its own code, whatever its type. Site-level controls such as web server configuration and administrator accounts are covered in the security hardening topic.
Capability checks on every action
Every page, form submission, web service function and AJAX endpoint must verify the user's capability in the right context, not just that they are logged in. Use require_login() and require_capability() with the course or system context, and check ownership of the record being changed. Review each entry point and ask whether a user with a lower role could reach it by changing a URL or request.
Parameter cleaning and output escaping
Read request input with required_param() or optional_param() and a declared type such as PARAM_INT or PARAM_TEXT, never with raw $_GET or $_POST. Escape everything printed through the templates and output renderers, and pass database values through placeholders in the Moodle database API. Check that no plugin builds SQL by concatenating user input.
File uploads through the file API
Store uploaded files with the core File API rather than writing to moodledata or the web root yourself. The File API keeps files in the correct context, applies access checks on download and avoids path traversal. Validate file types and sizes on the server, and confirm that the plugin never serves files directly from a path a user controls.
Safe external web services and tokens
Each web service function a plugin exposes should declare its parameters, required capabilities and the service it belongs to, so administrators can scope tokens. Treat token holders as privileged users, limit which functions each service allows and confirm that the function checks capabilities itself. Ask whether any endpoint accepts data without a logged-in user or token.
Plugin types docsSecrets kept out of code
API keys, client secrets and service passwords belong in site configuration or a secrets store, never in plugin source, version.php, default settings files or a public repository. Store them through the admin settings API as protected values, mask them in the interface and exclude config files from version control. Scan the repository history before publishing, since a removed key stays in old commits.
Vetting third-party code
Every library or bundled JavaScript package a plugin includes becomes part of your security surface and your upgrade burden. Record each dependency with its version and licence, check its maintenance status and known vulnerabilities, and prefer core APIs over copied code. Confirm the licence is compatible with the GPL-3.0 licence that Moodle core uses before shipping it.
How to test a plugin and confirm it fails safely
A plugin is ready for a client only when it passes several test layers, not just a happy-path demo. Start with PHPUnit unit tests for the logic in your classes, then add Behat behavior tests that walk through the user flows your plugin adds, such as a teacher creating an activity, a student submitting it, and a manager viewing a report. Behat scenarios catch problems that unit tests miss, such as a missing capability check on a page or a form that saves but never displays. Keep the tests in the plugin's own tests directory so they travel with the code through every review and upgrade.
Install tests prove the plugin works from a clean state. Run a fresh install on each combination you declare support for, meaning each PHP version, database engine and Moodle release in the plugin's version.php and documentation. Then run an upgrade test from every previously released plugin version, because most long-lived plugins break at the upgrade step, not the install step. Build the matrix from the Moodle release notes for each target: the Moodle 5.1 release notes and the Moodle 5.3 release notes list the supported PHP and database versions and upgrade prerequisites. Confirm the exact combinations there before you commit to a matrix, because the minimum PHP and database versions change between releases.
Finally, test the failure paths. Log in as users without the relevant capability and confirm every page, web service and AJAX endpoint refuses them with no data in the response. Submit invalid input, including oversized values, wrong types and IDs belonging to other courses, and confirm the plugin rejects them with a clear error and writes nothing. Check that error messages and debug output do not reveal other users' records or internal paths. Record these results as a repeatable test set, so a reviewer or auditor can see the controls were checked, not assumed.
What to maintain, back up and document after release
A plugin is not finished at release. Its errors, scheduled tasks, data, compatibility and documentation all need an owner, because Moodle moves on a fixed release cadence and a plugin that is not maintained will eventually break at an upgrade. The four areas below connect so that a failure in one is visible and recoverable in the others.
Monitor errors and scheduled tasks
Review the site logs and the scheduled task status for your plugin after every release and after every cron run that touches its tables. Watch for repeated exceptions, tasks that stop reporting success, and ad hoc tasks that pile up in the queue. Set an owner for the review, and agree in writing who acts on an error within the working day it appears. Silent failures in a plugin's cron task often surface first as missing grades or stale completions, so check the task itself, not only the user complaint.
Back up plugin data with the site
Include the plugin's database tables, its stored configuration and any files it writes to moodledata in the same backup set as the rest of Moodle. A restore that brings back the core database without the plugin's tables leaves orphaned records and broken references. Test a restore into a staging environment at least once per release cycle, and confirm that the plugin's config values come back with the site rather than being reset to defaults.
Plan checks for each release
Moodle ships major releases every six months, in April and October, and minor point releases every two months. Use the Moodle releases schedule to plan a compatibility check before each major and before any point release that changes the APIs your plugin calls. Run the plugin's test suite on the supported PHP and database versions for the target release, and record which combinations passed. Treat an unverified release as a blocked upgrade, not as a risk to accept silently.
Moodle releases scheduleDocument the data model and upgrade steps
Keep a document that lists the plugin's tables, fields and their meaning, the capabilities it defines and which roles hold them, the upgrade steps it needs between versions, and the named owner. Record the core APIs and any third-party dependencies, with their versions. Also track security releases for core and for each dependency, and state who reads those advisories and how fast a patch is applied. Without this document, the next developer must reverse engineer the plugin before fixing a single bug.
Questions teams ask before commissioning Moodle plugin development
What drives the cost of a custom Moodle plugin?
The cost follows the scope of the requirements, the plugin type, and how many Moodle systems the plugin must touch. A plugin that only adds a report reading existing tables is usually less work than an activity module with its own database tables, grading, backup and restore, and privacy handling. Other drivers include the number of integrations with external systems, the depth of the testing you require, the accessibility and UI work, and the documentation and handover you ask for. Ongoing upgrade work is a recurring cost that many buyers overlook. Ask for a written scope that lists each requirement, the plugin type chosen and why, the test environments used, and the deliverables, so the quote can be compared line by line with an internal estimate.
How long does a Moodle plugin take to build?
Duration depends on the requirements being settled before coding starts, the plugin type, the number of external systems involved, and how much existing core API work can be reused. Plugins that depend on a sign-off from an HR or student information system team, or on data that has not been mapped yet, usually take longer because the blockers sit outside the code. Review cycles, security review, and testing against the Moodle versions you run also add time. Rather than relying on a general figure, request a timeline in the written scope that breaks the work into requirements, build, review, testing, packaging and deployment, and names the dependencies the client must clear.
Can our in-house team build a Moodle plugin themselves?
Yes, if the team has PHP experience and has worked with Moodle's core APIs, including the database API, the forms API, capability checks, and the plugin lifecycle. The main skills gaps tend to be the plugin type conventions, output rendering through templates and renderers, privacy and backup handling, and the code review and testing practices the Moodle community expects. Moodle documents more than 50 plugin types, so the first decision is which type fits, and the official plugin type documentation is the natural starting point. Teams often keep ownership of requirements and day-to-day maintenance while a partner handles the architecture review or the first build. Confirm the skills and time available before deciding, and make sure at least two people can maintain the plugin.
What does our team need to provide for plugin development?
The work needs a named requirements owner who can make decisions on behalf of the business, a test environment that matches your production Moodle version, PHP and database stack, and access to realistic test data. Without a test environment at the same major version, defects tend to appear only during upgrades or go-live. The team should also provide access to any external system the plugin reads from or writes to, such as an identity provider, HR system or grading service, along with sandbox credentials. If the plugin processes personal data, the data owner should confirm what may be used in testing and how it is anonymized. Ask the provider to list these inputs in the written scope, with the person responsible for each.
When should we choose a contributed plugin instead of building one?
Choose a contributed plugin when an existing one meets the requirement with acceptable configuration, is actively maintained, and supports your Moodle version. Check the plugin's compatibility list, its last update, its license under the GPL, and whether it handles the data and privacy requirements you have. Build custom code when the requirement is specific to your processes, when no maintained plugin covers it, or when a contributed option would require heavy changes that would be lost at each upgrade. Also weigh the ongoing cost: a custom plugin needs upgrade testing for every major release, while a contributed plugin shifts some of that maintenance to its maintainers. A short evaluation against these points usually settles the choice before any build starts.
How do we keep a custom plugin working after Moodle upgrades?
A plugin survives major upgrades when it uses only documented core APIs, avoids editing core files, keeps its database schema under its own install and upgrade scripts, and declares the Moodle versions it supports in its version file. Each Moodle major release, including the next long-term support release, should be tested in a staging environment before production upgrades, starting with the PHP and database versions that release requires. Automated tests, the Moodle code checker, and a documented list of the core APIs and hooks the plugin depends on make the upgrade faster. Removed features, such as the Classic theme that left core in 5.3, can break plugins that depended on them. Agree who runs these tests and how often in the written scope or in an ongoing support arrangement.
How DeployOpen scopes, builds and hands over Moodle plugins
DeployOpen approaches Moodle plugin development as a fixed-scope engagement inside your own infrastructure, with the plugin type, core APIs, tests and packaging agreed in writing before code is written. Each stage ends with documentation your administrators and developers can use after we leave.
How we scope
- Agree the requirement and the plugin type (activity, block, local, report or enrolment) before any build starts.
- Confirm the target Moodle versions and database and PHP versions your environment runs, including any planned upgrade path.
- Check whether a contributed plugin or configuration already meets the need, so custom code is limited to real gaps.
How we build
- Use Moodle core APIs for capabilities, database access, forms, output and events rather than patching core files.
- Write automated PHPUnit and Behat tests for the plugin's behaviour and permissions, and run them on the versions in scope.
- Run code review against Moodle coding guidelines and check the plugin's security handling of user input and files.
How we hand over
- Package the plugin with a version.php file, correct component name and dependency declarations so it installs cleanly.
- Deliver installation notes, a configuration guide, the test suite and a short record of the core APIs and assumptions used.
- Walk your administrators and developers through installation, upgrade steps and where the plugin's code and settings live.
How we support
- Offer ongoing support and upgrade testing as a retainer, covering plugin compatibility checks at each Moodle release.
- Plan the plugin's compatibility with the next Moodle major release during the upgrade window before the old version loses support.
- Keep fixes and retests in the same written scope so changes are traceable to the original requirements.

