Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Local plugins

From MoodleDocs

General customisations

Moodle has been designed with extensibility in mind. There are many plug-in points available though out Moodle to allow developers add new functionality to Moodle without modifying core code.

See the make a new plugin section of the Developer documentation page for the different plugin types available, and documentation on how to develop for them.

local/ folder for 'hacky' customisations

Sometimes it is not possible to use the available plug-in points to make your change. In situations like this then the local folder is for you. The idea is that instead of scattering your changes throughout the code base, you put them all in a folder called 'local'. Using this folder means you won't have to deal with merging problems when you upgrade the rest of your Moodle installation.

The local folder has some of the plug-in points available which are available to other modules. Perhaps most useful the local/db/ folder can be used to make database schema changes and custom role permissions.

However, using the local folder should be absolutely the last resort. Long term, you will almost certainly find it easier to maintain your changes if you can package them up as one of the standard types of plugins.

Local database changes and version

If you need to make local database customisations that are not easily encapsulated by a block or module, Moodle does support the use of a local db upgrade script, and local version number.

This is almost exactly the same as every other db/upgrade.php and version.php except for the following points:

local/version.php

local/version.php must look like:

$local_version = 2008121700;

local/db/install.xml

Local/ has no install.xml - only an upgrade.php. This is because often the changes that you want to make are not full tables, but just extra columns, and a local install.xml makes less sense than just upgrade.php.

local/db/upgrade.php

local/db/upgrade.php must look like:

function xmldb_local_upgrade($oldversion) {

   global $CFG, $db;
   $result = true;
   if ($result && $result < 2008121700) {
       $result = $result && create_table($table);
   }
   return $result;

}

Local post-installation data insertion

Local capabilities

Just like core and modules, Moodle supports the use of a db/access.php inside local/ to define local capabilities.

The formatting is exactly the same as the other db/access.php scripts - an array keyed by capability name, containing arrays of capability data, like so:

$local_capabilities = array(

   'moodle/local:capability' => array(
       'captype'      => 'write',
       'contextlevel' => CONTEXT_SYSTEM,
       'riskbitmask'  => RISK_SPAM,
   ),


Note that for all local capabilities you add, you'll need to add language strings. Moodle will expect to find them in local/lang/en_utf8/local.php (eg for English) with a key (following the above example) of local:capability

Local event subscriptions

Pending commit

It is often very helpful to be able to write custom code that subscribes to normal events that Moodle throws. It's also handy to be able to throw and catch your own custom events, as the Event API provides a very handy mechanism to do signal handling.

Local event handlers get registered at install/upgrade time just as the event handlers for modules do. To trigger an update when you add a new event handler, you must bump the local version number.

Event handlers must be defined in an array, keyed by event name, with each entry in the array information about the handler, like so:

   $handlers = array(
       'some_core_event'     => array(            // eg 'user_created'
           'handlerfile'     => '/local/lib.php', // example
           'handlerfunction' => 'local_user_create_handler',
           'schedule'        => 'cron'
       )
   );

Local admin menu items and settings

Local backup and restore hooks

Local course deletion hook

Local my moodle overrides

Local stickyblocks targets

Local user profile view hook

Local language strings

See also