Building a Pluggable Plugin

building a pluggable plugin

Building plugins is something that’s near and dear to our business. We build and sell our own premium plugins. And just about every project we take on has some sort of custom functionality that we roll into a plugin. Over the years, we’ve evolved our process to make it easier to extend or modify these plugins in specific situations. We like to call these kinds of plugins, Pluggable Plugins.

Using AdSanity as an example, our entire add-on architecture is built from this methodology. But this isn’t a concept that we conjured out of thin air. We’re utilizing actions and filters available through WordPress Core’s Plugin API. In fact, WordPress Core uses these APIs throughout its codebase. This allows the codebase to be modified without developers having to hard code changes into the software. This would make it complicated to update without losing your changes. You see, that’s the beauty of using actions and filters.

Doing an Action

Actions allow you or another developer to tap into the execution of your code at specific places to execute code. The Gravity Forms plugin uses actions extensively, so I’ll use their code as an example.

Every time a form is submitted, the “gform_after_submission” action is triggered. Along with that action being triggered, the action passes along some data that I can use in my own callback. That data is the entry object and form object. Let’s say I wanted to send the data that was submitted to a third party Customer Relationship Management (CRM) system. I could write my own functionality and hook it into the action provided by Gravity Forms. This would fire off an API call to my CRM of choice. Additionally, since I have access to the data submitted in the entry object, I can write in conditional logic to process different submissions in different ways. The possibilities are endless!

Applying a Filter

With filters you are changing data. Functionally, the code to implement a filter is very similar to action. But the use case is definitely different. Actions allow you to execute some new code. Filters change data to achieve a different result. Beaver Builder is a plugin that takes advantage of filters in a number of different ways.

For example, we wanted to be able to schedule certain modules to publish and sunset on particular days. So we built a user interface to select a publish date and a sunset date within each module. The developers at Beaver Builder built a filter to add sections to each module’s settings screen, “fl_builder_register_settings_form”. Similar to how actions work, data can be passed on through filters. The list of tabs for the module and the ID of the element being shown are passed through this filter. We received the tab data, add our tabs, and then send the data back into the Beaver Builder machine.

Go Out and Make Pluggable Plugins

WordPress Core makes use of actions and filters throughout its codebase. So by no means do you have to be using plugins to utilize the Plugins API. But if you build plugins for you or for your clients, you owe it to yourself to utilize the Plugins API in your own code. This will make your projects more versatile both for you and anyone else working on your codebase.

Please note: Links to external companies may be affiliate links. If you use our links, we may earn a small commission.

Written by the Team at Pixel Jar

We hope you got something useful out of that post. If you'd like to read more we have an active blog with topics across the spectrum of website development. If you're researching information for a project we'd love to talk to you about it.

WordCamp LAX 2015 logo

Jeff Presents at WordCamp LAX 2015

This summer Jeff was selected to speak at WordCamp LAX, a WordCamp we love attending every year. His topic covered productivity tips he uses when developing websites. The idea being that time is money, so do not waste it on repetitive or mundane tasks that can be automated or sped up. You can watch his…
Read More
custom theme design versus existing themes

Custom Theme Design vs. Existing Themes

When we start discussing a new website project with a client there are two primary paths that we walk. We can base the new design on an existing theme or we can create a custom theme design. There are usually some immediate reactions to these options depending on the client. In this post we’re going…
Read More

How Can We Help You?

We want to build your next project.

Connect with Pixel Jar

Our Community

Subscribe to learn more about the goings on at Pixel Jar.
  • Note: Your email will be added to our CRM and be used to receive emails from Pixel Jar. You can unsubscribe at any time.

  • This field is for validation purposes and should be left unchanged.