In the midst of 2016, I had an interesting conversation with a friend who's a local realtor. He explained that he would love to put more efforts into his online marketing, but claimed that he doesn't have a good way to import his real estate listings from ImmobilienScout24 (a popular real estate platform in the D-A-CH region) to his WordPress website.
ImmobilienScout24 only offers iFrame integration, which sucks for various reasons that I won't explain here. Instead, I'll share the tools I'm using not just to build his real estate import plugin but to turn that plugin into a business.
Let's assume you created a WordPress plugin and wanted to sell licenses for it, without paying hundreds of dollars for (well-working) solutions like Easy Digital Downloads and alike.
The problem is not to handle the payment process, but to automatically create licenses, manage their activations, and to roll out updates for your plugins.
My take on this situation is as follows:
- I'm using S2 Member to handle payments and create user accounts. It's rock-solid, and the free version allows me to implement my business idea without spending too much money initially. Generating pre-sales at discounted rates would have been another good way to validate this business, but since my friend is demanding this solution, I assume other German realtors have the same problem.
- When a new user registers in S2 Member, a routine in Software License Manager automatically creates the software license and emails it to the customer. The customer will also be able to access the license from their member dashboard.
- The realtor plugin I built checks with my license server if a valid license is provided and only loads the full functionality if that license check returns a positive result.
There might be more efficient ways to handle this situation, but this is my first official WordPress plugin, and this solution currently makes the most sense to me.
1. Handling the user registration
Assuming the plugin itself is done and working, the first step is to set up the membership area and the registration process. I've installed S2 Member on the plugin's homepage and have integrated PayPal as the payment gateway. Covering this process isn't the topic of the post, so here's a link to the S2 Member Knowledgebase.
The reason for using S2 Member primarily is that it can trigger scripts based on the event that happened.
If a new user creates a paid account, I can trigger the script to create a WP Immo license for it. You can find that setting under "S2 Member" -> "API / Notifications" in your WP Admin.
The blacked out part is the parameter that authenticates the request to my license server.
If a customer cancels her account, I can trigger a script to deactivate the respective license.
Again, I have only blacked out the secret parameter that authenticates the request with my license server.
These are the two primary use cases that can happen in a plugin-based business. Nothing too complicated if you think about it, so I felt intrigued to come up with a solution that didn't require me to buy a software that does everything for me.
2. Creating the license
Now that S2 Member has been configured to trigger the scripts to create or deactivate licenses, it's time to code the scripts. For that purpose, I've used an official tutorial from Software License Manager as a foundation and then modified the code to my needs.
I created two must-use plugins consisting of just two files. Those files receive the notifications from S2 Member and run the scripts. They could have been combined into one file, but I like to keep things separate while I'm learning.
The code of the first file handles the license creation:
The code of the second file handles the license deactivation:
These two files are placed in the mu-plugins folder in wp-content so that they're loaded with WordPress and don't show up in the Plugins menu. You could also integrate that code into a custom plugin directly; there are multiple ways to handle things like this.
3. Implementing license checks in the plugin
The last step is, to add a function to your plugin that verifies the license your user has activated.
Again, the Software License Manager has a built-in functionality you can leverage. Your user's site can communicate with your license server (the site that Software License Manager runs on) via wp_remote_get and just asks if the provided license key is valid.
First, you need to define two constants in your plugin:
define( 'YOURPREFIX_LICENSE_SERVER', 'https://wp.immo'); define( 'YOURPREFIX_VALIDATION_KEY', 'xxx');
where 'XXX' needs to be replaced with your "Secret Key for License Verification Requests" from Software License Manager.
For WP Immo, I've set up a WP-Cron job that runs daily and checks if the license entered is valid. After each run, it updates a wp_option field that is used when shortcodes or the admin pages of the plugin are loaded. By using the wp_option field instead of querying my license server every time, I'm trying to keep the impact on the loading time of the user's website as little as possible.
Be aware that this option potentially allows your user to manually overwrite the wp_option field and make the plugin think that the license is valid even if it's not. But users who are that tech-savvy could also easily remove the entire license check and rewrite the plugin to their needs - and they're probably one in 1,000 users.
The central part of the function I'm using to query the license server is:
You can then check the $repsonse variable and update the wp_option field accordingly using the update_option() function.
Building a framework that sells and manages software licenses doesn't need to be hard. I have yet to submit WP Immo to the official plugin repository.
I have yet to submit WP Immo to the official plugin repository. Once it gets approved, I can use the default WordPress update routine to roll-out updates to my customers - which was my biggest concern when I started developing WP Immo.
Even though I'm still learning a lot about building WP plugins, in particular with the intention to sell them to more than a handful of customers, I wanted to share some of my learnings with you.
My processes surely aren't perfect, but they're working for me. I'm open to suggestions how to handle things more efficient!