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.

WordPress optimization

Easy Does It – 5 Steps to WordPress Optimization

More sites use WordPress than any other content management system (CMS) in the world. This CMS has been able to achieve this feat through its ease of use, reliability, customization, and smooth operations. However, those characteristics don’t come by default. Like most great inventions, WordPress isn’t perfect all by itself – it needs a human…
Read More
Understanding the GDPR

Understanding the GDPR

The GDPR (General Data Protection Regulation) is a new law in the European Union (EU) going into effect May 25 of 2018. There are provisions of the new regulation that make it relevant for all countries with websites that do business in the EU. What You Should Know About the GDPR The GDPR was written…
Read More
how-to-perform-a-website-audit_sidebar

Maximize your website's appeal and keep everything working for the best conversions.

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.