Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save messica/2775b7e01850e1809122a096d22d3ada to your computer and use it in GitHub Desktop.
Save messica/2775b7e01850e1809122a096d22d3ada to your computer and use it in GitHub Desktop.
Testing the pmprosed_fixDate() function of PMPro Set Expiration Dates
/**
* Testing the pmprosed_fixDate function.
* 1. Make sure PMPro and PMPro Set Expiration Dates is active.
* 2. Add this code to a custom plugin.
* 3. Visit ?test_fix_date=1 to a URL
* 3a. Add &use_test_date to test from a custom date (set $now below)
* 4. Remember to remove the code when done.
*/
function test_set_expiration_dates() {
if ( empty( $_REQUEST['test_fix_date'] ) ) {
return;
}
if(!empty($_REQUEST['use_test_date'])) {
// Test date
$now = strtotime(date('2018-12-20'));
} else {
$now = current_time( 'timestamp');
}
echo 'Today is ' . date( 'Y-m-d', $now ) . '<hr />';
if ( ! function_exists( 'pmprosed_fixDate' ) && ! function_exists( 'pmprosd_daysUntilDate' ) ) {
die( 'Please activate PMPro and the PMPro Set Expiration Dates or PMPro Subscription Delays Add Ons.' );
}
$dates = array(
// set date => correct date
'Y1-12-15' => '2019-12-15',
'Y1-12-25' => '2018-12-25',
'Y1-11-15' => '2019-11-15',
'Y1-11-25' => '2019-11-25',
'Y1-M1-15' => '2019-01-15',
'Y1-M1-25' => '2018-12-25',
'Y1-M2-15' => '2019-01-15',
'Y1-M2-25' => '2019-01-25',
'Y2-M1-15' => '2019-01-15',
'Y2-M1-25' => '2019-12-25',
'Y2-M2-15' => '2019-01-15',
'Y2-M2-25' => '2019-01-25',
'2018-12-25' => '2018-12-25',
);
foreach ( $dates as $date => $correct_date ) {
// Set Expiration Dates
if ( function_exists( 'pmprosed_fixDate' ) ) {
if($correct_date == pmprosed_fixDate( $date, $now )) {
echo '&check; ';
}
echo '(' . $date . ' => ' . pmprosed_fixDate( $date, $now ) . ')<br />';
}
// Subscription Delays
if ( function_exists( 'pmprosd_daysUntilDate' ) ) {
echo '(' . $date . ' => ' . pmprosd_daysUntilDate( $date ) . ')<br />';
}
echo '<hr />';
}
exit;
}
add_action( 'init', 'test_set_expiration_dates' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment