Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save eighty20results/77b87a6415da47994650 to your computer and use it in GitHub Desktop.
Save eighty20results/77b87a6415da47994650 to your computer and use it in GitHub Desktop.
Allow user to define a custom expiration interval (defined in constant)
<?php
/*
Plugin Name: PMPro Custom Renew Button interval
Plugin URI: http://www.paidmembershipspro.com/wp/pmpro-customizations/
Description: Customization to let admin specify how early to show the renew button.
Version: .1
Author: Thomas Sjolshagen @ Stranger Studios <thomas@eighty20results.com>
Author URI: https://eighty20results.com/thomas-sjolshagen/
*/
define('CRBI_DAYS_BEFORE_EXPIRY', 30);
function crbi_is_level_expiring_soon( $is_expiring, $level )
{
if( !pmpro_isLevelExpiring( $level ) || empty( $level->enddate ) )
return $is_expiring;
switch ($level->expiration_period)
{
case 'Week':
$expires = $level->expiration_number * WEEK_IN_SECONDS;
break;
case 'Month':
$expires = $level->expiration_number * WEEK_IN_SECONDS * 4;
break;
case 'Year':
$expires = $level->expiration_number * YEAR_IN_SECONDS;
break;
default:
$expires = $level->expiration_number * DAY_IN_SECONDS;
}
if ( $expires < CRBI_DAYS_BEFORE_EXPIRY * DAY_IN_SECONDS )
$expires = CRBI_DAYS_BEFORE_EXPIRY * DAY_IN_SECONDS;
if ( (current_time('timestamp') + $expires) >= $level->enddate )
$is_expiring = true;
return $is_expiring;
}
add_filter('pmpro_is_level_expiring_soon', 'crbi_is_level_expiring_soon' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment