I’ve been using Processwire for quite some time now and yet I’m frequently amazed by how easy it is to extend it’s functionality.

Today I needed to add a new method to an existing Processwire class. At first, I wasn’t really sure how to go about it but after reading the documentation, it was much easier than expected.

I wrote a module which adds a custom hook to one of Processwire’s classes. My code looked something like this:

public function init() {
  $this->addHook('Pageimage::toPicture', $this, 'renderPictureElem');
}

And that’s all there is to it really. I then wrote a function called renderPictureElem which returns some markup when called on a Pageimage class object via the toPicture() method. Because it’s that easy to deal with functionality in Processwire, I often forget that I’m really not a backend coder, or PHP programmer for that matter. But extending Processwire is pretty straight forward and adding custom hooks is no exception. And that’s what I learnt today.