From 36dc26817a1432f6111fae714fc426b3caec4da9 Mon Sep 17 00:00:00 2001 From: asus Date: Tue, 9 Apr 2024 11:46:08 +0200 Subject: [PATCH] cipf v 0.5.5 added history and order id acf --- plugins/cipf_plugin/cipf_plugin.php | 5 +- .../php/_actions_scheduled_events.php | 59 +++--- plugins/cipf_plugin/php/_utils_acf_fields.php | 28 +++ .../cipf_plugin/php/paypal/user_can_pay.php | 2 +- plugins/cipf_plugin/php/profs_dates.php | 2 +- ç | 197 ------------------ 6 files changed, 57 insertions(+), 236 deletions(-) delete mode 100644 ç diff --git a/plugins/cipf_plugin/cipf_plugin.php b/plugins/cipf_plugin/cipf_plugin.php index 0a32a52..f95fdc3 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.4 +Version: 0.5.5 Author URI: */ @@ -83,6 +83,7 @@ class Cipf { const ACF_PAGE_STATE = ['_name'=>'etat_page_partenaire', 'publish'=>'Publiee', 'draft'=>'Brouillon']; const ACF_CARD_ORDER_ID = ['_name'=>'order_id']; const ACF_HISTORY = ['_name'=>'history']; + const ACF_PROF_DELETE_ACCOUNT = ['_name'=>'date_suppression_compte']; // META const META_PAYEMENT_STATUS = 'cipf_payement_status'; @@ -133,7 +134,7 @@ class Cipf { // SCHEDULED EVENTS const DURATION_OLD_ORDER_ID = '3 days'; - const DURATION_ACCOUNT_DELETE_AFTER_EXPIRE = '6 months'; + const DURATION_ACCOUNT_DELETE_AFTER_EXPIRE = '+6 months'; const DURATION_REMINDER_BEFORE_ACCOUNT_EXPIRE_FIRST = '1 month'; const DURATION_REMINDER_BEFORE_ACCOUNT_EXPIRE_LAST = '7 days'; const DURATION_REMINDER_BEFORE_ACCOUNT_DELETE_FIRST = '1 month'; diff --git a/plugins/cipf_plugin/php/_actions_scheduled_events.php b/plugins/cipf_plugin/php/_actions_scheduled_events.php index 458b2ce..809b2cb 100644 --- a/plugins/cipf_plugin/php/_actions_scheduled_events.php +++ b/plugins/cipf_plugin/php/_actions_scheduled_events.php @@ -53,12 +53,14 @@ if (!defined('ABSPATH')) { * after 3 days ? * */ -function schedule_delete_orderid_CIPF($user_id, $order_id) { +function schedule_delete_orderid_CIPF($order_id, $user_id) { Plgntls::debug_infos(); - $delay = strtotime('+3 days'); - wp_schedule_single_event($delay, 'orderid_deletion_event_CIPF', array($user_id, $order_id)); + $duration_order_id = Cipf::DURATION_OLD_ORDER_ID; + + $delay = strtotime($duration_order_id); + wp_schedule_single_event($delay, 'orderid_deletion_event_CIPF', array($order_id, $user_id)); } -function delete_order_id_later_CIPF($user_id, $order_id) { +function delete_order_id_later_CIPF($order_id, $user_id) { Plgntls::debug_infos(); if (!isset_acf_order_id_CIPF($user_id)) { @@ -76,43 +78,30 @@ add_action('orderid_deletion_event_CIPF', 'delete_order_id_later_CIPF', 10, 2); /* * 2. prof, suppress account XX time after expiration, also email +* need to include file for wp_delete_user to work : https://developer.wordpress.org/reference/functions/wp_delete_user/ * */ -function schedule_prof_account_suppression_CIPF($user_id) { +function schedule_prof_account_deletion_CIPF($user_id) { Plgntls::debug_infos(); - $duration_deletion = Cipf::DURATION_ACCOUNT_DELETE_AFTER_EXPIRE; - $date_limit = get_date_limit_CIPF($user_id); - $time_limit = $date_limit->getTimestamp(); - //$date_interval = date_interval_create_from_date_string($duration_deletion); - //$date_deletion = $date_limit->add($date_interval); - $date_deletion = $date_limit->modify('+'.$duration_deletion); - $time_deletion = $date_deletion->getTimestamp(); -//error_log("duration_deletion: " . json_encode($duration_deletion)); -//error_log("date_limit : " . json_encode($date_limit)); -//error_log("time_limit : " . json_encode($time_limit)); -////error_log("date_interval: " . json_encode($date_interval)); -//error_log("date_deletion: " . json_encode($date_deletion)); -//error_log("time_deletion: " . json_encode($time_deletion)); -/* -duration_deletion: "6 months" -date_limit : {"date":"2094-09-19 15:33:35.000000","timezone_type":3,"timezone":"UTC"} -time_limit : 3919851215 -date_deletion: {"date":"2094-09-19 15:33:35.000000","timezone_type":3,"timezone":"UTC"} -time_deletion: 3935748815 - -duration_deletion: "6 months" -date_limit : {"date":"2094-09-19 15:32:03.000000","timezone_type":3,"timezone":"UTC"} -time_limit : 3919851123 -date_deletion: {"date":"2094-09-19 15:32:03.000000","timezone_type":3,"timezone":"UTC"} -time_deletion: 3935748723 -*/ - //$delay = strtotime('+3 days'); -// wp_schedule_single_event($delay, 'scedule_event_CIPF', array($user_id)); +// $duration_deletion = Cipf::DURATION_ACCOUNT_DELETE_AFTER_EXPIRE; +// +// $date_limit = get_date_limit_CIPF($user_id); +// if (false === $date_limit) { +// return; +// } +// $date_limit->modify($duration_deletion); +// $delay = $date_limit->getTimestamp(); +// wp_schedule_single_event($delay, 'schedule_event_prof_account_deletion_CIPF', array($user_id)); } -//function event_CIPF($user_id) { +//function event_prof_account_deletion_CIPF($user_id) { // Plgntls::debug_infos(); +// if (false === get_user_by('id', $user_id)) { +// return; +// } +// include_once(ABSPATH.'wp-admin/includes/user.php'); +// wp_delete_user($user_id); //} -//add_action('schedule_event_CIPF', 'event_CIPF', 10, 2); +//add_action('schedule_event_prof_account_deletion_CIPF', 'event_prof_account_deletion_CIPF'); diff --git a/plugins/cipf_plugin/php/_utils_acf_fields.php b/plugins/cipf_plugin/php/_utils_acf_fields.php index 0a9e793..7a3b96b 100644 --- a/plugins/cipf_plugin/php/_utils_acf_fields.php +++ b/plugins/cipf_plugin/php/_utils_acf_fields.php @@ -46,6 +46,8 @@ if (!defined('ABSPATH')) { * * [/] card expiration date ('fin_de_validite') * +* [/] prof deletion date ('date_suppression_compte') +* * */ @@ -160,6 +162,12 @@ function set_acf_field_CIPF($acf_field, $acf_value, $acf_id) { * */ $new_value = get_acf_field_CIPF($acf_field, $acf_id); + if (!is_string($old_value)) { + $old_value = json_encode($old_value); + } + if (!is_string($new_value)) { + $new_value = json_encode($new_value); + } if ($new_value !== $old_value) { $old_history = get_acf_field_CIPF($acf_history, $acf_id); $france_timezone = new DateTimeZone("Europe/Paris"); @@ -556,6 +564,26 @@ function isset_acf_card_expiration_CIPF($user_id = null) { + +/* +* date_suppression_compte +* +*/ +function isset_acf_prof_account_delete_CIPF($user_id = null) { + Plgntls::debug_infos(); + $acf_prof_delete = Cipf::ACF_PROF_DELETE_ACCOUNT; + + if (is_null($user_id)) { + $user_id = get_current_user_id(); + } + $acf_id = 'user_'.$user_id; + return isset_acf_field_CIPF($acf_prof_delete, $acf_id); +} + + + + + /* * order_id * diff --git a/plugins/cipf_plugin/php/paypal/user_can_pay.php b/plugins/cipf_plugin/php/paypal/user_can_pay.php index 6683279..8e47a64 100644 --- a/plugins/cipf_plugin/php/paypal/user_can_pay.php +++ b/plugins/cipf_plugin/php/paypal/user_can_pay.php @@ -56,7 +56,7 @@ function check_can_pay_CIPF() { -schedule_prof_account_suppression_CIPF($user_id); +schedule_prof_account_deletion_CIPF($user_id); /* * check if payment is virement or immediat diff --git a/plugins/cipf_plugin/php/profs_dates.php b/plugins/cipf_plugin/php/profs_dates.php index 780e75d..10e24f9 100644 --- a/plugins/cipf_plugin/php/profs_dates.php +++ b/plugins/cipf_plugin/php/profs_dates.php @@ -95,7 +95,7 @@ function card_date_diff_CIPF($user_id = null) { /* * returns true if date is in paste or is empty -* use is_card_date_exists_CIPF to check if the field is empty +* use card_date_exists_CIPF to check if the field is empty * */ function is_card_date_expired_CIPF($user_id = null) { diff --git a/ç b/ç deleted file mode 100644 index 0e4beb8..0000000 --- a/ç +++ /dev/null @@ -1,197 +0,0 @@ - https://www.php.net/manual/en/function.strtotime.php -* or the time constants in seconds : -* - time() + 3 * MINUTE_IN_SECONDS -* -> https://codex.wordpress.org/Easier_Expression_of_Time_Constants -* -*/ - -/* -* events and emails : -* -* 1. [/] payments : TIME_OLD_ORDER_ID - suppress old order_ids -* 2. [ ] prof (email) : TIME_ACCOUNT_DELETE_AFTER_EXPIRE - schedule event to suppress the account xx time (6 month ?) after end of validity of the card, and supress the codes -* 3. [ ] prof (email) : - schedule event to deactivate the card -* 4. [ ] prof (email) : TIME_REMINDER_BEFORE_ACCOUNT_EXPIRE_FIRST - send emails reminder before account deactivate -* 5. [ ] prof (email) : TIME_REMINDER_BEFORE_ACCOUNT_EXPIRE_LAST - send emails reminder before account deactivate -* 6. [ ] prof (email) : TIME_REMINDER_BEFORE_ACCOUNT_DELETE_FIRST - send emails reminder before account delete -* 7. [ ] prof (email) : TIME_REMINDER_BEFORE_ACCOUNT_DELETE_LAST - send emails reminder before account delete -* 8. [ ] partner (email) : TIME_REMINDER_BEFORE_OFFER_EXPIRE - send emails reminder before offer ends -* 9. [ ] partners (email) : - temp offers -> make them disappeay after end card validity -> put them in hidden -* -*/ - - - - -/* -* 1. prof, add a schedule event to delete this order_id -* after 3 days ? -* -*/ -function schedule_delete_orderid_CIPF($user_id, $order_id) { - Plgntls::debug_infos(); - $delay = strtotime('+3 days'); - wp_schedule_single_event($delay, 'orderid_deletion_event_CIPF', array($user_id, $order_id)); -} -function delete_order_id_later_CIPF($user_id, $order_id) { - Plgntls::debug_infos(); - delete_user_meta($user_id, 'cipf_order_id', $order_id); -} -add_action('orderid_deletion_event_CIPF', 'delete_order_id_later_CIPF', 10, 2); - - - - -/* -* 2. prof, suppress account XX time after expiration, also email -* -*/ -function schedule_prof_account_suppression_CIPF($user_id) { - Plgntls::debug_infos(); - $duration_deletion = Cipf::DURATION_ACCOUNT_DELETE_AFTER_EXPIRE; - $date_limit = get_date_limit_CIPF($user_id); - $time_limit = $date_limit->getTimestamp(); - //$date_interval = date_interval_create_from_date_string($duration_deletion); - //$date_deletion = $date_limit->add($date_interval); - $date_deletion = $date_limit->modify($duration_deletion); - $time_deletion = $date_deletion->getTimestamp(); -error_log("duration_deletion: " . json_encode($duration_deletion)); -error_log("date_limit : " . json_encode($date_limit)); -//error_log("date_interval: " . json_encode($date_interval)); -error_log("date_deletion: " . json_encode($date_deletion)); -error_log("time_deletion: " . json_encode($time_deletion)); -/* - -duration_deletion: "6 months" -date_limit : {"date":"2094-09-19 15:30:29.000000","timezone_type":3,"timezone":"UTC"} -date_deletion: {"date":"2094-09-19 15:30:29.000000","timezone_type":3,"timezone":"UTC"} -time_deletion: 3935748629 -*/ - //$delay = strtotime('+3 days'); -// wp_schedule_single_event($delay, 'scedule_event_CIPF', array($user_id)); -} -//function event_CIPF($user_id) { -// Plgntls::debug_infos(); -//} -//add_action('schedule_event_CIPF', 'event_CIPF', 10, 2); - - - - -/* -* 3. prof, deactivate card at expiration time, also email -* -function schedule__CIPF($user_id) { - Plgntls::debug_infos(); - $delay = strtotime('+3 days'); - wp_schedule_single_event($delay, 'scedule_event_CIPF', array($user_id)); -} -function event_CIPF($user_id) { - Plgntls::debug_infos(); -} -add_action('schedule_event_CIPF', 'event_CIPF', 10, 2); -*/ - - - - -/* -* 4. && 5. prof, send email reminder before account expire -* -function schedule__CIPF($user_id) { - Plgntls::debug_infos(); - $delay = strtotime('+3 days'); - wp_schedule_single_event($delay, 'scedule_event_CIPF', array($user_id)); -} -function event_CIPF($user_id) { - Plgntls::debug_infos(); -} -add_action('schedule_event_CIPF', 'event_CIPF', 10, 2); -*/ - - - - -/* -* 6. && 7. prof, send email reminder account deletion -* -function schedule__CIPF($user_id) { - Plgntls::debug_infos(); - $delay = strtotime('+3 days'); - wp_schedule_single_event($delay, 'scedule_event_CIPF', array($user_id)); -} -function event_CIPF($user_id) { - Plgntls::debug_infos(); -} -add_action('schedule_event_CIPF', 'event_CIPF', 10, 2); -*/ - - - - -/* -* 8. partner, send email before offer expire -* -function schedule__CIPF($user_id) { - Plgntls::debug_infos(); - $delay = strtotime('+3 days'); - wp_schedule_single_event($delay, 'scedule_event_CIPF', array($user_id)); -} -function event_CIPF($user_id) { - Plgntls::debug_infos(); -} -add_action('schedule_event_CIPF', 'event_CIPF', 10, 2); -*/ - - - - -/* -* 9. partner, handle offer expire, also sens email -* -function schedule__CIPF($user_id) { - Plgntls::debug_infos(); - $delay = strtotime('+3 days'); - wp_schedule_single_event($delay, 'scedule_event_CIPF', array($user_id)); -} -function event_CIPF($user_id) { - Plgntls::debug_infos(); -} -add_action('schedule_event_CIPF', 'event_CIPF', 10, 2); -*/ - - - - - - - - - - -?>