System Plugins

Official Documentation: https://docs.joomla.org/Plugin/Events/System

A system plugin is not only useful for a wide variety of site tasks, but is also a good intro to the lifecycle. Take note of the naming coventions plg group name written camel case for the class and snake case for the the internal plugin name.

Manifest

File Location: /plugins/system/example/example.xml

<?xml version="1.0" encoding="utf-8"?>
<extension version="3.8" type="plugin" group="system">
  <name>plg_system_example</name>
  <author>Author</author>
  <creationDate>January 2018</creationDate>
  <version>1.0.1</version>
  <description>An example system plugin</description>
  <files>
    <filename plugin="example">example.php</filename>
  </files>
  <config></config>
</extension>

Entry File

File Location: /plugins/system/example/example.php

<?php
defined('_JEXEC') or die;

class plgSystemExample extends JPlugin
{
    public function onAfterInitialise()
    {
        // Do something onAfterInitialise
        // eg. Manipulate the input prior to the router dealing with it
    }

    public function onAfterRoute()
    {
        // Do something onAfterRoute
        // eg. Test to see if this a certain component and if so run some script
    }

    function onBeforeCompileHead()
    {
        // Do something onBeforeCompileHead
        // eg. Manipulate something in the head tag
    }

    public function onAfterRender()
    {
        // Do something onAfterRender
        // eg. pull the html from the document buffer and do a string replace on something
    }
}