diff --git a/plugins/cipf_plugin/cipf_plugin.php b/plugins/cipf_plugin/cipf_plugin.php index d4d2b6c..9a73776 100644 --- a/plugins/cipf_plugin/cipf_plugin.php +++ b/plugins/cipf_plugin/cipf_plugin.php @@ -98,6 +98,7 @@ class Cipf { const ACF_PARTNER_OFFER_2_OUTPUT = ['_name'=>'afficher_offre_2', 'show'=>'Afficher', 'hide'=>'Masquer']; const ACF_PARTNER_OFFER_3_OUTPUT = ['_name'=>'afficher_offre_3', 'show'=>'Afficher', 'hide'=>'Masquer']; const ACF_READONLY_CLASS = 'readonly_acf'; + const ACF_DATE_FORMAT = 'Ymd'; // META const META_PAYEMENT_STATUS = 'cipf_payement_status'; diff --git a/plugins/cipf_plugin/php/_utils_acf_dates.php b/plugins/cipf_plugin/php/_utils_acf_dates.php index ec9e596..5c19a8c 100644 --- a/plugins/cipf_plugin/php/_utils_acf_dates.php +++ b/plugins/cipf_plugin/php/_utils_acf_dates.php @@ -18,6 +18,7 @@ if (!defined('ABSPATH')) { */ function get_date_CIPF($acf_date, $acf_id) { Plgntls::debug_infos(); + $acf_date_format = Cipf::ACF_DATE_FORMAT; /* * get acf date field @@ -36,11 +37,37 @@ function get_date_CIPF($acf_date, $acf_id) { // compare 2 dates : https://stackoverflow.com/q/8722806/9497573 // also I dont use strtotime to compare 2 ints, // because i don't know if it will fail one day (2000y bug style) - $current_date = date_create_immutable_from_format('Ymd', $current_date_string); + $current_date = date_create_immutable_from_format($acf_date_format, $current_date_string); if ($current_date === false) { return false; } +// /* +// * get acf date field +// * +// */ +// $current_date_object = get_field_object($acf_date['_name'], $acf_id); +// if (empty($current_date_object)) { +// return false; +// } +// if (empty($current_date_object['value'])) { +// return false; +// } +// +// /* +// * create date object from acf date +// * +// */ +// $current_date_string = $current_date_object['value']; +// $current_format_field = $current_date_object['return_format']; +// // compare 2 dates : https://stackoverflow.com/q/8722806/9497573 +// // also I dont use strtotime to compare 2 ints, +// // because i don't know if it will fail one day (2000y bug style) +// $current_date = date_create_immutable_from_format($current_format_field, $current_date_string); +// if ($current_date === false) { +// return false; +// } + /* * returns the date object * @@ -110,9 +137,9 @@ function get_new_date_CIPF($date, $duration) { */ function set_acf_date_CIPF($acf_date_field_to_update, $new_date, $user_id) { Plgntls::debug_infos(); + $acf_date_format = Cipf::ACF_DATE_FORMAT; $acf_id = 'user_'.$user_id; - $acf_date_format = 'Y-m-d H:i:s'; set_acf_field_CIPF($acf_date_field_to_update, $new_date->format($acf_date_format), $acf_id); } @@ -220,10 +247,13 @@ function is_prof_account_deletion_date_exceeded_CIPF($user_id = null) { */ function get_offer_date_expiration_CIPF($offer_number, $page_id) { Plgntls::debug_infos(); + $acf_date_format = Cipf::ACF_DATE_FORMAT; + + $acf_field_name = 'fin_offre_'.$offer_number; + + $current_date_expiration = get_field($acf_field_name, $page_id, false); + $date_expiration = date_create_immutable_from_format($acf_date_format, $current_date_expiration); - // last parameter is false to not format the date, and get the 'Ymd' format - $offer_expiration = get_field('fin_offre_'.$offer_number, $page_id, false); - $date_expiration = date_create_immutable_from_format('Ymd', $offer_expiration); return $date_expiration; } function is_offer_date_exceeded_CIPF($offer_number, $page_id) {