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"); 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.

  • Terran

    This isn't absolutely necessary, but I think it's a nice touch. I've also created a plugin which will display a notification in the admin section of blogs that are nearing the end of a subscription period encouraging them to sign up for a longer term (monthly/quarterly), sign up for a recurring plan (non-recurring like free trial, or manual), or thanking them (yearly).

    Create a php file named whatever you want with the following:

    <?php>
    /*
    Plugin Name: Supporter payment notification
    Plugin URI:
    Description: Displays a notification in the admin section of blogs that are nearing the end of a subscription period encouraging them to sign up for a longer term (monthly/quarterly), sign up for a recurring plan (non-recurring like free trial, or manual), or thanking them (yearly).
    Author: Terran Birrell
    Version: 1.0
    Author URI: http://terran.birrell.us/
    */
    <p>global $wpdb;
    if (is_admin() && is_supporter() && $wpdb->blogid != 1){ //only run on supporter blogs and when in the admin section
    function supporter_payment_notification() {<br />
    global $wpdb;<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 />
    $remaining_days = ($expiration_date - $today)/(60 * 60 *24); //seconds b/w expiration and today += not expired, -=expired</p>
    <p>$term = $wpdb->get_var("SELECT term FROM " . $wpdb->base_prefix . "supporters WHERE blog_ID = '" . $wpdb->blogid . "'");</p>
    <p>		if ($remaining_days <= 45) {<br />
    			if ($term == 1) {<br />
    				if ($remaining_days <= 15) { //only shows up within 15 days of "expiration" for monthly<br />
    			  echo '<div id="message" class="updated"><p>You have a recurring monthly membership which will renew on ' . date(get_option('date_format'), $expire) . ' unless you have cancelled your subscription through paypal. <b>You could get 1 to 2-1/2  months free</b> every year by upgrading to a 3 or 12 month membership <a href="/wp-admin/supporter.php">here</a>. We\'d love to know your awesome self is planning to stick around for awhile!</p></div>';<br />
    				}<br />
    			  }<br />
    			elseif ($term == 3) {<br />
    					if ($remaining_days <= 15) { //only shows up within 15 days of "expiration" for quarterly<br />
    				echo '<div id="message" class="updated"><p>You have a recurring quarterly membership which will renew on ' . date(get_option('date_format'), $expire) . ' unless you have cancelled your subscription through paypal. <b>You could get 2-1/2 months free</b> every year by upgrading to a 12 month membership <a href="/wp-admin/supporter.php">here</a>. We\'d love to know your awesome self is planning to stick around for awhile!</p></div>';<br />
    					}<br />
    			}<br />
    			elseif ($term == 12) {<br />
    					if ($remaining_days <= 15) { //only shows up within 15 days of "expiration" for yearly<br />
    				echo '<div id="message" class="updated"><p>You have a recurring yearly membership which will renew on ' . date(get_option('date_format'), $expire) . ' unless you have cancelled your subscription through paypal. Thanks for sticking with us for the long haul-You\'re awesome!</p></div>';<br />
    					}<br />
    			}<br />
                else { //only shows up within 45 days of expiration. Change above to whatever # of days you'd like.<br />
    			  echo '<div id="message" class="updated"><p>You have a non-recurring <b>membership which will run out on ' . date(get_option('date_format'), $expire) . '</b>. Once your membership runs out you can renew it by signing up for a membership plan <a href="/wp-admin/supporter.php">here</a> or <a href="http://coachio.com/contact/">contact us</a> any time to arrange payment. We\'d love to have your awesome self stick around for awhile!</p></div>';<br />
    			  }<br />
    		}<br />
    }<br />
    add_action('admin_notices', 'supporter_payment_notification');<br />
    }<br />
    ?>

    This should be placed in mu-plugins.

  • Terran

    Hmmm...it did get a little ugly when I copied it in huh? If you want to shoot me an email I can send you the actual files in case something weird went on with that.

    I don't think I got a server error even when I broke things with this.

    Could the date stuff do it? Try getting rid of the grace period part.

    Also try getting rid of

    if(!is_supporter())
    	{
    		update_option('supporter_signed_up', 1);
    	}

    If that's already being set correctly I wonder if it could cause problems?

  • Terran

    @redfactory, you already have this via email, but for the benefit of anyone else reading:

    I think the most likely causes of your problem are $expire = supporter_get_expire((int)$_GET['bid']); or $expiration_date = date(U, $expire); in supporter-pay-only.php

    If you want the grace period part try removing them one at a time (note that they each appear twice each in the original file), and see if you server crash goes away. Note that the plugin won't actually work without them, but that should help narrow down the problem.

    Especially if it is the date retrieval code $expiration_date = date(U, $expire); I'd wonder if your server is using php 4 rather than 5?

    I've also added a zip with all the files at http://terran.birrell.us/pay-only-supporter-plugin/

    Hope you can figure it out!

  • Terran

    I would think you could at least achieve the free trial part with the one built in to supporter. It's basically giving supporter status so the blog would pass the is_supporter conditional as far as this plugin is concerned.

    To get different treatment for blogs that are part of a free trial (essentially not monthly, quarterly, or yearly) you would probably want to look into $term = $wpdb->get_var("SELECT term FROM " . $wpdb->base_prefix . "supporters WHERE blog_ID = '" . $wpdb->blogid . "'"); code which is finding out which type of payment they've selected.