updated plgntls options to improve default with new options

This commit is contained in:
asus
2024-04-03 22:43:05 +02:00
parent 1628eac171
commit 91a67d955b
7 changed files with 118 additions and 92 deletions

View File

@@ -4,7 +4,7 @@ Plugin Name: hggg_cipf
Plugin URI:
Description:
Author: hugogogo
Version: 0.5.2
Version: 0.5.2.2
Author URI:
*/
@@ -159,7 +159,6 @@ contactez la fipf directement",
'_name'=>'cipf_emails_option',
'_callback'=>'update_emails_settings_option_CIPF',
'_default'=>[
// 1. profs : email : payment_success : validation payment prof reussi, send email
'payment_success'=>[
'name'=>'prof - le paiement a réussi',
'notification_send'=>true,
@@ -170,7 +169,6 @@ contactez la fipf directement",
'confirmation_subject'=>"[CIPF - paiement réussi]",
'confirmation_message'=>"paiement réussi",
],
// 2. profs : email : payment_failure : validation payment prof echec, send email
'payment_echec'=>[
'name'=>'prof - le paiement a echoué',
'notification_send'=>true,
@@ -181,7 +179,6 @@ contactez la fipf directement",
'confirmation_subject'=>"[CIPF - paiement echoué]",
'confirmation_message'=>"votre paiement a echoué",
],
// 3. profs : email : transfert_success : validation transfert prof reussi, send email
'transfert_success'=>[
'name'=>'prof - le virement a été validé',
'notification_send'=>true,
@@ -192,40 +189,6 @@ contactez la fipf directement",
'confirmation_subject'=>"[CIPF - virement validé]",
'confirmation_message'=>"votre virement a été validé",
],
// 4. profs : email : transfert_failures : validation transfert prof echec, send email
// 'transfert_echec'=>[
// 'name'=>'prof - le virement a échoué',
// 'notification_send'=>true,
// 'notification_to'=>'$$__admin_email__$$',
// 'notification_subject'=>"[CIPF /prof - virement echoué]",
// 'notification_message'=>'virement echoué pour $$user_login$$ : $$__author_page_url__$$',
// 'confirmation_send'=>true,
// 'confirmation_subject'=>"[CIPF - virement echoué]",
// 'confirmation_message'=>"votre virement a echoué",
// ],
// 5. partners : email : offer_expired : offres temporaires -> gerer qu'elles disparaissent apres la date de validite -> la passer en masquer
'offer_expired'=>[
'name'=>"partenaire - l'offre partenaire a expirée",
'notification_send'=>true,
'notification_to'=>'$$__admin_email__$$',
'notification_subject'=>"[CIPF /partenaire - offre expirée]",
'notification_message'=>'offre expirée pour $$user_login$$ : $$__user_post_url__$$',
'confirmation_send'=>true,
'confirmation_subject'=>"[CIPF - offre expirée]",
'confirmation_message'=>'votre offre a expiré, pour la renouveler rendez-vous sur $$__base_url__$$',
],
// 6. partners : email : offer_will_expire : la gestion des offres à échéance
'offer_will_expire'=>[
'name'=>"partenaire - l'offre arrive bientot a expiration",
'notification_send'=>true,
'notification_to'=>'$$__admin_email__$$',
'notification_subject'=>"[CIPF /partenaire - offre va expirer]",
'notification_message'=>'offre va expirer pour $$user_login$$ : $$__user_post_url__$$',
'confirmation_send'=>true,
'confirmation_subject'=>"[CIPF - offre va expirer]",
'confirmation_message'=>'une de vos offre va expirer, rendez-vous sur $$__base_url__$$',
],
// 7. payments : email : account_deleted : schedule event pour supprimer le compte xx temps (6 mois ?) apres fin de validite de la carte
'account_deleted'=>[
'name'=>'prof - le compte a été supprimé',
'notification_send'=>true,
@@ -236,27 +199,45 @@ contactez la fipf directement",
'confirmation_subject'=>"[CIPF - compte supprimé]",
'confirmation_message'=>'votre compte a été supprimé sur $$__base_url__$$',
],
// 8. payments : email : account_will_expire : faire rappels emails avant expiration
'account_will_expire'=>[
'name'=>'prof - le compte va bientot expirer',
'name'=>'prof - la carte va bientot expirer',
'notification_send'=>true,
'notification_to'=>'$$__admin_email__$$',
'notification_subject'=>"[CIPF /prof - compte va expirer]",
'notification_message'=>'le compte va expirer pour $$user_login$$ : $$__author_page_url__$$',
'notification_subject'=>"[CIPF /prof - carte va expirer]",
'notification_message'=>'la carte va expirer pour $$user_login$$ : $$__author_page_url__$$',
'confirmation_send'=>true,
'confirmation_subject'=>"[CIPF - compte va expirer]",
'confirmation_message'=>'votre compte va expirer bientot, renouvellez-le sur $$__base_url__$$',
'confirmation_subject'=>"[CIPF - carte va expirer]",
'confirmation_message'=>'votre carte va expirer bientot, renouvellez-la sur $$__base_url__$$',
],
// 9. payments : email : account_expired : desactiver carte expiree
'account_expired'=>[
'name'=>'prof - le compte a expiré',
'name'=>'prof - la carte a expiré',
'notification_send'=>true,
'notification_to'=>'$$__admin_email__$$',
'notification_subject'=>"[CIPF /prof - compte expiré]",
'notification_message'=>'compte expiré pour $$user_login$$ : $$__author_page_url__$$',
'notification_subject'=>"[CIPF /prof - carte expirée]",
'notification_message'=>'carte expirée pour $$user_login$$ : $$__author_page_url__$$',
'confirmation_send'=>true,
'confirmation_subject'=>"[CIPF - compte expiré]",
'confirmation_message'=>'votre compte a expiré, renouvelez-le sur $$__base_url__$$',
'confirmation_subject'=>"[CIPF - carte expirée]",
'confirmation_message'=>'votre carte a expiré, renouvelez-la sur $$__base_url__$$',
],
'offer_will_expire'=>[
'name'=>"partenaire - l'offre arrive bientot a expiration",
'notification_send'=>true,
'notification_to'=>'$$__admin_email__$$',
'notification_subject'=>"[CIPF /partenaire - offre va expirer]",
'notification_message'=>'offre va expirer pour $$user_login$$ : $$__user_post_url__$$',
'confirmation_send'=>true,
'confirmation_subject'=>"[CIPF - offre va expirer]",
'confirmation_message'=>'une de vos offre va expirer, rendez-vous sur $$__base_url__$$',
],
'offer_expired'=>[
'name'=>"partenaire - l'offre partenaire a expirée",
'notification_send'=>true,
'notification_to'=>'$$__admin_email__$$',
'notification_subject'=>"[CIPF /partenaire - offre expirée]",
'notification_message'=>'offre expirée pour $$user_login$$ : $$__user_post_url__$$',
'confirmation_send'=>true,
'confirmation_subject'=>"[CIPF - offre expirée]",
'confirmation_message'=>'votre offre a expiré, pour la renouveler rendez-vous sur $$__base_url__$$',
],
],
];

