format('%R%a'); } /* * returns true if date is in paste or is empty * use is_card_date_exists_CIPF to check if the field is empty * */ function is_card_date_expired_CIPF($user_id = null) { Plgntls::debug_infos(); /* * define user_id * */ if (is_null($user_id)) { $user_id = get_current_user_id(); } /* * check if expired * */ $date_diff = card_date_diff_CIPF($user_id); if ($date_diff === false) { return true; } else if ($date_diff < 0) { return true; } return false; } /* * returns true if date is empty * */ function card_date_exists_CIPF($user_id = null) { Plgntls::debug_infos(); $acf_card_expiration = Cipf::ACF_CARD_EXPIRATION; /* * define ids * */ if (is_null($user_id)) { $user_id = get_current_user_id(); } $acf_id = 'user_'.$user_id; /* * get acf date field * */ $date_now = date_create('today'); // we dont use utility fonction 'get_acf_field_CIPF' because we want to know if it was not init. Do we ? $current_date = get_field($acf_card_expiration['_name'], $acf_id); if (empty($current_date)) { return false; } if (is_null($current_date)) { return false; } return true; } /* * will add card_duration to card * card_duration is expected in a string format : https://www.php.net/manual/en/class.dateinterval.php * */ function update_card_expiration_CIPF($user_id = null) { Plgntls::debug_infos(); $acf_card_expiration = Cipf::ACF_CARD_EXPIRATION; $card_duration = Cipf::CARD_VALIDITY_TIME; /* * define acf id and acf date format * */ if (is_null($user_id)) { $user_id = get_current_user_id(); } $acf_id = 'user_'.$user_id; $acf_date_format = 'Y-m-d H:i:s'; /* * get date limit as DateTime object * */ $current_date_limit = get_date_limit_CIPF($user_id); if ($current_date_limit === false) { $current_date_limit = date_create('today'); } /* * update date limit validity to add 1 year * */ $date_plus_one_year = $current_date_limit->add(date_interval_create_from_date_string('+'.$card_duration)); set_acf_field_CIPF($acf_card_expiration, $date_plus_one_year->format($acf_date_format), $acf_id); } ?>