Home > Articles > Web Development

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

How Do Plugins Work?

Plugins work in three steps, as follows:

  1. One or more plugin files are included into the current script, usually with the JPluginHelper::importPlugin() method. Because plugins are normally class declarations, no code is executed at this point.
  2. An event is triggered, usually with the $dispatcher->trigger() method (where $dispatcher is a JDispatcher object). Each event has a name, such as onBeforeInitialise or onContentBeforeSave.
  3. The event processing code looks for any enabled plugins that are currently loaded that have a method that matches the event name. If any matching methods are found, they are executed.

Naming Conventions for Plugins

For plugins to be found by the JPluginHelper::importPlugin() method, we need to follow the correct naming conventions for the plugin file and class names.

Plugin folder and file names are created as follows:

plugins/<plugin type>/<plugin name>/<plugin name>.php

So, for example, the SEF file is plugins/system/sef/sef.php. Plugins have an XML file with the same name (for example, plugins/system/sef/sef.xml). We discuss the XML file later in the chapter when we talk about packaging a plugin extension.

The class name of the plugin is based on the naming convention

"plg" + <plugin type> + <plugin file name>

So, for example, the class name of the SEF plugin is plgSystemSEF.

  • + Share This
  • 🔖 Save To Your Account