I’ve been working on a new WordPress plugin called Instant Content for Demand Media that allows users to search for, purchase, and import article content directly to a WordPress site. You can think of it as a marketplace for written content that’s accessible directly through WordPress dashboard.
Instant Content is launching with over 50,000 titles available for sale, all written by freelance writers working with Demand Media. The articles are mostly practical “How-To” type content.
It’s been an interesting project to work on and I’d like to share some of the ideas behind it, how the code works, and even how the plugin could even be adapted for other purposes.
How the Plugin Works
Here’s a video demo of how purchasing content works in the plugin. I’ll describe the various nuts and bolts in more detail below:
To enable the search and purchasing of content, we needed to build our own API to return results in JSON format. The API also receives the Instant Payment Notification (IPN) from PayPal, which it uses to verify the payments and move into the purchaser’s library.
PayPal is used to handle the purchasing, which was actually much simpler than I thought it was going to be. A form is populated with all the required PayPal information. When a user clicks “Purchase” a hidden field “custom” is populated with the article key and license key, and the form is submitted to PayPal.
Once the user finishes the checkout, the IPN is sent to the API, which decodes the custom field and assigns the correct article to the user’s library (which is public JSON if you have the correct license key). It also removes that specific piece of content from sale so it can’t be purchased by anyone else.
The required fields are all in the search view if you’d like to look at the code.
The importer class uses wp_remote_get to get the article JSON, which is parsed, and then inserted as a draft post using wp_insert_post. If the creation of the post is successful, it returns the post ID back to the ajax function which let’s the user know the draft post has been created and links to it.
Gary Jones did a huge code review and refactor of the entire plugin codebase, and this is one of the many places he helped me break large functions into much smaller and generic components. So if anyone is looking to make their own importer that pulls off a JSON feed (Twitter, Instagram, WordPress.com, Data.gov), this code should be very re-usable.
License Keys / Automatic Updates
Since this is a “storefront” plugin, it could not be hosted at WordPress.org (see guideline #6). For me, automatic updates are essential to any plugin- so not being able to have the plugin on WordPress.org meant I needed to build that functionality from scratch or find an existing library to handle it.
I decided to use Easy Digital Downloads (EDD) along with the licensing add on. The licensing add-on generates licenses keys, which our internal API uses as the user key, as well as EDD to verify the download and deliver automatic updates.
In retrospect (and after some changing legal requirements about user terms), this probably could have been built much more simply by using a GitHub updater class and just making a quick custom plugin to generate unique user keys.
What I Learned
This project was first conceived as a hackathon project. We built a proof of concept in less than two days. It didn’t have the PayPal checkout functionality, or user libraries, but it demonstrated the basic idea of how a user could search and import content.
One big takeaway for me is that it takes much longer than one might think to go from a prototype to finished product. There are bound to be features and requirements that hadn’t even been considered, even big ones like automated updaters and license key generation.
In this project I was also humbled by a brilliant code review and plugin refactor/rewrite by Gary Jones. Until Gary was hired, I was the only one who had even looked at the plugin code.
There’s no reason stock photography and images couldn’t be sold through a plugin like this- there’s already an established market for it and images can also be sold multiple times (in contrast to articles).
Another interesting idea would be to allow individual site owners submit their own titles and editorial guidelines, which could then be written by qualified freelancers specifically for their site. Many sites that publish a lot of content already do this on an individual basis, but this would remove the friction from sourcing qualified freelancers and making sure they get paid.
But the first step is to see if anyone actually uses the plugin to purchase content. I invite you to try it out.