handle reminders before card expiration and account deletion
This commit is contained in:
@@ -100,9 +100,9 @@ function send_emails_CIPF($email_name, $user_id = null) {
|
|||||||
foreach ($emails as $email) {
|
foreach ($emails as $email) {
|
||||||
error_log('Email: ' . json_encode($email));
|
error_log('Email: ' . json_encode($email));
|
||||||
$sent = wp_mail($email['to'], $email['subject'], $email['message'], $email['headers']);
|
$sent = wp_mail($email['to'], $email['subject'], $email['message'], $email['headers']);
|
||||||
}
|
if (!$sent) {
|
||||||
if (!$sent) {
|
error_log('Email sending failed!: ' . json_encode($email));
|
||||||
error_log('Email sending failed!: ' . json_encode($email));
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -48,17 +48,30 @@ if (!defined('ABSPATH')) {
|
|||||||
*
|
*
|
||||||
* [/] prof change card ('changement_de_carte')
|
* [/] prof change card ('changement_de_carte')
|
||||||
*
|
*
|
||||||
|
* [/] 'emails_reminders'
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
/*
|
||||||
|
{"ID":36414, "key":"field_65d85d72c4265", "label":"\u00c9tat carte", "name":"etat_carte", "aria-label":"", "prefix":"acf", "type":"radio", "value":"Renouvellement", "menu_order":0, "instructions":"", "required":0, "id":"", "class":"", "conditional_logic":0, "parent":34538, "wrapper":{"width":"","class":"","id":""}, "choices":{"Commande":"Commande","Renouvellement":"Renouvellement"}, "default_value":"Commande", "return_format":"value", "allow_null":0, "other_choice":0, "layout":"vertical", "save_other_choice":0, "_name":"etat_carte", "_valid":1}
|
||||||
|
{"ID":40951, "key":"field_65eedb65227cb", "label":"\u00c9tat paiement", "name":"etat_paiement", "aria-label":"", "prefix":"acf", "type":"radio", "value":"aucun", "menu_order":1, "instructions":"", "required":0, "id":"", "class":"", "conditional_logic":0, "parent":34538, "wrapper":{"width":"","class":"","id":""}, "choices":{"en_cours":"en_cours","reussi":"reussi","echec":"echec","aucun":"aucun"}, "default_value":"aucun", "return_format":"value", "allow_null":0, "other_choice":0, "layout":"vertical", "save_other_choice":0, "_name":"etat_paiement", "_valid":1}
|
||||||
|
{"ID":41496, "key":"field_65f89fb6de318", "label":"\u00c9tat compte", "name":"etat_compte", "aria-label":"", "prefix":"acf", "type":"radio", "value":"carte expiree", "menu_order":2, "instructions":"", "required":0, "id":"", "class":"", "conditional_logic":0, "parent":34538, "wrapper":{"width":"","class":"","id":""}, "choices":{"nouveau prof":"nouveau prof","doit payer":"doit payer","carte valide":"carte valide","en attente invalide":"en attente invalide","en attente valide":"en attente valide","carte expiree":"carte expiree"}, "default_value":"nouveau prof", "return_format":"value", "allow_null":0, "other_choice":0, "layout":"vertical", "save_other_choice":0, "_name":"etat_compte", "_valid":1}
|
||||||
|
{"ID":36014, "key":"field_65d66b26ebf59", "label":"Fin de validit\u00e9", "name":"fin_de_validite", "aria-label":"", "prefix":"acf", "type":"date_picker", "value":"14\/10\/2023", "menu_order":3, "instructions":"", "required":0, "id":"", "class":"", "conditional_logic":0, "parent":34538, "wrapper":{"width":"","class":"","id":""}, "display_format":"d\/m\/Y", "return_format":"d\/m\/Y", "first_day":1, "_name":"fin_de_validite", "_valid":1}
|
||||||
|
{"ID":34541, "key":"field_65d24447cc89f", "label":"Tarif", "name":"tarif", "aria-label":"", "prefix":"acf", "type":"radio", "value":"Mon association adh\u00e8re \u00e0 la FIPF, je peux commander la carte \u00e0 10 \u20ac", "menu_order":4, "instructions":"", "required":0, "id":"", "class":"", "conditional_logic":0, "parent":34538, "wrapper":{"width":"","class":"","id":""}, "choices":{"10":"Mon association adh\u00e8re \u00e0 la FIPF, je peux commander la carte \u00e0 10 \u20ac","15":"Je suis hors r\u00e9seau FIPF et je souhaite commander la carte \u00e0 15 \u20ac"}, "default_value":"", "return_format":"label", "allow_null":0, "other_choice":0, "layout":"vertical", "save_other_choice":0, "_name":"tarif", "_valid":1}
|
||||||
|
{"ID":34539, "key":"field_65d243b9cc89d", "label":"Paiement", "name":"paiement", "aria-label":"", "prefix":"acf", "type":"radio", "value":"Paypal", "menu_order":5, "instructions":"", "required":0, "id":"", "class":"", "conditional_logic":0, "parent":34538, "wrapper":{"width":"","class":"","id":""}, "choices":{"Paypal":"Imm\u00e9diat par carte bancaire ou transfert via PayPal","Virement":"Par virement bancaire (coordonn\u00e9es bancaires apr\u00e8s validation)"}, "default_value":"", "return_format":"value", "allow_null":0, "other_choice":0, "layout":"vertical", "save_other_choice":0, "_name":"paiement", "_valid":1}
|
||||||
|
{"ID":34777, "key":"field_65d36f6e02a9a", "label":"Livraison", "name":"livraison", "aria-label":"", "prefix":"acf", "type":"radio", "value":"Je t\u00e9l\u00e9charge ma carte au format pdf pour l'imprimer", "menu_order":6, "instructions":"", "required":0, "id":"", "class":"", "conditional_logic":0, "parent":34538, "wrapper":{"width":"","class":"","id":""}, "choices":{"Je t\u00e9l\u00e9charge ma carte au format pdf pour l'imprimer":"Je t\u00e9l\u00e9charge ma carte au format pdf pour l'imprimer","Je pr\u00e9f\u00e8re r\u00e9gler un suppl\u00e9ment de 5 euros pour recevoir ma carte plastifi\u00e9e":"Je pr\u00e9f\u00e8re r\u00e9gler un suppl\u00e9ment de 5 euros pour recevoir ma carte plastifi\u00e9e"}, "default_value":"", "return_format":"label", "allow_null":0, "other_choice":0, "layout":"vertical", "save_other_choice":0, "_name":"livraison", "_valid":1}
|
||||||
|
{"ID":34540, "key":"field_65d2441fcc89e", "label":"CGV", "name":"cgv", "aria-label":"", "prefix":"acf", "type":"checkbox", "value":[], "menu_order":7, "instructions":"", "required":0, "id":"", "class":"", "conditional_logic":0, "parent":34538, "wrapper":{"width":"","class":"","id":""}, "choices":{"cgv":"J'accepte les conditions g\u00e9n\u00e9rales de vente"}, "default_value":[], "return_format":"value", "allow_custom":0, "layout":"vertical", "toggle":0, "save_custom":0, "custom_choice_button_text":"Ajouter un nouveau choix", "_name":"cgv", "_valid":1}
|
||||||
|
{"ID":34869, "key":"field_65d396876fe57", "label":"Somme \u00e0 r\u00e9gler", "name":"somme_a_regler", "aria-label":"", "prefix":"acf", "type":"number", "value":"10", "menu_order":8, "instructions":"", "required":0, "id":"", "class":"", "conditional_logic":0, "parent":34538, "wrapper":{"width":"","class":"","id":""}, "default_value":"", "min":"", "max":"", "placeholder":"", "step":"", "prepend":"", "append":"", "_name":"somme_a_regler", "_valid":1}
|
||||||
|
{"ID":39528, "key":"field_65e48a0201107", "label":"Num\u00e9ro de la carte", "name":"numero_de_la_carte", "aria-label":"", "prefix":"acf", "type":"number", "value":"20240410264", "menu_order":9, "instructions":"", "required":0, "id":"", "class":"", "conditional_logic":0, "parent":34538, "wrapper":{"width":"","class":"","id":""}, "default_value":"", "min":"", "max":"", "placeholder":"", "step":"", "prepend":"", "append":"", "_name":"numero_de_la_carte", "_valid":1}
|
||||||
|
{"ID":41524, "key":"field_65f9ecc223c86", "label":"\u00c9tat virement", "name":"etat_virement", "aria-label":"", "prefix":"acf", "type":"checkbox", "value":[], "menu_order":10, "instructions":"", "required":0, "id":"", "class":"", "conditional_logic":0, "parent":34538, "wrapper":{"width":"","class":"","id":""}, "choices":{"virement re\u00e7u":"virement re\u00e7u"}, "default_value":[], "return_format":"value", "allow_custom":0, "layout":"vertical", "toggle":0, "save_custom":0, "custom_choice_button_text":"Add new choice", "_name":"etat_virement", "_valid":1}
|
||||||
|
{"ID":41746, "key":"field_66143344e64f0", "label":"order id", "name":"order_id", "aria-label":"", "prefix":"acf", "type":"text", "value":"98L02669NJ307423E", "menu_order":11, "instructions":"", "required":0, "id":"", "class":"", "conditional_logic":0, "parent":34538, "wrapper":{"width":"","class":"","id":""}, "default_value":"", "maxlength":"", "placeholder":"", "prepend":"", "append":"", "_name":"order_id", "_valid":1}
|
||||||
|
{"ID":41763, "key":"field_6615790b81f9b", "label":"changement de carte", "name":"changement_de_carte", "aria-label":"", "prefix":"acf", "type":"true_false", "value":false, "menu_order":12, "instructions":"", "required":0, "id":"", "class":"", "conditional_logic":0, "parent":34538, "wrapper":{"width":"","class":"","id":""}, "message":"carte perdue", "default_value":0, "ui":0, "ui_on_text":"", "ui_off_text":"", "_name":"changement_de_carte", "_valid":1}
|
||||||
|
{"ID":41781, "key":"field_66168f203fd03", "label":"rappels emails", "name":"rappels_emails", "aria-label":"", "prefix":"acf", "type":"checkbox", "value":["rappel email 7 jours avant suppression du compte","rappel email 1 mois avant suppression du compte","rappel email 7 jours avant suppression du compte","rappel email 1 mois avant suppression du compte","rappel email 7 jours avant suppression du compte"], "menu_order":14, "instructions":"case coch\u00e9e signifie email deja envoy\u00e9, donc pas renvoy\u00e9", "required":0, "id":"", "class":"", "conditional_logic":0, "parent":34538, "wrapper":{"width":"","class":"","id":""}, "choices":{"card_expiration \/ -30 days":"rappel email 1 mois avant expiration de la carte","card_expiration \/ -7 days":"rappel email 7 jours avant expiration de la carte","account_deletion \/ -30 days":"rappel email 1 mois avant suppression du compte","account_deletion \/ -7 days":"rappel email 7 jours avant suppression du compte"}, "default_value":[], "return_format":"label", "allow_custom":0, "layout":"vertical", "toggle":0, "save_custom":0, "custom_choice_button_text":"Add new choice", "_name":"rappels_emails", "_valid":1}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
i* try to init acf value with
|
* try to init acf value with default value
|
||||||
* - default value
|
* -> dont init with other values, because it can be willingly that the init value is empty
|
||||||
* - first value
|
|
||||||
* also, if there is choices but default value is not set, init with first choice
|
|
||||||
* but if there is choices and default value is set, prefer default value
|
|
||||||
* if none of them are set, dont init
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function init_field_CIPF($acf_field_name, $acf_id) {
|
function init_field_CIPF($acf_field_name, $acf_id) {
|
||||||
@@ -82,7 +95,6 @@ function init_field_CIPF($acf_field_name, $acf_id) {
|
|||||||
|
|
||||||
$acf_object = null;
|
$acf_object = null;
|
||||||
foreach ($acf_groups as $group) {
|
foreach ($acf_groups as $group) {
|
||||||
error_log("group: " . json_encode($group));
|
|
||||||
foreach (acf_get_fields($group['key']) as $field_key => $field) {
|
foreach (acf_get_fields($group['key']) as $field_key => $field) {
|
||||||
if ($field['_name'] === $acf_field_name) {
|
if ($field['_name'] === $acf_field_name) {
|
||||||
$acf_object = $field;
|
$acf_object = $field;
|
||||||
@@ -92,40 +104,15 @@ function init_field_CIPF($acf_field_name, $acf_id) {
|
|||||||
if (empty($acf_object)) {
|
if (empty($acf_object)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//error_log("acf_object: " . json_encode($acf_object));
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* init with best value
|
* try to init with default value
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
$value = '';
|
|
||||||
$default = '';
|
|
||||||
$choice = '';
|
|
||||||
$should_init = false;
|
|
||||||
if (isset($acf_object['default_value'])) {
|
if (isset($acf_object['default_value'])) {
|
||||||
$default = $acf_object['default_value'];
|
$default = $acf_object['default_value'];
|
||||||
$should_init = true;
|
update_field($acf_field_name, $default, $acf_id);
|
||||||
}
|
}
|
||||||
if (isset($acf_object['choices'])) {
|
|
||||||
$choices = $acf_object['choices'];
|
|
||||||
if (!empty($choices)) {
|
|
||||||
$choice = reset($choices);
|
|
||||||
$should_init = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (false === $should_init) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// empty returns true for 0 and '0'
|
|
||||||
if ($default == 0 || !empty($default)) {
|
|
||||||
$value = $default;
|
|
||||||
}
|
|
||||||
else if ($choice == 0 || !empty($choice)) {
|
|
||||||
$value = $choice;
|
|
||||||
}
|
|
||||||
update_field($acf_field_name, $value, $acf_id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -135,47 +122,22 @@ function get_field_init_CIPF($acf_field_name, $acf_id) {
|
|||||||
|
|
||||||
init_field_CIPF($acf_field_name, $acf_id);
|
init_field_CIPF($acf_field_name, $acf_id);
|
||||||
|
|
||||||
$acf_state = get_field($acf_field_name, $acf_id);
|
$acf_values = get_field($acf_field_name, $acf_id);
|
||||||
|
|
||||||
return $acf_state;
|
return $acf_values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_field_object_init_CIPF($acf_field_name, $acf_id) {
|
||||||
|
|
||||||
/*
|
|
||||||
* global 'setter' and 'izzer' for this file
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function is_acf_field_CIPF($acf_field, $acf_value, $acf_id) {
|
|
||||||
Plgntls::debug_infos();
|
Plgntls::debug_infos();
|
||||||
|
|
||||||
/*
|
init_field_CIPF($acf_field_name, $acf_id);
|
||||||
* when acf fields have not been initated a first time, you can't find them by name
|
|
||||||
* - one solution is to use key instead
|
|
||||||
* but it means knowing the key, in my case it prevents fabien to create a field himself
|
|
||||||
* - another solution would be to :
|
|
||||||
* try if is null,
|
|
||||||
* if yes it means it was not initalize,
|
|
||||||
* then initalize with any value,
|
|
||||||
* find the default value,
|
|
||||||
* and assign it
|
|
||||||
*
|
|
||||||
$acf_state = get_field($acf_field['_key'], $acf_id);
|
|
||||||
*/
|
|
||||||
$acf_state = get_field_init_CIPF($acf_field['_name'], $acf_id);;
|
|
||||||
|
|
||||||
if (is_predefined_acf_state($acf_field, $acf_value)) {
|
$acf_object = get_field_object($acf_field_name, $acf_id);
|
||||||
$value = $acf_field[$acf_value];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$value = $acf_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($acf_state === $value) {
|
return $acf_object;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* some values are predefined in the plugin class for acf fields
|
* some values are predefined in the plugin class for acf fields
|
||||||
*
|
*
|
||||||
@@ -193,6 +155,51 @@ function is_predefined_acf_state($acf_field, $acf_value) {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* global 'setter' and 'izzer' for this file
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function is_acf_field_CIPF($acf_field, $acf_value, $acf_id) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
|
||||||
|
if (is_predefined_acf_state($acf_field, $acf_value)) {
|
||||||
|
$value = $acf_field[$acf_value];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$value = $acf_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* when acf fields have not been initated a first time, you can't find them by name
|
||||||
|
* it's ok if the field has no value, but it's not ok if the field has default value
|
||||||
|
* so we init it before
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$acf_state = get_acf_field_CIPF($acf_field, $acf_id);;
|
||||||
|
|
||||||
|
if (!is_array($acf_state)) {
|
||||||
|
if ($acf_state === $value) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if value is array
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$values = get_values_from_acf_field_CIPF($acf_field, $acf_value, $acf_id);
|
||||||
|
if (in_array($value, $values)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
function set_acf_field_CIPF($acf_field, $acf_value, $acf_id) {
|
function set_acf_field_CIPF($acf_field, $acf_value, $acf_id) {
|
||||||
Plgntls::debug_infos();
|
Plgntls::debug_infos();
|
||||||
$acf_history = Cipf::ACF_HISTORY;
|
$acf_history = Cipf::ACF_HISTORY;
|
||||||
@@ -237,10 +244,121 @@ function set_acf_field_CIPF($acf_field, $acf_value, $acf_id) {
|
|||||||
update_field($acf_history['_name'], $history, $acf_id);
|
update_field($acf_history['_name'], $history, $acf_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* get list of previous values as values, not label or array
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function get_values_from_acf_field_CIPF($acf_field, $acf_value, $acf_id) {
|
||||||
|
$raw_values = get_acf_field_CIPF($acf_field, $acf_id);
|
||||||
|
if (!is_array($raw_values)) {
|
||||||
|
set_acf_field_CIPF($acf_field, $acf_value, $acf_id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$acf_object = get_acf_field_object_CIPF($acf_field, $acf_id);
|
||||||
|
$return_format = $acf_object['return_format'];
|
||||||
|
$acf_choices = $acf_object['choices'];
|
||||||
|
|
||||||
|
$values = array();
|
||||||
|
if ($return_format === 'value') {
|
||||||
|
$values = $raw_values;
|
||||||
|
}
|
||||||
|
else if ($return_format === 'label') {
|
||||||
|
foreach ($acf_choices as $value => $label) {
|
||||||
|
if (in_array($label, $raw_values)) {
|
||||||
|
$values[] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ($return_format === 'array') {
|
||||||
|
foreach ($raw_values as $array) {
|
||||||
|
$values[] = $array['value'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $values;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* add this 'add' function, to not rewrite the working 'set' funciton at this state of the project
|
||||||
|
* it is useful for checkboxes
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function add_acf_field_CIPF($acf_field, $acf_value, $acf_id) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$acf_history = Cipf::ACF_HISTORY;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if acf_value is the name of a key in const acf_field,
|
||||||
|
* then we want to get its value from there,
|
||||||
|
* otherwise we just use it's value directly
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (is_predefined_acf_state($acf_field, $acf_value)) {
|
||||||
|
$value = $acf_field[$acf_value];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$value = $acf_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$values = get_values_from_acf_field_CIPF($acf_field, $acf_value, $acf_id);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* add new value, or do nothing if already there
|
||||||
|
* and set new value
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (in_array($acf_value, $values)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$values[] = $acf_value;
|
||||||
|
set_acf_field_CIPF($acf_field, $values, $acf_id);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* add this 'remove' function, to not rewrite the working 'set' funciton at this state of the project
|
||||||
|
* it is useful for checkboxes
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function remove_acf_field_CIPF($acf_field, $acf_value, $acf_id) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$acf_history = Cipf::ACF_HISTORY;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if acf_value is the name of a key in const acf_field,
|
||||||
|
* then we want to get its value from there,
|
||||||
|
* otherwise we just use it's value directly
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (is_predefined_acf_state($acf_field, $acf_value)) {
|
||||||
|
$value = $acf_field[$acf_value];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$value = $acf_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
$values = get_values_from_acf_field_CIPF($acf_field, $acf_value, $acf_id);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* remove new value, or do nothing if already not there
|
||||||
|
* and set new value
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (!in_array($acf_value, $values)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// produce array without $acf_value
|
||||||
|
$values = array_diff($values, array($acf_value));
|
||||||
|
// re-index array -> this: [0=>'element'] instead of this: ['1'=>'element']
|
||||||
|
$values = array_values($values);
|
||||||
|
set_acf_field_CIPF($acf_field, $values, $acf_id);
|
||||||
|
}
|
||||||
function get_acf_field_CIPF($acf_field, $acf_id) {
|
function get_acf_field_CIPF($acf_field, $acf_id) {
|
||||||
Plgntls::debug_infos();
|
Plgntls::debug_infos();
|
||||||
return get_field_init_CIPF($acf_field['_name'], $acf_id);
|
return get_field_init_CIPF($acf_field['_name'], $acf_id);
|
||||||
}
|
}
|
||||||
|
function get_acf_field_object_CIPF($acf_field, $acf_id) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
return get_field_object_init_CIPF($acf_field['_name'], $acf_id);
|
||||||
|
}
|
||||||
function isset_acf_field_CIPF($acf_field, $acf_id) {
|
function isset_acf_field_CIPF($acf_field, $acf_id) {
|
||||||
Plgntls::debug_infos();
|
Plgntls::debug_infos();
|
||||||
|
|
||||||
@@ -601,6 +719,72 @@ function reset_acf_cgv_CIPF($user_id = null) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* emails_reminders
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function get_emails_reminders_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$acf_emails_reminders = Cipf::ACF_EMAILS_REMINDERS;
|
||||||
|
|
||||||
|
if (is_null($user_id)) {
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
}
|
||||||
|
$acf_id = 'user_'.$user_id;
|
||||||
|
return get_acf_field_CIPF($acf_emails_reminders, $acf_id);
|
||||||
|
}
|
||||||
|
function get_emails_reminders_choices_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$acf_emails_reminders = Cipf::ACF_EMAILS_REMINDERS;
|
||||||
|
|
||||||
|
if (is_null($user_id)) {
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
}
|
||||||
|
$acf_id = 'user_'.$user_id;
|
||||||
|
$object = get_acf_field_object_CIPF($acf_emails_reminders, $acf_id);
|
||||||
|
return $object['choices'];
|
||||||
|
}
|
||||||
|
function set_email_reminder_choice_CIPF($value, $user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$acf_emails_reminders = Cipf::ACF_EMAILS_REMINDERS;
|
||||||
|
|
||||||
|
if (is_null($user_id)) {
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
}
|
||||||
|
$acf_id = 'user_'.$user_id;
|
||||||
|
add_acf_field_CIPF($acf_emails_reminders, $value, $acf_id);
|
||||||
|
}
|
||||||
|
function unset_email_reminder_choice_CIPF($value, $user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$acf_emails_reminders = Cipf::ACF_EMAILS_REMINDERS;
|
||||||
|
|
||||||
|
if (is_null($user_id)) {
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
}
|
||||||
|
$acf_id = 'user_'.$user_id;
|
||||||
|
remove_acf_field_CIPF($acf_emails_reminders, $value, $acf_id);
|
||||||
|
}
|
||||||
|
function is_email_reminder_choice_CIPF($value, $user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$acf_emails_reminders = Cipf::ACF_EMAILS_REMINDERS;
|
||||||
|
|
||||||
|
if (is_null($user_id)) {
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
}
|
||||||
|
$acf_id = 'user_'.$user_id;
|
||||||
|
return is_acf_field_CIPF($acf_emails_reminders, $value, $acf_id);
|
||||||
|
}
|
||||||
|
function reset_emails_reminders_choices_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$acf_emails_reminders = Cipf::ACF_EMAILS_REMINDERS;
|
||||||
|
|
||||||
|
if (is_null($user_id)) {
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
}
|
||||||
|
$acf_id = 'user_'.$user_id;
|
||||||
|
set_acf_field_CIPF($acf_emails_reminders, array(), $acf_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ function success_payment_for_user_CIPF($user_id, $order_id) {
|
|||||||
/*
|
/*
|
||||||
* else
|
* else
|
||||||
* order is important for some
|
* order is important for some
|
||||||
* -> first update date, then schedul events
|
* -> first update date, then the rest
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
update_card_date_expiration_CIPF($user_id);
|
update_card_date_expiration_CIPF($user_id);
|
||||||
@@ -182,6 +182,7 @@ function success_payment_for_user_CIPF($user_id, $order_id) {
|
|||||||
|
|
||||||
set_payment_success_CIPF($user_id);
|
set_payment_success_CIPF($user_id);
|
||||||
set_account_valid_CIPF($user_id);
|
set_account_valid_CIPF($user_id);
|
||||||
|
reset_emails_reminders_choices_CIPF($user_id);
|
||||||
send_emails_CIPF('payment_success', $user_id);
|
send_emails_CIPF('payment_success', $user_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ function handle_transfert_validation_CIPF($user_id) {
|
|||||||
update_card_date_expiration_CIPF($user_id);
|
update_card_date_expiration_CIPF($user_id);
|
||||||
set_card_number_CIPF($user_id);
|
set_card_number_CIPF($user_id);
|
||||||
set_card_renew_CIPF($user_id);
|
set_card_renew_CIPF($user_id);
|
||||||
|
reset_emails_reminders_choices_CIPF($user_id);
|
||||||
send_emails_CIPF('transfert_success', $user_id);
|
send_emails_CIPF('transfert_success', $user_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,20 +142,45 @@ function handle_reminders_before_card_expire_CIPF($user_id) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($card_reminders as $duration) {
|
$is_before_reminders = false;
|
||||||
$date_reminder = $date_limit->modify($duration);
|
$reminder_list = array();
|
||||||
$date_diff = date_diff($date_limit, $date_reminder);
|
foreach ($card_reminders as $reminder_key => $value) {
|
||||||
$date_diff = (int)$date_diff->format('%R%a');
|
$duration = get_duration_CIPF($reminder_key, 'card_expiration');
|
||||||
|
/*
|
||||||
|
* if false, this reminder is not for 'card_expiration'
|
||||||
|
* else, add to 'reminder_list'
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (false === $duration) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$reminder_list[] = $reminder_key;
|
||||||
|
|
||||||
$date_now = date_create('now');
|
$diff = compare_diff_with_today_CIPF($date_limit, $duration);
|
||||||
$current_date_diff = date_diff($date_limit, $date_now);
|
if ($diff > 0) {
|
||||||
$current_date_diff = (int)$current_date_diff->format('%R%a');
|
$is_before_reminders = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$is_before_reminders = false;
|
||||||
|
|
||||||
$diff = abs($current_date_diff - $date_diff);
|
if (is_email_reminder_choice_CIPF($reminder_key, $user_id)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
set_email_reminder_choice_CIPF($reminder_key, $user_id);
|
||||||
|
send_emails_CIPF('card_will_expire', $user_id);
|
||||||
|
return; // don't send multiple emails
|
||||||
|
}
|
||||||
|
|
||||||
if ($diff === 0) {
|
/*
|
||||||
// send_emails_CIPF('card_will_expire', $user_id);
|
* if didnt return, it either means that :
|
||||||
// return; // don't send multiple emails
|
* - today is before any reminder
|
||||||
|
* - today is after all reminders
|
||||||
|
* use 'is_before_reminders' to know
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if ($is_before_reminders) {
|
||||||
|
foreach ($reminder_list as $reminder) {
|
||||||
|
unset_email_reminder_choice_CIPF($reminder, $user_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -171,7 +197,6 @@ function handle_reminders_before_card_expire_CIPF($user_id) {
|
|||||||
*/
|
*/
|
||||||
function handle_reminders_before_account_deleted_CIPF($user_id) {
|
function handle_reminders_before_account_deleted_CIPF($user_id) {
|
||||||
Plgntls::debug_infos();
|
Plgntls::debug_infos();
|
||||||
$account_reminders = Cipf::DURATION_REMINDERS_BEFORE_ACCOUNT_DELETE;
|
|
||||||
$duration_deletion = Cipf::DURATION_ACCOUNT_DELETE_AFTER_EXPIRE;
|
$duration_deletion = Cipf::DURATION_ACCOUNT_DELETE_AFTER_EXPIRE;
|
||||||
|
|
||||||
if (!isset_acf_card_expiration_CIPF($user_id)) {
|
if (!isset_acf_card_expiration_CIPF($user_id)) {
|
||||||
@@ -186,23 +211,105 @@ function handle_reminders_before_account_deleted_CIPF($user_id) {
|
|||||||
}
|
}
|
||||||
$date_deletion = $date_limit->modify($duration_deletion);
|
$date_deletion = $date_limit->modify($duration_deletion);
|
||||||
|
|
||||||
foreach ($account_reminders as $reminder) {
|
|
||||||
$date_reminder = $date_deletion->modify($reminder);
|
|
||||||
$date_diff = date_diff($date_deletion, $date_reminder);
|
|
||||||
$date_diff = (int)$date_diff->format('%R%a');
|
|
||||||
|
|
||||||
$date_now = date_create('now');
|
$is_before_reminders = false;
|
||||||
$current_date_diff = date_diff($date_deletion, $date_now);
|
$reminder_list = array();
|
||||||
$current_date_diff = (int)$current_date_diff->format('%R%a');
|
/*
|
||||||
|
* get the acf reminders,
|
||||||
|
* - continue the ones not for account deletion
|
||||||
|
* - continue if date is not yet soon enough
|
||||||
|
* - continue if email was already sent
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$reminders_choices = get_emails_reminders_choices_CIPF($user_id);
|
||||||
|
foreach ($reminders_choices as $reminder_key => $value) {
|
||||||
|
$duration = get_duration_CIPF($reminder_key, 'account_deletion');
|
||||||
|
/*
|
||||||
|
* if false, this reminder is not for 'card_expiration'
|
||||||
|
* else, add to 'reminder_list'
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (false === $duration) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$reminder_list[] = $reminder_key;
|
||||||
|
|
||||||
// i add +3 in case there is a difference of maximum 3 days between a 31 days month and a 28 days february
|
$diff = compare_diff_with_today_CIPF($date_deletion, $duration);
|
||||||
if (abs($current_date_diff) <= (abs($date_diff) + 3)) {
|
if ($diff > 0) {
|
||||||
// send_emails_CIPF('account_will_be_deleted', $user_id);
|
$is_before_reminders = true;
|
||||||
// return; // don't send multiple emails
|
continue;
|
||||||
|
}
|
||||||
|
$is_before_reminders = false;
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if didnt return, it either means that :
|
||||||
|
* - today is before any reminder
|
||||||
|
* - today is after all reminders
|
||||||
|
* use 'is_before_reminders' to know
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if ($is_before_reminders) {
|
||||||
|
foreach ($reminder_list as $reminder) {
|
||||||
|
unset_email_reminder_choice_CIPF($reminder, $user_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* extract the duration
|
||||||
|
* returns false if not for the right type
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function get_duration_CIPF($reminder, $type) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
|
||||||
|
$explode_reminder = explode('/', $reminder);
|
||||||
|
$explode_reminder = array_map('trim', $explode_reminder);
|
||||||
|
if ($explode_reminder[0] !== $type) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$duration = $explode_reminder[1];
|
||||||
|
return $duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* find the diffs :
|
||||||
|
* - the intended diff between the deletion date and the reminder
|
||||||
|
* - the diff between the deletion date and today
|
||||||
|
* and return the difference
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function compare_diff_with_today_CIPF($date, $duration) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
|
||||||
|
$date_reminder = $date->modify($duration);
|
||||||
|
$date_diff = date_diff($date, $date_reminder);
|
||||||
|
$date_diff = (int)$date_diff->format('%R%a');
|
||||||
|
|
||||||
|
$date_now = date_create('now');
|
||||||
|
$current_date_diff = date_diff($date, $date_now);
|
||||||
|
$current_date_diff = (int)$current_date_diff->format('%R%a');
|
||||||
|
|
||||||
|
return ($date_diff - $current_date_diff);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
Reference in New Issue
Block a user