Last active
December 3, 2024 16:20
-
-
Save ipokkel/55b7dadc875e04f3d0fde4f971d41e13 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
/** | |
* Extend the expiration date from a set date for the Set Expiration Date Add On. | |
* | |
* You can add this recipe to your site by creating a custom plugin | |
* or using the Code Snippets plugin available for free in the WordPress repository. | |
* Read this companion article for step-by-step directions on either method. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_pmprosed_extend_expiration_date_from_set_date( $set_date ) { | |
// Set from date month and day here. | |
$extend_from_month = 9; // Set the numerical month from which the expiration date should be extended. | |
$extend_from_day = 1; // Set the day from which the expiration date should be extended. | |
// Build the extend from date. | |
$current_year = date( 'Y' ); // Get the current year. | |
$extent_from_date = strtotime( $current_year . '-' . $extend_from_month . '-' . $extend_from_day ); // Get timestamp. | |
// Check if we're in the extend period. | |
if ( time() >= $extent_from_date ) { | |
$set_date = date( 'Y-m-d', strtotime( '+1 year', strtotime( $set_date ) ) ); // Extend the expiration date by one year. | |
} | |
return $set_date; | |
} | |
add_filter( 'pmprosed_expiration_date', 'my_pmprosed_extend_expiration_date_from_set_date' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment