adde event expire card reminder

This commit is contained in:
asus
2024-04-09 23:05:11 +02:00
parent 1f03fa1a7b
commit 1775c86c25
4 changed files with 41 additions and 23 deletions

View File

@@ -216,7 +216,7 @@ contactez la fipf directement",
'confirmation_subject'=>"[CIPF - paiement changement carte réussi]", 'confirmation_subject'=>"[CIPF - paiement changement carte réussi]",
'confirmation_message'=>"paiement changement carte réussi", 'confirmation_message'=>"paiement changement carte réussi",
], ],
'account_will_expire'=>[ 'card_will_expire'=>[
'name'=>'prof - la carte va bientot expirer', 'name'=>'prof - la carte va bientot expirer',
'notification_send'=>true, 'notification_send'=>true,
'notification_to'=>'$$__admin_email__$$', 'notification_to'=>'$$__admin_email__$$',
@@ -226,7 +226,7 @@ contactez la fipf directement",
'confirmation_subject'=>"[CIPF - carte va expirer]", 'confirmation_subject'=>"[CIPF - carte va expirer]",
'confirmation_message'=>'votre carte va expirer bientot, renouvellez-la sur $$__base_url__$$', 'confirmation_message'=>'votre carte va expirer bientot, renouvellez-la sur $$__base_url__$$',
], ],
'account_expired'=>[ 'card_expired'=>[
'name'=>'prof - la carte a expiré', 'name'=>'prof - la carte a expiré',
'notification_send'=>true, 'notification_send'=>true,
'notification_to'=>'$$__admin_email__$$', 'notification_to'=>'$$__admin_email__$$',
@@ -236,6 +236,16 @@ contactez la fipf directement",
'confirmation_subject'=>"[CIPF - carte expirée]", 'confirmation_subject'=>"[CIPF - carte expirée]",
'confirmation_message'=>'votre carte a expiré, renouvelez-la sur $$__base_url__$$', 'confirmation_message'=>'votre carte a expiré, renouvelez-la sur $$__base_url__$$',
], ],
'account_will_be_deleted'=>[
'name'=>'prof - le compte va être supprimé',
'notification_send'=>true,
'notification_to'=>'$$__admin_email__$$',
'notification_subject'=>"[CIPF /prof - compte bientot supprimé]",
'notification_message'=>'compte bientot supprimé pour $$user_login$$ : $$__author_page_url__$$',
'confirmation_send'=>true,
'confirmation_subject'=>"[CIPF - compte bientot supprimé]",
'confirmation_message'=>'votre compte va bientot être supprimé sur $$__base_url__$$',
],
'account_deleted'=>[ 'account_deleted'=>[
'name'=>'prof - le compte a été supprimé', 'name'=>'prof - le compte a été supprimé',
'notification_send'=>true, 'notification_send'=>true,

View File

@@ -89,11 +89,11 @@ function schedule_prof_account_deletion_CIPF($user_id) {
if (false === $date_limit) { if (false === $date_limit) {
return; return;
} }
$date_limit->modify($duration_deletion); $new_date = $date_limit->modify($duration_deletion);
$delay = $date_limit->getTimestamp(); $delay = $new_date->getTimestamp();
wp_schedule_single_event($delay, 'CIPF_schedule_event_prof_account_deletion', array($user_id)); wp_schedule_single_event($delay, 'CIPF_prof_account_deletion', array($user_id));
} }
add_action('CIPF_schedule_event_prof_account_deletion', 'handle_prof_account_deletion_CIPF'); add_action('CIPF_prof_account_deletion', 'handle_prof_account_deletion_CIPF');
@@ -104,17 +104,16 @@ add_action('CIPF_schedule_event_prof_account_deletion', 'handle_prof_account_del
*/ */
function schedule_deactivate_expired_card_CIPF($user_id) { function schedule_deactivate_expired_card_CIPF($user_id) {
Plgntls::debug_infos(); Plgntls::debug_infos();
$duration_validity = Cipf::DURATION_CARD_VALIDITY;
$date_limit = get_card_date_expiration_CIPF($user_id); $date_limit = get_card_date_expiration_CIPF($user_id);
if (false === $date_limit) { if (false === $date_limit) {
return; return;
} }
$date_limit->modify('+1 day'); $new_date = $date_limit->modify('+1 day');
$delay = $date_limit->getTimestamp(); $delay = $new_date->getTimestamp();
wp_schedule_single_event($delay, 'CIPF_schedule_event_deactivate_expired_card', array($user_id)); wp_schedule_single_event($delay, 'CIPF_deactivate_expired_card', array($user_id));
} }
add_action('CIPF_schedule_event_deactivate_expired_card', 'handle_card_expire_CIPF'); add_action('CIPF_deactivate_expired_card', 'handle_card_expire_CIPF');
@@ -122,16 +121,24 @@ add_action('CIPF_schedule_event_deactivate_expired_card', 'handle_card_expire_CI
/* /*
* 4. && 5. prof, send email reminder before account expire * 4. && 5. prof, send email reminder before account expire
* *
function schedule__CIPF($user_id) {
Plgntls::debug_infos();
$delay = strtotime('+3 days');
wp_schedule_single_event($delay, 'scedule_event_CIPF', array($user_id));
}
function event_CIPF($user_id) {
Plgntls::debug_infos();
}
add_action('schedule_event_CIPF', 'event_CIPF', 10, 2);
*/ */
function schedule_reminder_before_card_expire_CIPF($user_id) {
Plgntls::debug_infos();
$card_reminder_1 = Cipf::DURATION_REMINDER_BEFORE_ACCOUNT_EXPIRE_FIRST;
$card_reminder_2 = Cipf::DURATION_REMINDER_BEFORE_ACCOUNT_EXPIRE_LAST;
$date_limit = get_card_date_expiration_CIPF($user_id);
if (false === $date_limit) {
return;
}
$new_date_1 = $date_limit->modify($card_reminder_1);
$new_date_2 = $date_limit->modify($card_reminder_2);
$delay_1 = $new_date_1->getTimestamp();
$delay_2 = $new_date_2->getTimestamp();
wp_schedule_single_event($delay_1, 'CIPF_reminder_before_card_expire', array('card_will_expire', $user_id));
wp_schedule_single_event($delay_2, 'CIPF_reminder_before_card_expire', array('card_will_expire', $user_id));
}
add_action('CIPF_reminder_before_card_expire', 'send_emails_CIPF', 10, 2);

View File

@@ -42,7 +42,7 @@ function get_date_CIPF($acf_date, $user_id) {
// compare 2 dates : https://stackoverflow.com/q/8722806/9497573 // compare 2 dates : https://stackoverflow.com/q/8722806/9497573
// also I dont use strtotime to compare 2 ints, // also I dont use strtotime to compare 2 ints,
// because i don't know if it will fail one day (2000y bug style) // because i don't know if it will fail one day (2000y bug style)
$current_date = date_create_from_format($current_format_field, $current_date_string); $current_date = date_create_immutable_from_format($current_format_field, $current_date_string);
if ($current_date === false) { if ($current_date === false) {
return false; return false;
} }
@@ -96,10 +96,10 @@ function get_new_date_CIPF($date, $duration) {
$current_date = $date; $current_date = $date;
// empty return true for false, null, empty string and array, and 0 // empty return true for false, null, empty string and array, and 0
if (empty($date)) { if (empty($date)) {
$current_date = date_create('today'); $current_date = date_create_immutable('today');
} }
else if (!$current_date instanceof DateTimeInterface) { else if (!$current_date instanceof DateTimeInterface) {
$current_date = date_create('today'); $current_date = date_create_immutable('today');
} }
/* /*

View File

@@ -176,6 +176,7 @@ function success_payment_for_user_CIPF($user_id, $order_id) {
update_card_date_expiration_CIPF($user_id); update_card_date_expiration_CIPF($user_id);
schedule_deactivate_expired_card_CIPF($user_id); schedule_deactivate_expired_card_CIPF($user_id);
schedule_prof_account_deletion_CIPF($user_id); schedule_prof_account_deletion_CIPF($user_id);
schedule_reminder_before_card_expire_CIPF($user_id);
if (is_card_new_CIPF($user_id)) { if (is_card_new_CIPF($user_id)) {
set_card_number_CIPF($user_id); set_card_number_CIPF($user_id);