View File

@@ -167,24 +167,38 @@ function update_paypal_credentials_CIPF($request, $option_name, $option_data, $o
function update_emails_settings_option_CIPF($request, $option_name, $option_data, $option_default) {
Plgntls::debug_infos();
//error_log("---");
//error_log("request: " . json_encode($request));
//error_log("option_data bedore: " . json_encode($option_data));
foreach ($option_data as $email_type => $email_options) {
//error_log("email_type: " . $email_type);
// if ($email_type === '_name') {
// continue;
// }
// $ret_email = update_email_by_type_CIPF($email_type, $email_options, $request);
// if ($ret_email !== false) {
// $option_data[$email_type] = $ret_email;
// }
$option_data[$email_type] = update_email_by_type_CIPF($email_type, $email_options, $request);
$ret_update = update_email_by_type_CIPF($email_type, $email_options, $request);
if ($ret_update !== false) {
$option_data[$email_type] = $ret_update;
}
}
//error_log("option_data after : " . json_encode($option_data));
Plgntls::update_option_safe($option_name, $option_data);
/*
* to reorder and add new data with the default data
* also take the name of the default
* not really good :p
*
*/
$new_option = array();
foreach ($option_default as $email => $options) {
if (isset($option_data[$email])) {
$new_option[$email] = $option_data[$email];
}
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);
if ($ret_update !== false) {
$new_option[$email] = $ret_update;
}
else {
$new_option[$email] = $options;
}
}
$new_option[$email]['name'] = $options['name'];
}
Plgntls::update_option_safe($option_name, $new_option);
}
@@ -195,10 +209,7 @@ function update_emails_settings_option_CIPF($request, $option_name, $option_data
*/
function update_email_by_type_CIPF($email_type, $email_options, $request) {
Plgntls::debug_infos();
//error_log("email type: " . $email_type);
//if ($email_type === '_name') {
// return false;
//}
$is_new = false;
/*
* set notification/confirmation_send to false by default,
@@ -220,19 +231,21 @@ function update_email_by_type_CIPF($email_type, $email_options, $request) {
if ($new_value === $value) {
continue;
}
$is_new = true;
if ($option === 'notification_send' || $option === 'confirmation_send') {
$email_options[$option] = true;
}
else {
// error_log("option: " . $option);
// error_log("- previous value: " . $value);
// error_log("- newvalue : " . $new_value);
$email_options[$option] = $new_value;
}
}
//error_log("email_options: " . json_encode($email_options));
return $email_options;
if ($is_new === false) {
return false;
}
else {
return $email_options;
}
}

View File

@@ -17,25 +17,44 @@ function is_own_partner() {
Plgntls::debug_infos(2);
$role_partner = Cipf::ROLE_PARTNER;
error_log("in toggle A");
/*
* is_single() will only return true for published post
* so instead checks for both is_singular and post_type
*
if (!is_single()) {
return false;
}
if (!is_singular()) {
return false;
}
error_log("post type: " . get_post_type());
if (get_post_type() !== 'post') {
return false;
}
*/
error_log("in toggle B");
if (!is_user_logged_in()) {
return false;
}
error_log("in toggle C");
if (!current_user_can($role_partner)) {
return false;
}
error_log("in toggle D");
global $post;
if (is_null($post)) {
return false;
}
error_log("in toggle E");
Plgntls::debug_infos();
$current_post_author = (int)($post->post_author);
$current_user_id = (int)get_current_user_id();
if ($current_user_id !== $current_post_author) {
return false;
}
error_log("in toggle F");
return true;
}
@@ -66,10 +85,10 @@ function partner_page_scripts_CIPF() {
/*
* then check if is partner own page
*
*/
if (!is_own_partner()) {
return;
}
*/
/*
* on partner own page, load css to show own stuff
@@ -96,16 +115,20 @@ function toggle_partner_page_CIPF() {
* - has query action
*
*/
error_log("in toggle 1");
if (!is_own_partner()) {
return;
}
error_log("in toggle 2");
Plgntls::debug_infos();
if (!isset($_GET['action'])) {
return;
}
error_log("in toggle 3");
if ($_GET['action'] !== $toggle_partner_page) {
return;
}
error_log("in toggle 4");
/*
* get the post id and object
@@ -116,6 +139,7 @@ function toggle_partner_page_CIPF() {
if (is_null($current_post)) {
return;
}
error_log("in toggle 5");
/*
* toogle the status
@@ -141,13 +165,12 @@ function toggle_partner_page_CIPF() {
*
*/
$url = remove_query_arg('action');
error_log("url: " . $url);
wp_safe_redirect($url);
exit;
}
add_action('template_redirect', 'toggle_partner_page_CIPF');
//add_action('template_redirect', 'toggle_partner_page_CIPF');

View File

@@ -86,6 +86,7 @@ function redirection_profil_CIPF(){
'post_type' => 'post',
'author' => $current_user_id,
'posts_per_page' => 1,
'post_status' => array('publish', 'draft'),
);
$posts = get_posts($args);

View File

@@ -1092,13 +1092,18 @@ class Plgntls {
*
*/
$option_data = get_option($option_name);
$false_serialized = serialize(false);
$option_unserialized = @unserialize($option_data);
if ($option_unserialized === false && $option_data != $false_serialized) {
if (!is_string($option_data)) {
$ret_option = $option_data;
}
else {
$ret_option = $option_unserialized;
$false_serialized = serialize(false);
$option_unserialized = @unserialize($option_data);
if ($option_unserialized === false && $option_data != $false_serialized) {
$ret_option = $option_data;
}
else {
$ret_option = $option_unserialized;
}
}
/*
@@ -1211,9 +1216,6 @@ class Plgntls {
if (!isset($option['_default'])) {
return false;
}
if (isset($option['_db'])) {
return $option['_name'];
}
/*
* if wp option does not already exists, just add it
@@ -1222,7 +1224,8 @@ class Plgntls {
*/
$name = $option['_name'];
if (false === get_option($name)) {
add_option($name, $option['_default'], '', 'no');
add_option($name, '', '', 'no');
self::update_option_safe($name, $option['_default']);
}
/*
@@ -1258,7 +1261,6 @@ class Plgntls {
*/
$options_serialized = get_option(self::$_options_list);
$options_unserialized = unserialize($options_serialized);
$option['_db'] = null;
$options_unserialized[$name] = $option;
update_option(self::$_options_list, serialize($options_unserialized), '', 'no');

View File

@@ -1085,13 +1085,18 @@ class Plgntls_xtx {
*
*/
$option_data = get_option($option_name);
$false_serialized = serialize(false);
$option_unserialized = @unserialize($option_data);
if ($option_unserialized === false && $option_data != $false_serialized) {
if (!is_string($option_data)) {
$ret_option = $option_data;
}
else {
$ret_option = $option_unserialized;
$false_serialized = serialize(false);
$option_unserialized = @unserialize($option_data);
if ($option_unserialized === false && $option_data != $false_serialized) {
$ret_option = $option_data;
}
else {
$ret_option = $option_unserialized;
}
}
return $ret_option;
@@ -1197,7 +1202,8 @@ class Plgntls_xtx {
*/
$name = $option['_name'];
if (false === get_option($name)) {
add_option($name, $option['_default'], '', 'no');
add_option($name, '', '', 'no');
self::update_option_safe($name, $option['_default']);
}
/*

View File

@@ -4,7 +4,7 @@ Plugin Name: hggg_xtxpatch
Plugin URI:
Description: some patchs for the xootix login/registration plugin
Author: hugogogo
Version: 0.1.1
Version: 0.1.2
Author URI:
*/