event delete

This commit is contained in:
asus
2024-04-09 20:43:47 +02:00
parent e77e41073f
commit e48eb9cb51
4 changed files with 46 additions and 28 deletions

View File

@@ -4,7 +4,7 @@ Plugin Name: hggg_cipf
Plugin URI:
Description:
Author: hugogogo
Version: 0.5.6
Version: 0.5.7
Author URI:
*/

View File

@@ -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');

View File

@@ -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);
}

View File

@@ -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);