Freelance web developer

Moodle 2.4.1 PHPxref Code Documentation

When developing for Moodle a best practice is to use the libraries available when writing your code. When you write a Moodle plugin: a block, module, report, custom certificate or whatever you will need to use Moodle libraries to communicate with the Moodle core.

Moodle has many libraries that are always available in your plugin. These libraries are stored in your lib folder. Others need to be included in your plugin using a require_once line or similar.

Finding your way in Moodle code takes time, reading the dev documentation on Moodle.org is a good start an working on copies of existing plugins helps you get started quickly.

You can browse your Moodle code using a PHP editor like Eclipse, Notepad++, Geany or many others. Another way of finding your way around Moodle code is using PHPXref. This is a set of script that take the php documentation included in Moodle and put it into a searchable structure that show you where functions are defined and used.

You can download PHPXref, download a fresh copy of Moodle and start building the documentation yourself. Or you can use this link to browse the Moodle code.

How to use PHP XREF:
For a plugin I was writing I needed to send emails to users about a offline session that was planned. Moodle has a SMTP server configured and can send emails. I just needed to know how Moodle sends emails and how these functions work.

Most basic moodle functions are defined in /lib/moodlelib.php. Most libraries in the /lib folder have a descriptive name so finding your functions is often easy. If you are totally lost use a command line find / grep operation. Searching for my email function i started opening moodlelib.php in xref:

In my browser search I typed: email. After a few searches I found a function that matches the action I want to perform: email_to_user.

After clicking on that link I go to the function documentation

Clicking on the link “email_to_user” again brings me to the actual code so I can inspect it’s inner working.

Navigation

About Bas Brands

I develop websites based on free open source
management systems like Joomla, Wordpress and Moodle. I am a great
fan of open source software because there are no restrictions for
the user (you), and therefore your possibilities infinite!

Building and developing a clear and modern website is my expertise.
Translating your ideas, preferences and identity into a funky and
attractive website with high usability is my passion. Knowledge on
the numerous possibilities, the do's and donts, coated with
creativity and out of the box ideas, that's my philosophy!