From e48eb9cb51ed965d0247cffce378d3e875dc7add Mon Sep 17 00:00:00 2001 From: asus Date: Tue, 9 Apr 2024 20:43:47 +0200 Subject: [PATCH] event delete --- plugins/cipf_plugin/cipf_plugin.php | 2 +- .../php/_actions_scheduled_events.php | 57 +++++++++++++------ plugins/cipf_plugin/php/_utils_acf_dates.php | 12 ++-- plugins/cipf_plugin/php/profs_profil.php | 3 +- 4 files changed, 46 insertions(+), 28 deletions(-) diff --git a/plugins/cipf_plugin/cipf_plugin.php b/plugins/cipf_plugin/cipf_plugin.php index d2ab2e7..b3b89f8 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.7 Author URI: */ diff --git a/plugins/cipf_plugin/php/_actions_scheduled_events.php b/plugins/cipf_plugin/php/_actions_scheduled_events.php index 1b32635..4b5a016 100644 --- a/plugins/cipf_plugin/php/_actions_scheduled_events.php +++ b/plugins/cipf_plugin/php/_actions_scheduled_events.php @@ -83,25 +83,46 @@ add_action('orderid_deletion_event_CIPF', 'delete_order_id_later_CIPF', 10, 2); */ function schedule_prof_account_deletion_CIPF($user_id) { Plgntls::debug_infos(); -// $duration_deletion = Cipf::DURATION_ACCOUNT_DELETE_AFTER_EXPIRE; -// -// $date_limit = get_card_date_expiration_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)); + $duration_deletion = Cipf::DURATION_ACCOUNT_DELETE_AFTER_EXPIRE; + + $date_limit = get_card_date_expiration_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_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_prof_account_deletion_CIPF', 'event_prof_account_deletion_CIPF'); +/* +* this function will delete the account if the deletion date is expired +* it is called both by e scheduled event, and every time a prof go on its page +* +*/ +function handle_prof_account_deletion_CIPF($user_id) { + Plgntls::debug_infos(); + + /* + * check if account still exists + * + */ + if (false === get_user_by('id', $user_id)) { + return; + } + + /* + * check if account should be deleted + * + */ + if (!is_prof_account_deletion_date_exceeded_CIPF($user_id)) { + error_log("dont delete yet"); + return; + } + error_log("delete now !"); + + include_once(ABSPATH.'wp-admin/includes/user.php'); + wp_delete_user($user_id); +} +add_action('schedule_event_prof_account_deletion_CIPF', 'handle_prof_account_deletion_CIPF'); diff --git a/plugins/cipf_plugin/php/_utils_acf_dates.php b/plugins/cipf_plugin/php/_utils_acf_dates.php index 9380930..c119efc 100644 --- a/plugins/cipf_plugin/php/_utils_acf_dates.php +++ b/plugins/cipf_plugin/php/_utils_acf_dates.php @@ -59,7 +59,7 @@ function get_date_CIPF($acf_date, $user_id) { * returns true if date is in paste or is empty * */ -function is_date_expired_CIPF($date) { +function is_date_exceeded_CIPF($date) { Plgntls::debug_infos(); if (empty($date)) { @@ -159,7 +159,7 @@ function is_card_date_expired_CIPF($user_id = null) { } $card_date = get_card_date_expiration_CIPF($user_id); - return is_date_expired_CIPF($card_date); + return is_date_exceeded_CIPF($card_date); } function isset_acf_card_expiration_CIPF($user_id = null) { Plgntls::debug_infos(); @@ -192,10 +192,6 @@ function update_card_date_expiration_CIPF($user_id = null) { /* * prof account deletion - -- get prof deletion date -- is prof deletion date expired - * */ function get_prof_accound_deletion_date_CIPF($user_id = null) { @@ -208,7 +204,7 @@ function get_prof_accound_deletion_date_CIPF($user_id = null) { $card_expiration_date = get_card_date_expiration_CIPF($user_id); return get_new_date_CIPF($card_expiration_date, $delete_duration); } -function is_prof_account_deletion_expired_CIPF($user_id = null) { +function is_prof_account_deletion_date_exceeded_CIPF($user_id = null) { Plgntls::debug_infos(); if (is_null($user_id)) { @@ -216,7 +212,7 @@ function is_prof_account_deletion_expired_CIPF($user_id = null) { } $account_date = get_prof_accound_deletion_date_CIPF($user_id); - return is_date_expired_CIPF($account_date); + return is_date_exceeded_CIPF($account_date); } diff --git a/plugins/cipf_plugin/php/profs_profil.php b/plugins/cipf_plugin/php/profs_profil.php index 3ef63ad..549dd97 100644 --- a/plugins/cipf_plugin/php/profs_profil.php +++ b/plugins/cipf_plugin/php/profs_profil.php @@ -52,11 +52,12 @@ function prof_profil_check_CIPF() { $author_id = get_queried_object_id(); /* - * in case event didn't fire, handle card changes + * in case event didn't fire, handle changes * */ handle_transfert_validation_CIPF($author_id); handle_card_expire_CIPF($author_id); + handle_prof_account_deletion_CIPF($author_id); } add_action('wp', 'prof_profil_check_CIPF', 11);