Instant Content Plugin

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.

demand-media

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:

The API

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.

Search

search-screen

You can look in the javascript file to see how search works. It’s a pretty basic AJAX call to the API- though pagination made it a bit more complex. In the future, I’d love to refactor this to use backbone and underscores templating instead.

Purchasing

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.

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.

Importing Content

Importing content is one of the most interesting pieces of the plugin. If a user clicks “import” from their library, a POST request is sent to the import view. A little Javascript/PHP dance then happens.

If the article key has been posted correctly, the javascript (initiateImporter) triggers the instant_content_import function in importer class.

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.

easy-digital

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.

Over a day or two Gary completely rewrote the plugin, broke apart my classes, broke down functional components, reorganized/rebuilt and greatly improved javascript performance, fixed missing string translations, updated inline documentation, and returned a hugely improved piece of work. The main takeaway here is to hire Gary if you can, but also, that it’s really important to have code review. I think it’s one of the best ways to become a better developer.

What’s Next

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.

About Devin

I am a developer based in Austin, Texas. I run a little theme shop called DevPress and help manage a WooCommerce shop with Universal Yums. Find me on twitter @devinsays.

6 Responses

  1. Or you could just use Written.com which licenses existing already successful content. Bloggers install our plugin and they choose which articles they want to license. Then brands make offers to license. If a blogger and a brand agree on terms the deal happens and the article is licensed – automatically transferred to the brand’s website.

    Feel free to check us out!
    http://written.com

  2. Instant Content sounds like a superbly useful plugin for budding wordpress bloggers and content publishers.

    My first question was, once you buy an article, is that same article still available to others for purchase, or does it get removed from the marketplace and become solely yours? Basically, I want to know if there’s an issue with duplicate content around the web because more than one person bought an article.

  3. Thank you for sharing this, we’re trying to do something very similar with JSON import from a site with the content we want to supply.

    I noticed that instantcontent.me is no longer, such a great idea.

    I owe you a beer for making it open source!

    Cheers
    Neil

Leave a Reply