WordPress allowed me to get a better job & better projects in just a Year. I will give you tips, tricks and guide you into WordPress development so you can get more income. Sign up to my 7-day email course!
When working on various solutions that are based on WordPress, you will most certainly need to extend some part of a plugin. But what if that plugin is not really extensible? How should we solve that?
In a previous article, I have already talked about 5 Ways to Make your WordPress Plugin Really Extensible. While working on a project, I had to make another plugin extensible through my own solution. Let’s see how we can extend non extensible plugins.
That could cross your mind. You could always copy the entire plugin, change its name and then extend what you want. Maybe even extend it?
I would not solve the extensibility issue in this way. Why? What happens if the original plugin gets updates? You will have to update everything and then implement the extensibility once more (if the plugin did not add that on its own).
If you are working on your own solution, you might approach it that way but I don’t recommend it. If you are working for a client, then this certainly is not the correct way.
If you follow the WordPress community or are involved in any way with it, then you must know something about contributing. That is one of the ways you could solve the extensibility. Contributing it on the plugin can help.
But, if your project is time sensitive you can’t wait for the plugin author(s) to look at your contribution and decide to accept it.
Also, there can be plugins that do not accept contributions or don’t have any information on how to contribute.
In conclusion, this is a viable solution but if you need something right now, then you’ll have to approach it differently.
Each plugin author(s) will have their own contribution rules. In general, if a plugin is hosted on a GitHub, then there will likely be a way to contribute to it. Let’s take an example of Easy Digital Downloads. The main plugin is free and it is also hosted on GitHub: https://github.com/easydigitaldownloads/easy-digital-downloads.
This is something that might be of help to you. When you’re working with various plugins, especially premium plugins (which are not easy to contribute to), you will probably have to extend it within your solution.
I will show you one particular situation in which I was and how I have solved it. The idea about this article also came from that.
I had to create a points system for a project. For that, I went with Points and Rewards add-on for EDD. The plugin has a messaging system built in to notify the user if a product will award him with points. On the checkout screen, there will be several messages. One of them will ask them to apply the points on it and get a discount.
If they choose to apply the points, then there will be another message. That message will give them the option to remove the points from that order. My project would not allow that since the points should be automatically applied without an option to remove them.
I have looked for a filter to remove that as an option. That would be an easy fix for it. But there were no filters applied on it. Also, if a message was empty (since you can control what each message will say), the HTML will still be rendered and you will be left with an empty box.
I had to change that somehow. So, how to approach it.
First, I went looking where the messages are rendered. The messages are formed and displayed in a class
EDD_Points_Renderer. Most of the messages are contained in several methods that are hooked on some EDD regular actions.
The object of
EDD_Points_Renderer is also saved in a global variable
$edd_points_render. So, what I have done? I have copied that class, made my own and change the methods. I have added some
if-else checks to render or not the messages.
What could I have also done? Just extend the same class and redefine the methods.
Then I had to remove the previously hooked methods from the original class and then add hook my own methods in the same way. Here is a piece of the code:
So, what have I done here? I retrieved the global renderer variable and removed its methods from the hooks. After that, I have instantiated my enhanced renderer class and hooked its methods in the same way (and same order).
WordPress is great and the plugins are really awesome. But some of the plugins are not implementing the Plugin API as much as they should. Maybe because they don’t see a reason behind it? But you never know when another developer will have to extend something or change. When writing your plugins, be sure to look at the WordPress Plugin API and consider applying some of it to your returned values.
Web Developer who mainly uses WordPress for projects. Working on various project through Codeable & Toptal. Author of several ebooks at https://leanpub.com/u/igorbenic.
In less than 2 weeks, I have earned $1,800 by working on a custom solution with Easy Digital Downloads without any prior experience. Let me teach you how you can too with various custom solutions.Get the eBook