'renouvellement' * */ set_account_valid_CIPF($user_id); update_card_date_expiration_CIPF($user_id); set_card_number_CIPF($user_id); set_card_renew_CIPF($user_id); reset_emails_reminders_choices_CIPF($acf_id); send_emails_CIPF('transfert_success', $user_id); } /* * if card expire, makes some changes * */ function handle_card_expire_CIPF($user_id) { Plgntls::debug_infos(); $acf_id = 'user_'.$user_id; if (false === isset_acf_card_expiration_CIPF($user_id)) { return; } if (is_card_date_expired_CIPF($user_id)) { if (is_account_waiting_transfert_CIPF($user_id)) { set_account_waiting_invalid_CIPF($user_id); } else { set_account_expired_CIPF($user_id); } if (!is_email_reminder_choice_CIPF('card_expired', $acf_id)) { set_email_reminder_choice_CIPF('card_expired', $acf_id); send_emails_CIPF('card_expired', $user_id); } } else { if (is_account_waiting_transfert_CIPF($user_id)) { set_account_waiting_valid_CIPF($user_id); } else { set_account_valid_CIPF($user_id); } reset_emails_reminders_box_CIPF('account_deletion', $acf_id); unset_email_reminder_choice_CIPF('card_expired', $acf_id); } } /* * 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)) { return; } send_emails_CIPF('account_deleted', $user_id); include_once(ABSPATH.'wp-admin/includes/user.php'); // dont delete, for log $user = get_user_by('id', $user_id); error_log("delete prof: " . $user->user_login); wp_delete_user($user_id); } /* * it should not be necessary, but just in case * ! no sens : it hooks after user is deleted, so images are already added to another user if they are not deleted * */ //function prof_deletion_ensure_images_are_deleted_CIPF($user_id, $reassign, $user) { // Plgntls::debug_infos(); // $role_prof = Cipf::ROLE_PROF; // // if (!in_array($role_prof, $user->roles)) { // return; // } // // $images = get_posts(array( // 'post_type' => 'attachment', // 'post_mime_type' => 'image', // 'posts_per_page' => -1, // 'author' => $user_id, // )); // if (empty($images)) { // return; // } // foreach ($images as $image) { // $image_id = $image->ID; // // Set the second argument to true to permanently delete the attachment // $result = wp_delete_attachment($image_id, true); // if ($result === false) { // error_log('- failed to delete image: ' . $image_id); // } // else { // error_log('- delete image: ' . $image_id); // } // } //} //add_action('deleted_user', 'prof_deletion_ensure_images_are_deleted_CIPF', 10, 3); /* * this function will check if users should be sent an email * to remind them of their card expiration date * */ function handle_reminders_before_card_expire_CIPF($user_id) { Plgntls::debug_infos(); $emails_reminders = Cipf:: ACF_EMAILS_REMINDERS; if (!isset_acf_card_expiration_CIPF($user_id)) { return; } if (is_card_date_expired_CIPF($user_id)) { return; } $date_limit = get_card_date_expiration_CIPF($user_id); if (false === $date_limit) { return; } handle_send_reminders_CIPF('user_'.$user_id, $user_id, $date_limit, 'card_expiration', 'card_will_expire'); } /* * this function will check if users should be sent an email * to remind them of their account beeing soon deleted * */ function handle_reminders_before_account_deleted_CIPF($user_id) { Plgntls::debug_infos(); $duration_deletion = Cipf::DURATION_ACCOUNT_DELETE_AFTER_EXPIRE; if (!isset_acf_card_expiration_CIPF($user_id)) { return; } $acf_id = 'user_'.$user_id; if (!is_card_date_expired_CIPF($user_id)) { reset_emails_reminders_box_CIPF('account_deletion', $acf_id); return; } $date_limit = get_card_date_expiration_CIPF($user_id); if (false === $date_limit) { return; } $date_deletion = $date_limit->modify($duration_deletion); handle_send_reminders_CIPF($acf_id, $user_id, $date_deletion, 'account_deletion', 'account_will_be_deleted'); } ?>