diff --git a/plugins/cipf_plugin/cipf_plugin.php b/plugins/cipf_plugin/cipf_plugin.php index 822fa29..ca05d73 100644 --- a/plugins/cipf_plugin/cipf_plugin.php +++ b/plugins/cipf_plugin/cipf_plugin.php @@ -4,7 +4,7 @@ Plugin Name: hggg_cipf Plugin URI: Description: Author: hugogogo -Version: 0.5.6 +Version: 0.5.6.1 Author URI: */ @@ -84,6 +84,7 @@ class Cipf { const ACF_HISTORY = ['_name'=>'historique']; const ACF_PROF_CHANGE_CARD = ['_name'=>'changement_de_carte']; const ACF_PAGE_STATE = ['_name'=>'etat_page_partenaire', 'publish'=>'Publiee', 'draft'=>'Brouillon']; + const ACF_EMAILS_REMINDERS = ['_name'=>'rappels_emails']; const ACF_PARTNER_DATE_OFFER_1 = ['_name'=>'fin_offre_1']; const ACF_PARTNER_DATE_OFFER_2 = ['_name'=>'fin_offre_2']; const ACF_PARTNER_DATE_OFFER_3 = ['_name'=>'fin_offre_3']; diff --git a/plugins/cipf_plugin/php/_utils_acf_fields.php b/plugins/cipf_plugin/php/_utils_acf_fields.php index 729198b..90e4404 100644 --- a/plugins/cipf_plugin/php/_utils_acf_fields.php +++ b/plugins/cipf_plugin/php/_utils_acf_fields.php @@ -52,39 +52,89 @@ if (!defined('ABSPATH')) { */ +/* +i* try to init acf value with +* - default value +* - 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) { + Plgntls::debug_infos(); + + /* + * check if need to init + * + */ + $acf_value = get_field($acf_field_name, $acf_id); + if ($acf_value !== null) { + return; + } + + + /* + * if need to init, check if exists + * + */ + $acf_groups = acf_get_field_groups(); + + $acf_object = null; + foreach ($acf_groups as $group) { + error_log("group: " . json_encode($group)); + foreach (acf_get_fields($group['key']) as $field_key => $field) { + if ($field['_name'] === $acf_field_name) { + $acf_object = $field; + } + } + } + if (empty($acf_object)) { + return; + } + //error_log("acf_object: " . json_encode($acf_object)); + + /* + * init with best value + * + */ + $value = ''; + $default = ''; + $choice = ''; + $should_init = false; + if (isset($acf_object['default_value'])) { + $default = $acf_object['default_value']; + $should_init = true; + } + 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); +} + function get_field_init_CIPF($acf_field_name, $acf_id) { Plgntls::debug_infos(); - $acf_state = get_field($acf_field_name, $acf_id); - if ($acf_state !== null) { - return $acf_state; - } + init_field_CIPF($acf_field_name, $acf_id); - /* - * if get_field returns null, it means it is not initialized - * - initialize it with 'temp' value - * - then find it's default value, and update with it - * - if no default value, update with first value - * - */ - update_field($acf_field_name, '', $acf_id); - $acf_object = get_field_object($acf_field_name, $acf_id); - - - $default = ''; - if (isset($acf_object['default_value'])) { - $default = $acf_object['default_value']; - } - else if (isset($acf_object['choices'])) { - $choices = $acf_object['choices']; - if (!empty($choices)) { - $default = reset($choices); - } - } - - update_field($acf_field_name, $default, $acf_id); $acf_state = get_field($acf_field_name, $acf_id); return $acf_state; diff --git a/plugins/cipf_plugin/php/partners_page.php b/plugins/cipf_plugin/php/partners_page.php index ba701f1..6da7e6e 100644 --- a/plugins/cipf_plugin/php/partners_page.php +++ b/plugins/cipf_plugin/php/partners_page.php @@ -56,6 +56,7 @@ function partner_page_init_CIPF() { } Plgntls::debug_infos(); + // https://developer.wordpress.org/reference/functions/get_query_var/#more-information global $wp; $wp->add_query_var('action'); diff --git a/plugins/cipf_plugin/php/profs_handle_states.php b/plugins/cipf_plugin/php/profs_handle_states.php index 919303e..bbebca2 100644 --- a/plugins/cipf_plugin/php/profs_handle_states.php +++ b/plugins/cipf_plugin/php/profs_handle_states.php @@ -128,6 +128,7 @@ function handle_prof_account_deletion_CIPF($user_id) { function handle_reminders_before_card_expire_CIPF($user_id) { Plgntls::debug_infos(); $card_reminders = Cipf::DURATION_REMINDERS_BEFORE_ACCOUNT_EXPIRE; + $emails_reminders = Cipf:: ACF_EMAILS_REMINDERS; if (!isset_acf_card_expiration_CIPF($user_id)) { return; @@ -151,9 +152,9 @@ function handle_reminders_before_card_expire_CIPF($user_id) { $diff = abs($current_date_diff - $date_diff); - if ($diff === 0)) { - 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); + // return; // don't send multiple emails } } } @@ -196,8 +197,8 @@ function handle_reminders_before_account_deleted_CIPF($user_id) { // i add +3 in case there is a difference of maximum 3 days between a 31 days month and a 28 days february if (abs($current_date_diff) <= (abs($date_diff) + 3)) { - send_emails_CIPF('account_will_be_deleted', $user_id); - return; // don't send multiple emails + // send_emails_CIPF('account_will_be_deleted', $user_id); + // return; // don't send multiple emails } } }