Pay only supporter solution

Hi All,

I know this is expected to be in a future release of supporter, but in the meantime I’ve had some people ask me about this, so here is how I tweaked supporter to offer only paid blogs.

Create a file named supporter-inactive.php with the following:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br />
<!-- Ticket #11289, IE bug fix: always pad the error page with enough characters such that it is greater than 512 bytes, even after gzip compression abcdefghijklmnopqrstuvwxyz1234567890aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz11223344556677889900abacbcbdcdcededfefegfgfhghgihihjijikjkjlklkmlmlnmnmononpopoqpqprqrqsrsrtstsubcbcdcdedefefgfabcadefbghicjkldmnoepqrfstugvwxhyz1i234j567k890laabmbccnddeoeffpgghqhiirjjksklltmmnunoovppqwqrrxsstytuuzvvw0wxx1yyz2z113223434455666777889890091abc2def3ghi4jkl5mno6pqr7stu8vwx9yz11aab2bcc3dd4ee5ff6gg7hh8ii9j0jk1kl2lmm3nnoo4p5pq6qrr7ss8tt9uuvv0wwx1x2yyzz13aba4cbcb5dcdc6dedfef8egf9gfh0ghg1ihi2hji3jik4jkj5lkl6kml7mln8mnm9ono -->
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
<head>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php bloginfo('name'); ?> › Inactive Site</title><br />
<link rel="stylesheet" href="/wp-admin/css/install.css" type="text/css" />
</head></p>
<p><body id="error-page">
<p>This site is currently inactive. If you are the owner of this site please <a href="/wp-admin/">login</a> to activate your site. </p>
<p>If this is a mistake please <a href="http://yoursite.tld/contact_page/">contact us</a> immediately so we can fix it!</p><br />
</body>
</html>

This is going to have to go into ALL the available themes. I’ll explain why later. I feel like there should be a way around this, but since I’m using a single parent theme and the rest are child themes I didn’t work too hard at it. I only have to put it in the parent theme.

This page is theme independent since it uses the default WordPress error page, but you could also make a prettier page if you wanted to create a template that will work within the site’s theme.

create a php file name whatever you want with the following:

<?php<br />
/*<br />
Plugin Name: Pay Only Supporter<br />
Plugin URI:<br />
Description: Displays an error message on the front end of a any site that does not have supporter status from the WPMU Dev supporter plugin.<br />
Author: Terran Birrell<br />
Version: 1.0<br />
Author URI: http://terran.birrell.us/<br />
*/</p>
<p>if (!is_supporter()) { //only run ANYTHING in this file if the blog is not a supporter blog </p>
<p>function grace_period_message() {<br />
$expire = supporter_get_expire((int)$_GET['bid']);<br />
$expiration_date = date(U, $expire); //Seconds b/w Unix Epoch (January 1 1970) and expiration date<br />
$today = date(U); //Seconds b/w Unix Epoch (January 1 1970) and today<br />
$grace_period = 15 * 24 * 60 * 60; //15 days x 24 hr/day x 60 min/hr x 60 sec/min<br />
$remaining_time = $expiration_date - $today; //seconds b/w expiration and today += not expired, -=expired<br />
$remaining_days = floor(($remaining_time + $grace_period) / (60 * 60 *24));</p>
<p>if (!is_supporter() && $remaining_time <= 0) {</p>
<p> echo '<p>The subscription for this site has expired. It is currently in the grace period. The site will <b>become inactive</b> in approximately <b>' . $remaining_days . ' days</b>. If you are the site owner and would like to prevent this please <a href="/wp-admin/supporter.php">login here</a> to renew your subscription. If this is a mistake please <a href="http://yoursite.tld/contact_page/">contact us</a> immediately so we can fix it!</p>' ;<br />
}<br />
}<br />
add_action('get_header','grace_period_message');<br />
//the entire grace_period_message() function can be deleted if you choose not offer a grace period by altering line 38 below.</p>
<p>//display a custom template if the blog is inactive<br />
function supporter_redirect() {<br />
$expire = supporter_get_expire((int)$_GET['bid']);<br />
$expiration_date = date(U, $expire); //Seconds b/w Unix Epoch (January 1 1970) and expiration date<br />
$today = date(U); //Seconds b/w Unix Epoch (January 1 1970) and today<br />
$grace_period = 15 * 24 * 60 * 60; //15 days x 24 hr/day x 60 min/hr x 60 sec/min<br />
$remaining_time = $expiration_date - $today; //seconds b/w expiration and today += not expired, -=expired<br />
$remaining_days = $remaining_time / (60 * 60 *24);</p>
<p>if(!is_supporter() && $remaining_time + $grace_period <= 0) //replace with if(!is_supporter()) to remove the grace period<br />
{<br />
include(TEMPLATEPATH."/supporter-inactive.php"); //place supporter-inactive.php in all available themes.<br />
exit();<br />
}<br />
}<br />
add_action('template_redirect','supporter_redirect');</p>
<p>//if not supporter set supporter_signed_up (ala signup form) to 1 so that it forces to supporter payment page even if they didn't indicate they were interested in the<br />
if(!is_supporter())<br />
{<br />
update_option('supporter_signed_up', 1);<br />
}<br />
}

This will be placed in mu-plugins.

As it is set up it offers a grace period of 15 days during which time it will display a message in the sites header (as long as the sites theme allows the get_header hook, which I think it should).

If you don’t want to offer a grace period (and have the blog become inactive immediately) just delete the entire grace_period_message() function (not that you have to since it will never get a chance to show anyway), and change if(!is_supporter() && $remaining_time + $grace_period <= 0) to if(!is_supporter()) You can also delete all the time calculation stuff in this case.

include(TEMPLATEPATH.”/supporter-inactive.php”:wink:; is the part which means the supporter-inactive.php template has to be in EVERY available theme since it’s going to look in the current sites active theme. I played around with this a little and couldn’t get it to work with the file in another location, but I feel like you should be able to get it to work in another location. I didn’t try very hard.

One last step: Comment out line 512 of supporter-framework.php which says:

add_action('supporter_output_after', 'supporter_signup_dismiss');

This will remove the “No Thanks” link from the supporter signup page.

Also note that you will want to always link to your signup page with the wp-signup.php?supporter=1 version of the link so you don’t confuse people by asking if they’re interested in supporter.

That was rather more complicated than I had thought, so let me know if anything was unclear.

I hope it helps some people.