events actions and email for profs are now well supported, without repeatitions

This commit is contained in:
asus
2024-04-11 14:36:44 +02:00
parent f2ca863dcb
commit 6aa3915ef9
4 changed files with 52 additions and 14 deletions

View File

@@ -28,7 +28,7 @@ if (!defined('ABSPATH')) {
function prepare_emails_CIPF($email_name, $user_id) {
Plgntls::debug_infos();
$emails_option_object = Cipf::OPTION_EMAILS;
if (!isset($emails_option_object['_default'][$email_name])) {
return false;
}
@@ -59,12 +59,13 @@ function prepare_emails_CIPF($email_name, $user_id) {
$tmp_email['message'] = $email['notification_message'];
$tmp_email['headers'] = array();
$tmp_email['headers'][] = $header_content_type;
$tmp_email['headers'][] = 'User_id: '.$user_id;
$from = $email['notification_from'];
if (empty($from)) {
$from = get_option('admin_email');
}
if (!empty($from)) {
$tmp_email['headers'][] = 'From:'.$from;
$tmp_email['headers'][] = 'From: '.$from;
}
$emails[] = $tmp_email;
}
@@ -75,12 +76,13 @@ function prepare_emails_CIPF($email_name, $user_id) {
$tmp_email['message'] = $email['confirmation_message'];
$tmp_email['headers'] = array();
$tmp_email['headers'][] = $header_content_type;
$tmp_email['headers'][] = 'User_id: '.$user_id;
$from = $email['confirmation_from'];
if (empty($from)) {
$from = get_option('admin_email');
}
if (!empty($from)) {
$tmp_email['headers'][] = 'From:'.$from;
$tmp_email['headers'][] = 'From: '.$from;
}
$emails[] = $tmp_email;
}
@@ -93,12 +95,11 @@ function send_emails_CIPF($email_name, $user_id = null) {
Plgntls::debug_infos();
$emails = prepare_emails_CIPF($email_name, $user_id);
if (false === $emails) {
error_log('Email preparing failed!: ' . json_encode($emails));
error_log('Email preparing failed!: ' . json_encode($email_name));
return;
}
foreach ($emails as $email) {
error_log('Email: ' . json_encode($email));
$sent = wp_mail($email['to'], $email['subject'], $email['message'], $email['headers']);
if (!$sent) {
error_log('Email sending failed!: ' . json_encode($email));

View File

@@ -71,7 +71,10 @@ function handle_card_expire_CIPF($user_id) {
else {
set_account_expired_CIPF($user_id);
}
send_emails_CIPF('account_expired', $user_id);
if (!is_email_reminder_choice_CIPF('card_expired', $user_id)) {
set_email_reminder_choice_CIPF('card_expired', $user_id);
send_emails_CIPF('card_expired', $user_id);
}
}
else {
if (is_account_waiting_transfert_CIPF($user_id)) {
@@ -81,6 +84,7 @@ function handle_card_expire_CIPF($user_id) {
set_account_valid_CIPF($user_id);
}
reset_emails_reminders_deletion_account_CIPF($user_id);
unset_email_reminder_choice_CIPF('card_expired', $user_id);
}
}
@@ -228,9 +232,6 @@ function handle_reminders_before_account_deleted_CIPF($user_id) {
if (is_email_reminder_choice_CIPF($reminder_key, $user_id)) {
continue;
}
/*
unset_email_reminder_choice_CIPF($reminder_key, $user_id);
*/
set_email_reminder_choice_CIPF($reminder_key, $user_id);
send_emails_CIPF('account_will_be_deleted', $user_id);
return; // don't send multiple emails