cipf v 0.5.8 handle partner events
This commit is contained in:
@@ -4,7 +4,7 @@ Plugin Name: hggg_cipf
|
||||
Plugin URI:
|
||||
Description:
|
||||
Author: hugogogo
|
||||
Version: 0.5.7
|
||||
Version: 0.5.8
|
||||
Author URI:
|
||||
*/
|
||||
|
||||
@@ -38,6 +38,7 @@ include_once(Plgntls::root_path() . 'php/profs_handle_states.php');
|
||||
include_once(Plgntls::root_path() . 'php/partners_register.php');
|
||||
include_once(Plgntls::root_path() . 'php/partners_page.php');
|
||||
include_once(Plgntls::root_path() . 'php/partners_form.php');
|
||||
include_once(Plgntls::root_path() . 'php/partners_handle_offers.php');
|
||||
// utils
|
||||
include_once(Plgntls::root_path() . 'php/_utils_acf_fields.php');
|
||||
include_once(Plgntls::root_path() . 'php/_utils_acf_dates.php');
|
||||
@@ -88,9 +89,12 @@ class Cipf {
|
||||
const ACF_PARTNER_DATE_OFFER_1 = ['_name'=>'fin_offre_1'];
|
||||
const ACF_PARTNER_DATE_OFFER_2 = ['_name'=>'fin_offre_2'];
|
||||
const ACF_PARTNER_DATE_OFFER_3 = ['_name'=>'fin_offre_3'];
|
||||
const ACF_PARTNER_OFFER_1_DURATION = ['_name'=>'duree_offre_1', 'no-end'=>'Permanente', 'end'=>'Temporaire'];
|
||||
const ACF_PARTNER_OFFER_2_DURATION = ['_name'=>'duree_offre_2', 'no-end'=>'Permanente', 'end'=>'Temporaire'];
|
||||
const ACF_PARTNER_OFFER_3_DURATION = ['_name'=>'duree_offre_3', 'no-end'=>'Permanente', 'end'=>'Temporaire'];
|
||||
const ACF_PARTNER_OFFER_1_DURATION = ['_name'=>'duree_offre_1', 'endless'=>'Permanente', 'tmp'=>'Temporaire'];
|
||||
const ACF_PARTNER_OFFER_2_DURATION = ['_name'=>'duree_offre_2', 'endless'=>'Permanente', 'tmp'=>'Temporaire'];
|
||||
const ACF_PARTNER_OFFER_3_DURATION = ['_name'=>'duree_offre_3', 'endless'=>'Permanente', 'tmp'=>'Temporaire'];
|
||||
const ACF_PARTNER_OFFER_1_OUTPUT = ['_name'=>'afficher_offre_1', 'show'=>'Afficher', 'hide'=>'Masquer'];
|
||||
const ACF_PARTNER_OFFER_2_OUTPUT = ['_name'=>'afficher_offre_2', 'show'=>'Afficher', 'hide'=>'Masquer'];
|
||||
const ACF_PARTNER_OFFER_3_OUTPUT = ['_name'=>'afficher_offre_3', 'show'=>'Afficher', 'hide'=>'Masquer'];
|
||||
|
||||
// META
|
||||
const META_PAYEMENT_STATUS = 'cipf_payement_status';
|
||||
|
||||
@@ -110,4 +110,91 @@ function send_emails_CIPF($email_name, $user_id = null) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* get the acf reminders,
|
||||
* - continue the ones not for the reminder_type
|
||||
* - continue if date is not yet soon enough
|
||||
* - continue if email was already sent
|
||||
*
|
||||
*/
|
||||
function handle_send_reminders_CIPF($acf_id, $user_id, $date_limit, $reminder_type, $email_type) {
|
||||
$is_before_reminders = true;
|
||||
$reminders_choices = get_emails_reminders_choices_CIPF($acf_id);
|
||||
foreach ($reminders_choices as $reminder_key => $value) {
|
||||
$duration = get_duration_CIPF($reminder_key, $reminder_type);
|
||||
if (false === $duration) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$diff = compare_diff_with_today_CIPF($date_limit, $duration);
|
||||
if ($diff > 0) {
|
||||
continue;
|
||||
}
|
||||
$is_before_reminders = false;
|
||||
|
||||
if (is_email_reminder_choice_CIPF($reminder_key, $acf_id)) {
|
||||
continue;
|
||||
}
|
||||
set_email_reminder_choice_CIPF($reminder_key, $acf_id);
|
||||
send_emails_CIPF($email_type, $user_id);
|
||||
return; // don't send multiple emails
|
||||
}
|
||||
|
||||
/*
|
||||
* if didnt return, it either means that :
|
||||
* - today is before any reminder
|
||||
* - today is after all reminders
|
||||
* use 'is_before_reminders' to know
|
||||
*
|
||||
*/
|
||||
if ($is_before_reminders) {
|
||||
reset_emails_reminders_box_CIPF($reminder_type, $acf_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* extract the duration
|
||||
* returns false if not for the right type
|
||||
*
|
||||
*/
|
||||
function get_duration_CIPF($reminder, $type) {
|
||||
Plgntls::debug_infos();
|
||||
|
||||
$explode_reminder = explode('/', $reminder);
|
||||
$explode_reminder = array_map('trim', $explode_reminder);
|
||||
if ($explode_reminder[0] !== $type) {
|
||||
return false;
|
||||
}
|
||||
$duration = $explode_reminder[1];
|
||||
return $duration;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* find the diffs :
|
||||
* - the intended diff between the deletion date and the reminder
|
||||
* - the diff between the deletion date and today
|
||||
* and return the difference
|
||||
*
|
||||
*/
|
||||
function compare_diff_with_today_CIPF($date, $duration) {
|
||||
Plgntls::debug_infos();
|
||||
|
||||
$date_reminder = $date->modify($duration);
|
||||
$date_diff = date_diff($date, $date_reminder);
|
||||
$date_diff = (int)$date_diff->format('%R%a');
|
||||
|
||||
$date_now = date_create('now');
|
||||
$current_date_diff = date_diff($date, $date_now);
|
||||
$current_date_diff = (int)$current_date_diff->format('%R%a');
|
||||
|
||||
return ($date_diff - $current_date_diff);
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -222,38 +222,19 @@ function is_prof_account_deletion_date_exceeded_CIPF($user_id = null) {
|
||||
* partner offers
|
||||
*
|
||||
*/
|
||||
function get_partner_offer_1_date_CIPF($post_id) {
|
||||
function get_offer_date_expiration_CIPF($offer_number, $page_id) {
|
||||
Plgntls::debug_infos();
|
||||
$offer_1 = Cipf::ACF_PARTNER_DATE_OFFER_1;
|
||||
return get_date_CIPF($offer_1, $post_id);
|
||||
}
|
||||
function get_partner_offer_2_date_CIPF($post_id) {
|
||||
Plgntls::debug_infos();
|
||||
$offer_2 = Cipf::ACF_PARTNER_DATE_OFFER_2;
|
||||
return get_date_CIPF($offer_2, $post_id);
|
||||
}
|
||||
function get_partner_offer_3_date_CIPF($post_id) {
|
||||
Plgntls::debug_infos();
|
||||
$offer_3 = Cipf::ACF_PARTNER_DATE_OFFER_3;
|
||||
return get_date_CIPF($offer_3, $post_id);
|
||||
}
|
||||
|
||||
function is_activ_partner_offer_1_date_CIPF($post_id) {
|
||||
Plgntls::debug_infos();
|
||||
$offer_1_duration = Cipf::ACF_PARTNER_OFFER_1_DURATION;
|
||||
return is_acf_field_CIPF($offer_1_duration, 'end', $post_id);
|
||||
$offer_expiration = get_post_meta($page_id, 'fin_offre_'.$offer_number);
|
||||
$date_expiration = date_create_immutable_from_format('Ymd', $offer_expiration[0]);
|
||||
return $date_expiration;
|
||||
}
|
||||
function is_activ_partner_offer_2_date_CIPF($post_id) {
|
||||
function is_offer_date_exceeded_CIPF($offer_number, $page_id) {
|
||||
Plgntls::debug_infos();
|
||||
$offer_2_duration = Cipf::ACF_PARTNER_OFFER_2_DURATION;
|
||||
return is_acf_field_CIPF($offer_2_duration, 'end', $post_id);
|
||||
}
|
||||
function is_activ_partner_offer_3_date_CIPF($post_id) {
|
||||
Plgntls::debug_infos();
|
||||
$offer_3_duration = Cipf::ACF_PARTNER_OFFER_3_DURATION;
|
||||
return is_acf_field_CIPF($offer_3_duration, 'end', $post_id);
|
||||
}
|
||||
|
||||
$offer_date = get_offer_date_expiration_CIPF($offer_number, $page_id);
|
||||
return is_date_exceeded_CIPF($offer_date);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -226,6 +226,9 @@ function set_acf_field_CIPF($acf_field, $acf_value, $acf_id) {
|
||||
*
|
||||
*/
|
||||
$new_value = get_acf_field_CIPF($acf_field, $acf_id);
|
||||
if (empty($new_value)) {
|
||||
return;
|
||||
}
|
||||
if (!is_string($old_value)) {
|
||||
$old_value = json_encode($old_value);
|
||||
}
|
||||
@@ -723,100 +726,53 @@ function reset_acf_cgv_CIPF($user_id = null) {
|
||||
* emails_reminders
|
||||
*
|
||||
*/
|
||||
function get_emails_reminders_CIPF($user_id = null) {
|
||||
function get_emails_reminders_CIPF($acf_id) {
|
||||
Plgntls::debug_infos();
|
||||
$acf_emails_reminders = Cipf::ACF_EMAILS_REMINDERS;
|
||||
|
||||
if (is_null($user_id)) {
|
||||
$user_id = get_current_user_id();
|
||||
}
|
||||
$acf_id = 'user_'.$user_id;
|
||||
return get_acf_field_CIPF($acf_emails_reminders, $acf_id);
|
||||
}
|
||||
function get_emails_reminders_choices_CIPF($user_id = null) {
|
||||
function get_emails_reminders_choices_CIPF($acf_id) {
|
||||
Plgntls::debug_infos();
|
||||
$acf_emails_reminders = Cipf::ACF_EMAILS_REMINDERS;
|
||||
|
||||
if (is_null($user_id)) {
|
||||
$user_id = get_current_user_id();
|
||||
}
|
||||
$acf_id = 'user_'.$user_id;
|
||||
$object = get_acf_field_object_CIPF($acf_emails_reminders, $acf_id);
|
||||
return $object['choices'];
|
||||
}
|
||||
function set_email_reminder_choice_CIPF($value, $user_id = null) {
|
||||
function set_email_reminder_choice_CIPF($value, $acf_id) {
|
||||
Plgntls::debug_infos();
|
||||
$acf_emails_reminders = Cipf::ACF_EMAILS_REMINDERS;
|
||||
|
||||
if (is_null($user_id)) {
|
||||
$user_id = get_current_user_id();
|
||||
}
|
||||
$acf_id = 'user_'.$user_id;
|
||||
add_acf_field_CIPF($acf_emails_reminders, $value, $acf_id);
|
||||
}
|
||||
function unset_email_reminder_choice_CIPF($value, $user_id = null) {
|
||||
function unset_email_reminder_choice_CIPF($value, $acf_id) {
|
||||
Plgntls::debug_infos();
|
||||
$acf_emails_reminders = Cipf::ACF_EMAILS_REMINDERS;
|
||||
|
||||
if (is_null($user_id)) {
|
||||
$user_id = get_current_user_id();
|
||||
}
|
||||
$acf_id = 'user_'.$user_id;
|
||||
remove_acf_field_CIPF($acf_emails_reminders, $value, $acf_id);
|
||||
}
|
||||
function is_email_reminder_choice_CIPF($value, $user_id = null) {
|
||||
function is_email_reminder_choice_CIPF($value, $acf_id) {
|
||||
Plgntls::debug_infos();
|
||||
$acf_emails_reminders = Cipf::ACF_EMAILS_REMINDERS;
|
||||
|
||||
if (is_null($user_id)) {
|
||||
$user_id = get_current_user_id();
|
||||
}
|
||||
$acf_id = 'user_'.$user_id;
|
||||
return is_acf_field_CIPF($acf_emails_reminders, $value, $acf_id);
|
||||
}
|
||||
function reset_emails_reminders_choices_CIPF($user_id = null) {
|
||||
function reset_emails_reminders_choices_CIPF($acf_id) {
|
||||
Plgntls::debug_infos();
|
||||
$acf_emails_reminders = Cipf::ACF_EMAILS_REMINDERS;
|
||||
|
||||
if (is_null($user_id)) {
|
||||
$user_id = get_current_user_id();
|
||||
}
|
||||
$acf_id = 'user_'.$user_id;
|
||||
set_acf_field_CIPF($acf_emails_reminders, array(), $acf_id);
|
||||
}
|
||||
function reset_emails_reminders_expiration_card_CIPF($user_id = null) {
|
||||
function reset_emails_reminders_box_CIPF($acf_reminder_type, $acf_id) {
|
||||
Plgntls::debug_infos();
|
||||
$acf_emails_reminders = Cipf::ACF_EMAILS_REMINDERS;
|
||||
|
||||
if (is_null($user_id)) {
|
||||
$user_id = get_current_user_id();
|
||||
}
|
||||
$acf_id = 'user_'.$user_id;
|
||||
|
||||
$reminders_choices = get_emails_reminders_choices_CIPF($user_id);
|
||||
$reminders_choices = get_emails_reminders_choices_CIPF($acf_id);
|
||||
foreach ($reminders_choices as $reminder_key => $value) {
|
||||
$explode_reminder = explode('/', $reminder_key);
|
||||
$explode_reminder = array_map('trim', $explode_reminder);
|
||||
if ($explode_reminder[0] === 'card_expiration') {
|
||||
unset_email_reminder_choice_CIPF($reminder_key, $user_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
function reset_emails_reminders_deletion_account_CIPF($user_id = null) {
|
||||
Plgntls::debug_infos();
|
||||
$acf_emails_reminders = Cipf::ACF_EMAILS_REMINDERS;
|
||||
|
||||
if (is_null($user_id)) {
|
||||
$user_id = get_current_user_id();
|
||||
}
|
||||
$acf_id = 'user_'.$user_id;
|
||||
|
||||
$reminders_choices = get_emails_reminders_choices_CIPF($user_id);
|
||||
foreach ($reminders_choices as $reminder_key => $value) {
|
||||
$explode_reminder = explode('/', $reminder_key);
|
||||
$explode_reminder = array_map('trim', $explode_reminder);
|
||||
if ($explode_reminder[0] === 'account_deletion') {
|
||||
unset_email_reminder_choice_CIPF($reminder_key, $user_id);
|
||||
if ($explode_reminder[0] === $acf_reminder_type) {
|
||||
unset_email_reminder_choice_CIPF($reminder_key, $acf_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ function update_emails_settings_option_CIPF($request, $option_name, $option_data
|
||||
}
|
||||
else {
|
||||
// it means it was not in the saved data, but was added in the default
|
||||
$ret_update = update_email_by_type_CIPF($email, $options, $request);
|
||||
$ret_update = update_email_by_type_CIPF($email, $options, $option_default[$email], $request);
|
||||
if ($ret_update !== false) {
|
||||
$new_option[$email] = $ret_update;
|
||||
}
|
||||
|
||||
71
plugins/cipf_plugin/php/partners_handle_offers.php
Normal file
71
plugins/cipf_plugin/php/partners_handle_offers.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* it means someone outside wp is accessing the file, in this case kill it.
|
||||
*/
|
||||
if (!defined('ABSPATH')) {
|
||||
die('You can not access this file!');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function handle_partner_offers_expire_CIPF($page_id) {
|
||||
Plgntls::debug_infos();
|
||||
|
||||
$i = 1;
|
||||
while ($i <= 3) {
|
||||
$offer_duration = get_field_init_CIPF('duree_offre_'.$i, $page_id);
|
||||
if ($offer_duration !== 'Temporaire') {
|
||||
++$i;
|
||||
continue;
|
||||
}
|
||||
$offer_output = get_field_init_CIPF('afficher_offre_'.$i, $page_id);
|
||||
if ($offer_output === 'Masquer') {
|
||||
++$i;
|
||||
continue;
|
||||
}
|
||||
handle_offer_is_expired_CIPF($i, $page_id);
|
||||
handle_offer_will_expire_CIPF($i, $page_id);
|
||||
++$i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function handle_offer_will_expire_CIPF($i, $page_id) {
|
||||
Plgntls::debug_infos();
|
||||
|
||||
if (is_offer_date_exceeded_CIPF($i, $page_id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$date_limit = get_offer_date_expiration_CIPF($i, $page_id);
|
||||
if (false === $date_limit) {
|
||||
return;
|
||||
}
|
||||
|
||||
$post = get_post($page_id);
|
||||
$user_id = $post->post_author;
|
||||
handle_send_reminders_CIPF($page_id, $user_id, $date_limit, 'offer_expiration', 'offer_will_expire');
|
||||
}
|
||||
|
||||
|
||||
|
||||
function handle_offer_is_expired_CIPF($i, $page_id) {
|
||||
Plgntls::debug_infos();
|
||||
|
||||
if (!is_offer_date_exceeded_CIPF($i, $page_id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
update_field('afficher_offre_'.$i, 'Masquer', $page_id);
|
||||
set_email_reminder_choice_CIPF('offer_expired', $acf_id);
|
||||
send_emails_CIPF('offer_expired', $user_id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@@ -155,6 +155,7 @@ function failure_payment_for_user_CIPF($user_id, $order_id, $status) {
|
||||
function success_payment_for_user_CIPF($user_id, $order_id) {
|
||||
Plgntls::debug_infos();
|
||||
|
||||
$acf_id = 'user_'.$user_id;
|
||||
schedule_delete_orderid_CIPF($order_id, $user_id);
|
||||
|
||||
/*
|
||||
@@ -182,7 +183,7 @@ function success_payment_for_user_CIPF($user_id, $order_id) {
|
||||
|
||||
set_payment_success_CIPF($user_id);
|
||||
set_account_valid_CIPF($user_id);
|
||||
reset_emails_reminders_choices_CIPF($user_id);
|
||||
reset_emails_reminders_choices_CIPF($acf_id);
|
||||
send_emails_CIPF('payment_success', $user_id);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ if (!defined('ABSPATH')) {
|
||||
function handle_transfert_validation_CIPF($user_id) {
|
||||
Plgntls::debug_infos();
|
||||
|
||||
$acf_id = 'user_'.$user_id;
|
||||
/*
|
||||
* check and reset the acf fielf for transfert
|
||||
*
|
||||
@@ -47,7 +48,7 @@ function handle_transfert_validation_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($user_id);
|
||||
reset_emails_reminders_choices_CIPF($acf_id);
|
||||
send_emails_CIPF('transfert_success', $user_id);
|
||||
}
|
||||
|
||||
@@ -61,6 +62,8 @@ function handle_transfert_validation_CIPF($user_id) {
|
||||
*/
|
||||
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;
|
||||
}
|
||||
@@ -71,8 +74,8 @@ function handle_card_expire_CIPF($user_id) {
|
||||
else {
|
||||
set_account_expired_CIPF($user_id);
|
||||
}
|
||||
if (!is_email_reminder_choice_CIPF('card_expired', $user_id)) {
|
||||
set_email_reminder_choice_CIPF('card_expired', $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);
|
||||
}
|
||||
}
|
||||
@@ -83,8 +86,8 @@ function handle_card_expire_CIPF($user_id) {
|
||||
else {
|
||||
set_account_valid_CIPF($user_id);
|
||||
}
|
||||
reset_emails_reminders_deletion_account_CIPF($user_id);
|
||||
unset_email_reminder_choice_CIPF('card_expired', $user_id);
|
||||
reset_emails_reminders_box_CIPF('account_deletion', $acf_id);
|
||||
unset_email_reminder_choice_CIPF('card_expired', $acf_id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,38 +149,7 @@ function handle_reminders_before_card_expire_CIPF($user_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
$is_before_reminders = true;
|
||||
$reminders_choices = get_emails_reminders_choices_CIPF($user_id);
|
||||
foreach ($reminders_choices as $reminder_key => $value) {
|
||||
$duration = get_duration_CIPF($reminder_key, 'card_expiration');
|
||||
if (false === $duration) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$diff = compare_diff_with_today_CIPF($date_limit, $duration);
|
||||
if ($diff > 0) {
|
||||
continue;
|
||||
}
|
||||
$is_before_reminders = false;
|
||||
|
||||
if (is_email_reminder_choice_CIPF($reminder_key, $user_id)) {
|
||||
continue;
|
||||
}
|
||||
set_email_reminder_choice_CIPF($reminder_key, $user_id);
|
||||
send_emails_CIPF('card_will_expire', $user_id);
|
||||
return; // don't send multiple emails
|
||||
}
|
||||
|
||||
/*
|
||||
* if didnt return, it either means that :
|
||||
* - today is before any reminder
|
||||
* - today is after all reminders
|
||||
* use 'is_before_reminders' to know
|
||||
*
|
||||
*/
|
||||
if ($is_before_reminders) {
|
||||
reset_emails_reminders_expiration_card_CIPF($user_id);
|
||||
}
|
||||
handle_send_reminders_CIPF('user_'.$user_id, $user_id, $date_limit, 'card_expiration', 'card_will_expire');
|
||||
}
|
||||
|
||||
|
||||
@@ -197,8 +169,9 @@ function handle_reminders_before_account_deleted_CIPF($user_id) {
|
||||
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_deletion_account_CIPF($user_id);
|
||||
reset_emails_reminders_box_CIPF('account_deletion', $acf_id);
|
||||
return;
|
||||
}
|
||||
$date_limit = get_card_date_expiration_CIPF($user_id);
|
||||
@@ -207,90 +180,8 @@ function handle_reminders_before_account_deleted_CIPF($user_id) {
|
||||
}
|
||||
$date_deletion = $date_limit->modify($duration_deletion);
|
||||
|
||||
handle_send_reminders_CIPF($acf_id, $user_id, $date_deletion, 'account_deletion', 'account_will_be_deleted');
|
||||
|
||||
$is_before_reminders = true;
|
||||
/*
|
||||
* get the acf reminders,
|
||||
* - continue the ones not for account deletion
|
||||
* - continue if date is not yet soon enough
|
||||
* - continue if email was already sent
|
||||
*
|
||||
*/
|
||||
$reminders_choices = get_emails_reminders_choices_CIPF($user_id);
|
||||
foreach ($reminders_choices as $reminder_key => $value) {
|
||||
$duration = get_duration_CIPF($reminder_key, 'account_deletion');
|
||||
if (false === $duration) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$diff = compare_diff_with_today_CIPF($date_deletion, $duration);
|
||||
if ($diff > 0) {
|
||||
continue;
|
||||
}
|
||||
$is_before_reminders = false;
|
||||
|
||||
if (is_email_reminder_choice_CIPF($reminder_key, $user_id)) {
|
||||
continue;
|
||||
}
|
||||
set_email_reminder_choice_CIPF($reminder_key, $user_id);
|
||||
send_emails_CIPF('account_will_be_deleted', $user_id);
|
||||
return; // don't send multiple emails
|
||||
}
|
||||
|
||||
/*
|
||||
* if didnt return, it either means that :
|
||||
* - today is before any reminder
|
||||
* - today is after all reminders
|
||||
* use 'is_before_reminders' to know
|
||||
*
|
||||
*/
|
||||
if ($is_before_reminders) {
|
||||
reset_emails_reminders_deletion_account_CIPF($user_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* extract the duration
|
||||
* returns false if not for the right type
|
||||
*
|
||||
*/
|
||||
function get_duration_CIPF($reminder, $type) {
|
||||
Plgntls::debug_infos();
|
||||
|
||||
$explode_reminder = explode('/', $reminder);
|
||||
$explode_reminder = array_map('trim', $explode_reminder);
|
||||
if ($explode_reminder[0] !== $type) {
|
||||
return false;
|
||||
}
|
||||
$duration = $explode_reminder[1];
|
||||
return $duration;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* find the diffs :
|
||||
* - the intended diff between the deletion date and the reminder
|
||||
* - the diff between the deletion date and today
|
||||
* and return the difference
|
||||
*
|
||||
*/
|
||||
function compare_diff_with_today_CIPF($date, $duration) {
|
||||
Plgntls::debug_infos();
|
||||
|
||||
$date_reminder = $date->modify($duration);
|
||||
$date_diff = date_diff($date, $date_reminder);
|
||||
$date_diff = (int)$date_diff->format('%R%a');
|
||||
|
||||
$date_now = date_create('now');
|
||||
$current_date_diff = date_diff($date, $date_now);
|
||||
$current_date_diff = (int)$current_date_diff->format('%R%a');
|
||||
|
||||
return ($date_diff - $current_date_diff);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -55,8 +55,8 @@ class Plgntls {
|
||||
* typical for early hooks like 'init' or 'wp', where there is a first check to see if you should 'enter' in this function, level 1 will be present after thoses checks
|
||||
* 2 : output everything
|
||||
*
|
||||
private static $_DEBUG_INFOS = 1;
|
||||
private static $_DEBUG_INFOS = 2;
|
||||
private static $_DEBUG_INFOS = 1;
|
||||
*/
|
||||
private static $_DEBUG_INFOS = 0;
|
||||
|
||||
@@ -947,6 +947,8 @@ class Plgntls {
|
||||
'capability'=> 'manage_options',
|
||||
'slug' => $menu_options['name'],
|
||||
'callback' => $menu_options['callback'],
|
||||
'icon' => '',
|
||||
'position' => 10,
|
||||
'toggle' => true,
|
||||
);
|
||||
foreach ($default as $key => $value) {
|
||||
@@ -956,7 +958,15 @@ class Plgntls {
|
||||
}
|
||||
|
||||
if (false === $menu_options['toggle']) {
|
||||
add_menu_page($menu_options['page_title'], $menu_options['name'], $menu_options['capability'], $menu_options['slug'], $menu_options['callback']);
|
||||
add_menu_page(
|
||||
$menu_options['page_title'],
|
||||
$menu_options['name'],
|
||||
$menu_options['capability'],
|
||||
$menu_options['slug'],
|
||||
$menu_options['callback'],
|
||||
$menu_options['icon'],
|
||||
$menu_options['position'],
|
||||
);
|
||||
}
|
||||
else {
|
||||
self::_toggle_menu($menu_options['page_title'], $menu_options['name'], $menu_options['capability'], $menu_options['slug'], $menu_options['callback']);
|
||||
|
||||
Reference in New Issue
Block a user