Ready-made extensions and custom development for Joomla!

More plugins tips and tricks

programmin joomla pluginsAs already mentioned in our previous article, I'm reading the book "Programming Joomla Plugins" by our friend Jisse Reitma of Yireo.

I found some more interesting stuff and it was worth another article.

If you're interested in the full story, here's the link to buy the book.

Extension plugins

For global management of your site, you may be interested in the "extension" plugins group.

The related events are:

  • onExtensionBeforeInstall
  • onExtensionAfterInstall
  • onExtensionBeforeUpdate
  • onExtensionAfterUpdate
  • onExtensionBeforeUninstall
  • onExtensionAfterUninstall

Note: there are also the onExtensionBeforeSave and onExtensionAfterSave events, but they're a bit less simple to understand / use so I'll ignore them.

With these hooks available, It's easy to add custom features like:

  • tracking / notifying install and uninstall of any extension
  • perform additional checks to prevent the execution (*)
  • perform additional operations like an extra backup

* : the hook does not in fact check the return values from the plugins, so the only way to actually prevent the execution is to perform a redirect of the Joomla application.

Installer plugins

There are some system events referring to installer tasks. Some of them may partially overlap with the above mentioned onExtension* events.

The most interesting event in this group is the onInstallerBeforePackageDownload.

This allows you to dynamically change the URL used to download a package.

Lately, this has been used to support remote updates for commercial (subscription) based extensions from within Joomla.

Shortly, you can build a plugin that picks a license key (probably from your extension configuration settings) and add it to the base update URL, so that the package download only works for active subscribers.

Lesser known plugins

There are some lesser known plugin events, like for example the ones referring to contacts and to categories.

And of course, any third party extension may have its own plugin events.

The best way to find them all is to search the code for the "trigger" keyword. The JDispatcher::trigger method is the one that actually raise a given event and allow all interested plugins do their stuff.

Conclusions

On top of all the tips strictly related to plugins development, the last chapters of the book provide useful suggestions about design patterns, best practices and other Joomla related topics.

I'm definitely happy with the book!