Skip to content

Instantly share code, notes, and snippets.

@ideadude
Last active February 22, 2023 18:56
Show Gist options
  • Save ideadude/f94f4440ab109fe894a4a45bd9b64734 to your computer and use it in GitHub Desktop.
Save ideadude/f94f4440ab109fe894a4a45bd9b64734 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_date_functions=1 to a URL
* 4. Remember to remove the code when done.
*/
function test_set_expiration_dates() {
if( empty( $_REQUEST['test_date_functions'] ) ) {
return;
}
echo "Today is " . date( 'Y-m-d', current_time( 'timestamp' ) ) . "<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(
'2018-12-31',
'2019-01-01',
'2019-04-10',
'Y1-M1-01',
'Y1-M1-14',
'Y1-M1-15',
'Y1-12-01',
'Y1-12-14',
'Y1-12-15',
'Y1-12-31',
'Y1-01-01',
'Y1-01-14',
'Y1-01-15',
'Y1-04-10',
'Y2-01-01',
'Y2-12-31',
'Y2-M2-01',
'Y1-M2-01',
);
foreach( $dates as $date ) {
if( function_exists( 'pmprosed_fixDate' ) ) {
echo "(" . $date . " => " . pmprosed_fixDate( $date ) . ")<br />";
}
if( function_exists( 'pmprosd_daysUntilDate' ) ) {
echo "(" . $date . " => " . pmprosd_daysUntilDate( $date ) . ")<br />";
}
echo "<hr />";
}
exit;
}
add_action( 'init', 'test_set_expiration_dates' );
@ideadude
Copy link
Author

Potentially better test that has the expected results for each input: https://gist.github.com/messica/2775b7e01850e1809122a096d22d3ada

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment