gerer qu'elles disparaissent apres la date de validite -> la passer en masquer * 5. [ ] partners : offer_will_expire : la gestion des offres à échéance * 6. [ ] prof : account_deleted : schedule event pour supprimer le compte xx temps (6 mois ?) apres fin de validite de la carte * 7. [ ] prof : account_will_expire : faire rappels emails avant expiration * 8. [ ] prof : account_expired : desactiver carte expiree * */ 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; } if (is_null($user_id)) { $user_id = get_current_user_id(); } $user = get_user_by('id', $user_id); $user_email = $user->user_email; $header_content_type = 'Content-Type: text/html; charset=UTF-8'; $emails_option = Plgntls::get_option_safe($emails_option_object); if (!$emails_option) { return false; } if (!isset($emails_option[$email_name])) { return false; } $email = $emails_option[$email_name]; $emails = array(); if ($email['notification_send']) { $tmp_email = array(); $tmp_email['to'] = $email['notification_to']; $tmp_email['subject'] = $email['notification_subject']; $tmp_email['message'] = $email['notification_message']; $tmp_email['headers'] = array(); $tmp_email['headers'][] = $header_content_type; $from = $email['notification_from']; if (empty($from)) { $from = get_option('admin_email'); } if (!empty($from)) { $tmp_email['headers'][] = 'From:'.$from; } $emails[] = $tmp_email; } if ($email['confirmation_send']) { $tmp_email = array(); $tmp_email['to'] = $user_email; $tmp_email['subject'] = $email['confirmation_subject']; $tmp_email['message'] = $email['confirmation_message']; $tmp_email['headers'] = array(); $tmp_email['headers'][] = $header_content_type; $from = $email['confirmation_from']; if (empty($from)) { $from = get_option('admin_email'); } if (!empty($from)) { $tmp_email['headers'][] = 'From:'.$from; } $emails[] = $tmp_email; } return $emails; } 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)); 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)); } } } ?>