Created
March 16, 2016 18:27
-
-
Save eighty20results/77b87a6415da47994650 to your computer and use it in GitHub Desktop.
Allow user to define a custom expiration interval (defined in constant)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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