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.
How Can We Help You?
We want to build your next project.
Does Your Website Need a Tune Up?
Run a Multi-Point Inspection on your website now!
- Check speed rankings
- Test security vulnerabilities
- Find site optimizations