The freemium model is a well-known business model in WordPress. Basically, you have a free plugin with core features and a pro one with advanced features (or add-ons). In this tutorial, you will see how I use OOP to show my users the upgrade option. That could help you get better conversions in WordPress plugins.

Loading Order

To use OOP to drive better conversions, you will have to understand how everything works. The first thing is the loading order.

In my own plugin, I am using Freemius to provide my Premium version. That service allows me to have the premium code in the same place as my core features and on deployment, my premium code will be extracted from the free version.

If you’re using another method, that’s fine, as long as you are loading your premium classes before the free ones. You don’t have to load all the premium feature before, just the classes from the features you want to show as premium features. It might be confusing now, but bear with me and I’ll show you what I mean.

Plugin Features

In this example, the plugin premium features will be some of the integrations. Imagine an admin screen of integrations. Each integration is a separate class.

Integrations screen of Simple Giveaways

Let’s now look at the part of the code where I list my integrations:

For now, we don’t have any integrations, but if you add this code to a custom page for your plugin, you will just get an empty page. This is not a complete code of the admin page.

The key here is the method $integration_object->buttons(). Let’s now create the class that will be in our free plugin.

I will just assume there a function or method that includes all the files, so let’s include our free integration class somewhere like this:

include_once 'includes/integrations/mailchimp.php';

Free Premium Integration

The free premium integration will be a class that will contain just enough code for a class to work with our admin screen. The mailchimp.php would contain something like this:

As you can see, the GA_MailChimp is extended from GA_Integration. The class GA_Integration would be just an abstract class that would contain all those methods. By doing it like that, we are ensuring that there will be no errors when we call the method buttons(). Also, the method buttons() inside the class GA_Integration would have every button we would use in our premium integrations.

The free class is overriding that method and showing only the upgrade link.

Now we also need to add that class to our integrations filter my_plugin_integrations, so we could have something like this at the bottom of that file:

Now, our integration would load there and the method buttons() will only show a button to upgrade to PRO. The upgrade_url() is also from the Freemius service. You could have your own link there.

Introducing the Premium Integration

If you’re doing it like I am where I have all the code inside the same plugin (before deployment), I would load that premium integration before the free integration. So let’s say, we could have something like this:

include_once 'includes/integrations/premium/mailchimp.php';
include_once 'includes/integrations/mailchimp.php';

Let’s look at our premium class inside the premium/mailchimp.php:

If we try to load our site now, we would encounter an error that there are two same classes defined. That should not happen. And here we come to the beauty of OOP.

We just need to wrap our free integration class with a simple statement:

With that simple statement, our GA_MailChimp class will still load, but now only the premium integration one and we would have a screen like this:

Premium Integration

Conclusion

This is just a simple way of using OOP to get better conversions without doing too much in the code. We have the basic code that will process any integrations here, so we can use the same class for free and premium features. The OOP and class_exists will do the rest:)

If you’re using a different approach to loading the premium features, just be sure to load the premium class before the free one and everything should work fine.

How are you showing the premium features inside your free plugin? Are you doing something else to get better conversion? Share with others in the comment.

Are you interested in a basic plugin that could help you with such implementation?

Posted by Igor Benic

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.

3 Comments

  1. This is awesome, I like how you organize everything and that beauty of the code 🙂

    Thanks for sharing!

    Reply

  2. Great tutorial. One recommendation is for you to stop using “class_exists” and start namespacing all your classes and functions.

    Reply

    1. Hi Collins, in the scenario I am explaining in this tutorial namespaces would not help since the classes would still have the same name. That is why we are using the filter to add the integrations. That will remain the same, but the premium one will include only the class with more features.

      Reply

Leave a reply

Your email address will not be published. Required fields are marked *