In this article I will show you one way you can create a WordPress site where subscription downloads and support are available only to current subscribers.
Requirement: Subscription downloads and support
Some of the least perceptive readers of this blog will wonder, why is this a problem? Just install Easy Digital Downloads and be ready to go. EDD is an awesome plugin for selling all kinds of digital products, be they graphics, software, books, you name it. If it’s a file you can sell it, and there’s a range of plugins for alternative functionality, payment gateways and such.
Read the title again! What I wanted was not to simply sell some downloads, but to offer a subscription service where said downloads are accessible. I could perhaps have gone with using the licensing extensions of EDD, but I also had the requirement that I wanted to offer restricted access to other content on the site.
The model I was going for is that a paying customer gets access to
- downloads, and
- support,
while other people simply have access to a subset of the site’s content.
Picking off-the-shelf components
Now, in WordPressland, subscriptions equals Simple Membership. So I went ahead and installed that. It can utilize PayPal recurring payments, so you can offer a subscription service that renews automatically, unless the subscriber decides to opt-out. This is, for instance, part of the model of the very successful WPMU DEV site. As a sidenote, I liked how Simple Membership integrates with MailChimp, since I’ll be needing a newsletter feature for my subscribers.
For issue tracking, I decided to go with Software Issue Manager. Unfortunately as of this writing, WordPress does not have as wide a selection of free ticket systems as I would have liked to see, but SIM is a good one and is configurable enough to fit my needs. It creates custom post types for Projects (software) and Issues (tickets). This is convenient because it means that these can then be protected with Simple Membership, like all other WordPress content.
For downloads, I chose Download Manager. The free edition offers all kinds of features for providing free downloads, while the premium package lets you build your own digital store. Since I’m using Simple Membership for billing, I don’t need the store features. I loved the feature where different versions of the same download are stored under one entity. You can offer downloads to your latest version in a prominent way, and still let the users download previous versions if they want to. There’s a simple templating system for building your download views.
And that’s it. Again, the three essential components I ended up with were the free editions of:
- Download Manager for creating downloads,
- Software Issue Manager for issue tracking, and
- Simple Membership for protecting the above content and for billing.
Now my only worry is whether the visitors of my site will be more keen to pay for digital goods than I was :-p
Glue code
By using free third-party components I’ve already packed quite a lot of features into my site without writing any code. Yet!
OK I’ve had to edit my nginx configuration so that protected downloads are actually protected,
location /wp-content/uploads/dlm_uploads { deny all; return 403; }
but that hardly counts as code. (Apache users are pandered with a ready-made .htaccess
file, so they have to do even less than that!)
Expired subscribers should have no access
It turns out I did need to write some code. Simple Membership stores its members as WordPress users, with the Subscriber role. When these users have paid, this is tracked by the plugin. When their subscription expires, they remain WordPress users. They lose access to the issue tracker because it is a custom post type and thus directly protected by Simple Membership. But downloads are shortcodes that generate links, and place them into pages that are not protected. And even if we could protect the links or their pages, we don’t want the subscribers guessing the URLs of new downloads. Users whose subscription has expired should have no access.
Fortunately, Download Manager offers a filter for access to downloads. And Simple Membership offers an easy way to check if the current user’s subscription has expired. Putting two and two together…
// restrict members only downloads if user is logged in but expired function my_dlm_can_download( $can_download, $download ) { $auth = SwpmAuth::get_instance(); //Check if account is expired. if ( is_user_logged_in() && $auth->is_expired_account() && $download->is_members_only() ) { return false; } return $can_download; } add_filter( 'dlm_can_download', 'my_dlm_can_download', 11, 2 );
I will now let you marvel at the simplicity…