Another day another challenge. This time I was working on a WordPress Plugin. As you might know, I use the Divi Theme a lot. I think it’s a really cool Theme with a powerful page builder and all sorts of cool modules. There is even a marketplace where you can buy additional modules and child themes.

About two month ago, I was in desperate needs for a module for my german travel blog which didn’t exist in the Divi Page Builder. I also did not find anything close to what I needed on the web or in the marketplace. So as the programmer I am, I decided that it was time to learn another language (PHP) and dive a little bit into WordPress development.

I developed a module called Date Counter for Divi for the Divi Page Builder and I was really happy with it. On Facebook I asked in some Divi groups if people would like to test it – my plan was to sell it via Gumroad on this site. A fellow german developer pointed me to the Elegant Marketplace and told me that I should start selling my plugins there.

I checked the page out, created a account and after one or two days, I already had my first sale. Awesome. But then I created a update because I fixed a small issue with a wrong text. Now how should I give the update to my customers? I mean sure, they can just download the plugin, remove the old one from their WordPress and install the new version but we live in 2017, not 1600 bc – amirite?

Fortunately the Elegant Marketplace works with a tool called Easy Digital Downloads – a suite for selling digital products via your own WordPress installation. It comes with all sorts of extensions and one of the – at least I think so – coolest functions is the possibility to use WordPress native updating mechanism to provide updates for your plugins and themes.

Implementation is quiet simple too. At least if you know what to do. Elegant Marketplace provides a small coding sample in the Vendor Dashboard as well as a sample plugin and a sample theme but I still got confused and in the end, even after I did everything right according to them, it still did not work till I did a small change by myself they were not aware of by themselves.

So let me explain what you actually have to do to get licensing and updating via EDD for your products on the Elegant Marketplace.

Step 1: Preparing your Plugin

The first thing you have to do is to prepare your plugin. Thats really, really really simple. All you have to do is to copy over the EDD_SL_Plugin_Updater.php file to your plugin folder. It really doesn’t matter where you put it. I for example put it in the root directory because my plugins are only a few files and I don’t see a need for folders.

I saw that the popular Woo Layout Injector plugin puts it in a folder called includes but thats just personal preference I guess. You can get the file from the edd-sample-plugin-1 on the vendor dashboard of Elegant Marketplace or directly from the Easy Digital Downloads Github Repo.

Step 2: Copy over the sample code

The second step is to copy over the sample code from the edd-sample-plugin.php to your plugin file. If you are an advances developer, you of course can put this code in a separate php file and include it in your plugin file instead of stuffing your plugin file with all that code. Anyways, lets go through the code. I’ll explain to you step by step what you have to change and what to keep.

This is the first part. Here we define the EDD store url, the plugin name, the page where the license field is displayed and we also include the EDD_SL_Plugin_Updater.php if it wasn’t installed by another plugin already. Here are the changes you have to do:

  • Rename EDD_SAMPLE_STORE_URL to something meaningful for you
  • Change the value of EDD_SAMPLE_STORE_URL to
  • Rename EDD_SAMPLE_ITEM_NAME to something meaningful for you
  • Change the value of EDD_SAMPLE_ITEM_NAME to the display name of your plugin or theme on Elegant Marketplace. A good example is my “Date Counter for Divi” Module or the “Woo Layout Injector”
  • Rename EDD_SAMPLE_PLUGIN_LICENSE_PAGE to something meaningful for you
  • Change the value of EDD_SAMPLE_PLUGIN_LICENSE_PAGE to the slug of your license page. If you want to include the license field on a existing settings page, this should match it
  • Finally change the path to the EDD_SL_Plugin_Updater.php to match whatever path you put it in. If your EDD_SL_Plugin_Updater.php is in the root directory of your plugin, you don’t need to change the path

Ready for the next part? Here we go:

This function sets up the updating mechanism. Here I had the most trouble when setting up my plugin for the first time. It took me a few days to figure out what I was doing wrong. I ended up debugging the EDD_SL_Plugin_Updater class and recreating its API calls to see whats wrong. So let me tell you what you have to change here:

  • Change edd_sample_license_key to something meaningful for you. It’s a good idea to use your vendor prefix (I use jt_ for my plugins) followed by your plugins name followed by license_key. Ideally you use search and replace to replace all occurrences of this string throughout the rest of the code.
  • Match the version field to your plugins current version.
  • Change EDD_SAMPLE_ITEM_NAME to match the field you changed in the last section.
  • Remove the author field completely. This is what in the end prevented my plugin from getting updates but I only found out about this after recreating the API call from the EDD_SL_Plugin_Updater with a REST tool (I use Postman by the way). As far as I’m concerned, the author field is not necessary when checking for updates so you can safely omit it
  • Finally rename edd_sl_sample_plugin_updater to something meaningful for you. Again, using your vendor prefix and plugin name followed by _updater is kind of a good idea I guess

The next part is simplest as well if you take your time and look through the code:

Here we add the settings page with the field to enter the license for updating. Of course you could also use get_option( ‘edd_sample_license_status’ ) in your plugin itself to check if the license is activated and only if so you would do something. However, I’m not doing that because first of all, I offer lifetime licenses for my customers but even if you offer only let’s say a year of updates, you still want your plugin to function. You just don’t give support.

The things we have to do here are:

  • Rename the functions to follow the previous naming convention <vendor>_<plugin>_<descriptive function name>
  • Rename Plugin License in the add_plugins_page() function to something meaningful. Remember, that page will show up under Plugins in your WordPress installation. Of course you can put this on a existing settings page of your plugin instead of adding a page under Plugins if you like.
  • Well basically you have to rename all the “edd_…” stuff and match it to whatever you renamed in the previous sections (e. g. EDD_SAMPLE_PLUGIN_LICENSE_PAGE which is the settings page slug)

Ready for the last parts? We are almost done.

Here we do almost exactly the same as in the previous section. We change every occurrence of edd to our own vendor prefix, rename samle to our own plugin name and match the constants we have defined. If you used search and replace, you should have almost nothing to do.

Did I say “every occurence of edd”? Well that is not completely true. Notice that the $api_params array has a field called edd_action. This field must keep the name edd_action! This is one of the rare occurrences where you don’t rename edd and it costed me half a day to figure this out. Blindly following the tutorial on Elegant Marketplace I first used a search and replace to replace every edd_ throughout the whole code and then the search for errors started.

So be aware and don’t change the edd_action to your plugin prefix!

Okay, now to the last part:

This function takes care of displaying error messages if something goes wrong during the activation process of the license. Here again we just have to rename the functions to match our vendor prefix and plugin name.

Thats it. Your licensing / updating should now work. For me the two issues which caused the most trouble were the fact that I renamed the edd_action parameter and that I had to remove the vendor field from the call to the updater class. If this tutorial was helpful for your, I’d love to hear about it in the comments section. Cheers ✌️



Pin It on Pinterest

Share This