Compare commits
128 Commits
debug_rout
...
emails
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
15b315b4f3 | ||
|
|
d2b2967218 | ||
|
|
8ac16dc1f4 | ||
|
|
913165a056 | ||
|
|
a34b9173cf | ||
|
|
ffc47a0295 | ||
|
|
59b9acc55e | ||
|
|
1553490444 | ||
|
|
1d36093d9f | ||
|
|
9abe24b3bb | ||
|
|
9e903a2ecf | ||
|
|
2329482aa1 | ||
|
|
7a5b1f63d3 | ||
|
|
67bebe4cfc | ||
|
|
ccb800c203 | ||
|
|
47360119e8 | ||
|
|
1f5fff26d6 | ||
|
|
64dc0ffbc5 | ||
|
|
bc06828093 | ||
|
|
86539d5c14 | ||
|
|
b24f0f4210 | ||
|
|
fb146ecda4 | ||
|
|
4d7906be40 | ||
|
|
75205571fe | ||
|
|
0a30bca907 | ||
|
|
5d4be76102 | ||
|
|
995e230e32 | ||
|
|
b4745ff672 | ||
|
|
3e2174a23f | ||
|
|
7ad01a51ba | ||
|
|
ca13c5dccb | ||
|
|
0f554444dd | ||
|
|
1268dc56e3 | ||
|
|
95c292c626 | ||
|
|
2682f3bcd4 | ||
|
|
ade0be87ce | ||
|
|
42e8cbc4e9 | ||
|
|
50c05df2b6 | ||
|
|
dd0d4dfbeb | ||
|
|
a0018c903b | ||
|
|
8b70bea62a | ||
|
|
ab6d825724 | ||
|
|
0808c83589 | ||
|
|
0136be4316 | ||
|
|
dbb6dc0d19 | ||
|
|
27e1e69dfb | ||
|
|
90fb5bc0b6 | ||
|
|
44a5d93f77 | ||
|
|
c9f0522ecc | ||
|
|
4036f4300d | ||
|
|
6ec621a20b | ||
|
|
8ebbb8bff2 | ||
|
|
f055a10d1c | ||
|
|
85e5a34e42 | ||
|
|
569f4524d3 | ||
|
|
1745d8754d | ||
|
|
28a1f7922d | ||
|
|
1856943bc9 | ||
|
|
f882caf850 | ||
|
|
1415fc14a2 | ||
|
|
94dbe05f87 | ||
|
|
5c93938b53 | ||
|
|
b05b5f375e | ||
|
|
46885fe10e | ||
|
|
aae40be620 | ||
|
|
b6d1d63b93 | ||
|
|
1fe5379845 | ||
|
|
cb9042a746 | ||
|
|
ab9afab160 | ||
|
|
66fbbfd586 | ||
|
|
782ae1b1d8 | ||
|
|
fcd7aae681 | ||
|
|
dc77784fef | ||
|
|
68905de5d5 | ||
|
|
c973af3131 | ||
|
|
b57fb6156c | ||
|
|
c69df03c75 | ||
|
|
8933b3d321 | ||
|
|
abd9717fe0 | ||
|
|
578502838e | ||
|
|
b93a3298d2 | ||
|
|
0717a7d9e4 | ||
|
|
58f287f00f | ||
|
|
4eee697078 | ||
|
|
f9788fa96e | ||
|
|
0ab26c0b31 | ||
|
|
227d07fe46 | ||
|
|
33adb095e5 | ||
|
|
0127d8db4c | ||
|
|
61063cabd9 | ||
|
|
1248c2339d | ||
|
|
d264e6c321 | ||
|
|
4de26b79fc | ||
|
|
58d02708b9 | ||
|
|
cbfbfabd18 | ||
|
|
f7c805f22b | ||
|
|
db1d16bd91 | ||
|
|
2f0b15dd6f | ||
|
|
aad98c5188 | ||
|
|
5010b70d79 | ||
|
|
f221e43807 | ||
|
|
5e7ca4f0f1 | ||
|
|
0b8b479584 | ||
|
|
e1f4799150 | ||
|
|
9cda6f13bd | ||
|
|
cabee4db30 | ||
|
|
ba1d3e3707 | ||
|
|
c1b687064f | ||
|
|
5be80d1566 | ||
|
|
98dfb17bf4 | ||
|
|
82b6593dd9 | ||
|
|
fcb15c97d1 | ||
|
|
874736fd8a | ||
|
|
c39a656ab1 | ||
|
|
a245bd4350 | ||
|
|
eaa45c4ed1 | ||
|
|
70d8998a3f | ||
|
|
fc41f7d36b | ||
|
|
f9b245c39c | ||
|
|
6ad1fb5137 | ||
|
|
494943e4f7 | ||
|
|
6c7b269052 | ||
|
|
9ebce56025 | ||
|
|
70888d384c | ||
|
|
0d6d475ce0 | ||
|
|
4c81476336 | ||
|
|
30c84135ef | ||
|
|
4220c34c7f |
293
plugins/cipf_plugin/cipf_plugin.php
Normal file
293
plugins/cipf_plugin/cipf_plugin.php
Normal file
@@ -0,0 +1,293 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
Plugin Name: hggg_cipf
|
||||||
|
Plugin URI:
|
||||||
|
Description:
|
||||||
|
Author: hugogogo
|
||||||
|
Version: 0.5.2
|
||||||
|
Author URI:
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
include_once( plugin_dir_path(__FILE__) . '/plgntls_class.php');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* general inclusions
|
||||||
|
// utils :
|
||||||
|
*/
|
||||||
|
include_once(Plgntls::root_path() . 'php/utils/globals.php');
|
||||||
|
include_once(Plgntls::root_path() . 'php/utils/console_log.php');
|
||||||
|
|
||||||
|
// paypal
|
||||||
|
include_once(Plgntls::root_path() . 'php/paypal/paypal.php');
|
||||||
|
// profs
|
||||||
|
include_once(Plgntls::root_path() . 'php/profs_profil.php');
|
||||||
|
include_once(Plgntls::root_path() . 'php/profs_form_commande.php');
|
||||||
|
include_once(Plgntls::root_path() . 'php/profs_dates.php');
|
||||||
|
include_once(Plgntls::root_path() . 'php/profs_handle_states.php');
|
||||||
|
// partners
|
||||||
|
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');
|
||||||
|
// utils
|
||||||
|
//include_once(Plgntls::root_path() . '/php/menus.php');
|
||||||
|
include_once(Plgntls::root_path() . 'php/states.php');
|
||||||
|
include_once(Plgntls::root_path() . 'php/redirections.php');
|
||||||
|
include_once(Plgntls::root_path() . 'php/display_css.php');
|
||||||
|
include_once(Plgntls::root_path() . 'php/payments.php');
|
||||||
|
include_once(Plgntls::root_path() . 'php/random_posts.php');
|
||||||
|
include_once(Plgntls::root_path() . 'php/scheduled_events.php');
|
||||||
|
include_once(Plgntls::root_path() . 'php/emails.php');
|
||||||
|
// admin
|
||||||
|
include_once(Plgntls::root_path() . 'php/admin_hide_bar.php');
|
||||||
|
include_once(Plgntls::root_path() . 'php/admin_user_profil.php');
|
||||||
|
include_once(Plgntls::root_path() . 'php/admin_menu.php');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class Cipf {
|
||||||
|
/*
|
||||||
|
* const declarations
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
// ACF
|
||||||
|
const ACF_CARD_STATE = ['_name'=>'etat_carte', 'new'=>'Commande', 'renew'=>'Renouvellement']; // radio button
|
||||||
|
const ACF_CARD_PAYMENT_METHOD = ['_name'=>'paiement', 'paypal'=>'Paypal', 'transfert'=>'Virement']; // radio button
|
||||||
|
const ACF_CARD_PRICE_CHOICE = ['_name'=>'tarif', 'low'=>'10', 'high'=>'15']; // radio button
|
||||||
|
const ACF_CARD_PRICE_DELIVERY = ['_name'=>'livraison', 'pdf'=>'0', 'post'=>'5']; // radio button
|
||||||
|
const ACF_PROF_IS_ACTIV = ['_name'=>'compte-actif', 'activ'=>'Actif', 'inactiv'=>'Inactif']; // radio button
|
||||||
|
const ACF_PROF_CGV = ['_name'=>'cgv', 'cgv'=>'cgv']; // checkbox
|
||||||
|
const ACF_CARD_PRICE_TOTAL = ['_name'=>'somme_a_regler']; // number
|
||||||
|
const ACF_CARD_NUMBER = ['_name'=>'numero_de_la_carte']; // number
|
||||||
|
const ACF_CARD_EXPIRATION = ['_name'=>'fin_de_validite']; // date picker
|
||||||
|
const ACF_CARD_PAYMENT_STATE = ['_name'=>'etat_paiement', 'started'=>'en_cours', 'success'=>'reussi', 'failure'=>'echec', 'nothing'=>'aucun']; // radio button
|
||||||
|
const ACF_ACCOUNT_STATE = ['_name'=>'etat_compte', 'new'=>'nouveau prof', 'to_pay'=>'doit payer', 'valid'=>'carte valide', 'waiting_invalid'=>'en attente invalide', 'waiting_valid'=>'en attente valide', 'expired'=>'carte expiree'];
|
||||||
|
const ACF_TRANSFERT_STATE = ['_name'=>'etat_virement', 'success'=>'virement validé'];
|
||||||
|
const ACF_PAGE_STATE = ['_name'=>'etat_page_partenaire', 'publish'=>'Publiee', 'draft'=>'Brouillon'];
|
||||||
|
|
||||||
|
// META
|
||||||
|
const META_PAYEMENT_STATUS = 'cipf_payement_status';
|
||||||
|
const META_ORDER_ID = 'cipf_order_id';
|
||||||
|
|
||||||
|
// SLUG
|
||||||
|
const SLUG_PROF_INACTIV = 'validation-en-cours';
|
||||||
|
const SLUG_COMMAND_CARD = 'commande';
|
||||||
|
const SLUG_PAGE_REDIRECTION = 'redirection_cipf';
|
||||||
|
const SLUG_PAYPAL_PAGE = 'paiement';
|
||||||
|
const SLUG_PAYPAL_REDIRECTION_SUCCESS = self::SLUG_PAGE_REDIRECTION;
|
||||||
|
const SLUG_PAYPAL_REDIRECTION_FAILURE = self::SLUG_PAGE_REDIRECTION;
|
||||||
|
const SLUG_ADMIN_VALIDATE_PROF = 'admin_activate_prof_cipf'; // for admin_modif_prof.php
|
||||||
|
const SLUG_PARTNER_REGISTRATION = 'compte-partenaire';
|
||||||
|
const SLUG_PARTNER_CREATE_PAGE = 'ma-page-partenaire';
|
||||||
|
|
||||||
|
// URL
|
||||||
|
const URL_BASE_REST_ROUTE = 'cipf_plugin/api/v1'; // for routes, in php/paypal/routes.php && php/admin_modif_prof.php
|
||||||
|
|
||||||
|
// QUERY
|
||||||
|
const QUERY_TOGGLE_PARTNER_PAGE = 'toggle_partner_page_cipf';
|
||||||
|
|
||||||
|
// PAYPAL
|
||||||
|
const PAYPAL_SBOX_API_BASE_URL = "https://api-m.sandbox.paypal.com";
|
||||||
|
const PAYPAL_LIVE_API_BASE_URL = "https://api-m.paypal.com";
|
||||||
|
const PAYPAL_HUGO_SBOX_CLIENT_ID = "AfcmwxIXlG2ZxaMdjazX57I70BXz__aEqNWaTnqfSCI34a0V7nMbytswx7EViUjlpHs7opyrRwaH9YLl";
|
||||||
|
const PAYPAL_HUGO_SBOX_CLIENT_SECRET = "EGunIhGRjPvn0Z8wXO0JsdhET30OStTAH_IyRsmhimEN23_qiRSFD-ql4tvnulKJw6TitZ-vU-ytc4A-";
|
||||||
|
const PAYPAL_HUGO_LIVE_CLIENT_ID = "Aedn5e8z__hPBvKirqw5bwlhI9ChG8_N6c1xbgybYyBr4B4oP8uVzmVdH1QVKdPQKf6bWg7orPV4PDrO";
|
||||||
|
const PAYPAL_HUGO_LIVE_CLIENT_SECRET = "EGeGwfHGxHxsjnC-tH8W0IL4nN3_xlc3sXFRPCQOw5uUoWae3eOgghuDKMnZc5DVGTbP6yIjVJ1BaAra";
|
||||||
|
const PAYPAL_DIEGO_SBOX_CLIENT_ID = "AegZZ6vDrTBzUNGf-UOVoUwh51YU4cvjGGPQkOQ7gM3H2xij9Pdkf751WO1ZvLoFjqbeNN-M5F6WqrdL";
|
||||||
|
const PAYPAL_DIEGO_SBOX_CLIENT_SECRET = "ENH2n-trvWrs4B6IWdhl7NM_Wp-Rpyo5ONJJMjJFevGVJ2wtSdORPXFx-vPZ2RQGV0RUQzAp6qt4_qVn";
|
||||||
|
const PAYPAL_DIEGO_LIVE_CLIENT_ID = "Abp6y2Outx8bMsEQRXBjH7qYK7-sTHmCMWlmJcw0Ctl5c9XpNsbGt5Vl1tD1ZmFhuBGGjT8ec3FKoLCo";
|
||||||
|
const PAYPAL_DIEGO_LIVE_CLIENT_SECRET = "EFLFOATSMM1m9BZwfj209qAeYDrsH-ltcFnVBmyPAJM-KjQiMtUVDQNPeyikDO1Y41yMiKu_IoELp_vD";
|
||||||
|
//const PAYPAL_CLIENT_ID = self::PAYPAL_HUGO_LIVE_CLIENT_ID;
|
||||||
|
//const PAYPAL_CLIENT_SECRET = self::PAYPAL_HUGO_LIVE_CLIENT_SECRET;
|
||||||
|
//const PAYPAL_API_BASE_URL = self::PAYPAL_HUGO_LIVE_API_BASE_URL;
|
||||||
|
const PAYPAL_MESSAGE_SUCCESS = 'Paiement réussi, vous allez être redirigé-es vers votre espace';
|
||||||
|
const PAYPAL_MESSAGE_PROBLEM = "Paiement réussi, mais une erreure est survenue dans le traitement de la commande, si vous voyez que votre compte n'est pas mis à jour correctement, contactez la fipf directement";
|
||||||
|
const PAYPAL_MESSAGE_FAILURE = 'Paiement raté, vous allez être redirigé-es vers votre espace';
|
||||||
|
|
||||||
|
// ROLES
|
||||||
|
const ROLE_PROF = 'professeur__professeure';
|
||||||
|
const ROLE_PARTNER = 'partenaire';
|
||||||
|
const ROLE_FIPF = 'fipf';
|
||||||
|
const ROLE_ADMIN = 'administrator';
|
||||||
|
|
||||||
|
// SHORTCODES
|
||||||
|
|
||||||
|
// OPTIONS
|
||||||
|
const OPTION_PAYPAL = [
|
||||||
|
'_name'=>'cipf_paypal_credentials',
|
||||||
|
'_callback'=>'update_paypal_credentials_CIPF',
|
||||||
|
'_default' => [
|
||||||
|
'is_sandbox' =>true,
|
||||||
|
'client_id' =>'AfcmwxIXlG2ZxaMdjazX57I70BXz__aEqNWaTnqfSCI34a0V7nMbytswx7EViUjlpHs7opyrRwaH9YLl',
|
||||||
|
'client_secret'=>'EGunIhGRjPvn0Z8wXO0JsdhET30OStTAH_IyRsmhimEN23_qiRSFD-ql4tvnulKJw6TitZ-vU-ytc4A-',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
const OPTION_PAYMENT = [
|
||||||
|
'_name'=>'cipf_payment_messages',
|
||||||
|
'_callback'=>'update_payment_messages_option_CIPF',
|
||||||
|
'_default'=>[
|
||||||
|
'success'=>
|
||||||
|
'Paiement réussi,
|
||||||
|
vous allez être redirigés vers votre espace',
|
||||||
|
'failure'=>
|
||||||
|
'Paiement échoué,
|
||||||
|
vous allez être redirigés vers votre espace',
|
||||||
|
'problem'=>
|
||||||
|
"Paiement réussi,
|
||||||
|
mais une erreur est survenue dans le traitement de la commande,
|
||||||
|
si vous voyez que votre compte n'est pas mis à jour correctement,
|
||||||
|
contactez la fipf directement",
|
||||||
|
],
|
||||||
|
];
|
||||||
|
const OPTION_EMAILS = [
|
||||||
|
'_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,
|
||||||
|
'notification_to'=>'$$__admin_email__$$',
|
||||||
|
'notification_subject'=>"[CIPF /prof - paiement réussi]",
|
||||||
|
'notification_message'=>'paiement réussi de la part de $$user_login$$ : $$__author_page_url__$$',
|
||||||
|
'confirmation_send'=>true,
|
||||||
|
'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,
|
||||||
|
'notification_to'=>'$$__admin_email__$$',
|
||||||
|
'notification_subject'=>"[CIPF /prof - paiement echoué]",
|
||||||
|
'notification_message'=>'paiement echoué pour $$user_login$$ : $$__author_page_url__$$',
|
||||||
|
'confirmation_send'=>true,
|
||||||
|
'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,
|
||||||
|
'notification_to'=>'$$__admin_email__$$',
|
||||||
|
'notification_subject'=>"[CIPF /prof - virement validé]",
|
||||||
|
'notification_message'=>'virement validé pour $$user_login$$ : $$__author_page_url__$$',
|
||||||
|
'confirmation_send'=>true,
|
||||||
|
'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,
|
||||||
|
'notification_to'=>'$$__admin_email__$$',
|
||||||
|
'notification_subject'=>"[CIPF /prof - compte supprimé]",
|
||||||
|
'notification_message'=>'compte supprimé pour $$user_login$$ : $$__author_page_url__$$',
|
||||||
|
'confirmation_send'=>true,
|
||||||
|
'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',
|
||||||
|
'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__$$',
|
||||||
|
'confirmation_send'=>true,
|
||||||
|
'confirmation_subject'=>"[CIPF - compte va expirer]",
|
||||||
|
'confirmation_message'=>'votre compte va expirer bientot, renouvellez-le sur $$__base_url__$$',
|
||||||
|
],
|
||||||
|
// 9. payments : email : account_expired : desactiver carte expiree
|
||||||
|
'account_expired'=>[
|
||||||
|
'name'=>'prof - le compte 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__$$',
|
||||||
|
'confirmation_send'=>true,
|
||||||
|
'confirmation_subject'=>"[CIPF - compte expiré]",
|
||||||
|
'confirmation_message'=>'votre compte a expiré, renouvelez-le sur $$__base_url__$$',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
// ADMIN MENU
|
||||||
|
const SLUG_TOOGLE_ADMIN_MENU = ['_name'=>'toogle_admin_menu_url_cipf', 'toggle'=>'toggle', 'show'=>'show', 'hide'=>'hide'];
|
||||||
|
const TOGGLE_ADMIN_MENU = ['_name'=>'toggle_admin_menu_option_cipf', 'show'=>'show', 'hide'=>'hide'];
|
||||||
|
const ADMIN_POST_PAYPAL = 'paypal_credentials_CIPF';
|
||||||
|
const ADMIN_MENU_NONCE_PAYPAL = ['_name'=>'nonce_paypal_cipf', '_action'=>'action_admin_menu_paypal_cipf'];
|
||||||
|
const ADMIN_POST_EMAIL_REGISTRATION = 'email_registration_message_CIPF';
|
||||||
|
const ADMIN_MENU_NONCE_EMAIL_REGISTRATION = ['_name'=>'nonce_email_cipf', '_action'=>'action_admin_menu_email_registration_cipf'];
|
||||||
|
const ADMIN_POST_PAYMENT_MESSAGES = 'payment_messages_CIPF';
|
||||||
|
const ADMIN_MENU_NONCE_PAYMENT_MESSAGES = ['_name'=>'nonce_payment_cipf', '_action'=>'action_admin_menu_payment_messages_cipf'];
|
||||||
|
|
||||||
|
// FORMS
|
||||||
|
const FORM_PROF_COMMANDE_ID = 'prof_commande';
|
||||||
|
const FORM_PROF_TRANSFERT_ID = 'prof_valide_virement';
|
||||||
|
|
||||||
|
// OTHER
|
||||||
|
const CARD_RENEW_PERIOD = 31; // int : number of days before expiration when renew card start to be possible
|
||||||
|
const CARD_VALIDITY_TIME = '1 year'; // string : time of validity of the card (ex: '1 month' or '1 year' or '60 days')
|
||||||
|
const USER_INFO_DATE_FORMAT = 'd/m/Y'; // for user_infos.php (date format : https://www.php.net/manual/fr/datetime.format.php)
|
||||||
|
const ADMIN_VALIDATE_PROF_FIELD = 'admin_activate_prof_cipf'; // for admin_modif_prof.php
|
||||||
|
const INPUT_HIDDEN_ROLE = 'cipf_user_role';
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
3
plugins/cipf_plugin/css/display_states/_default.css
Normal file
3
plugins/cipf_plugin/css/display_states/_default.css
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
[class*='cipf_display_'] {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
[class*='cipf_display_'].cipf_display_carte_commande { display: block !important; }
|
||||||
|
[class*='cipf_display_'].cipf_display_carte_commande.cipf_flex { display: flex !important; }
|
||||||
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
[class*='cipf_display_'].cipf_display_carte_renouvellement { display: block !important; }
|
||||||
|
[class*='cipf_display_'].cipf_display_carte_renouvellement.cipf_flex { display: flex !important; }
|
||||||
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
[class*='cipf_display_'].cipf_display_compte_carte_expiree { display: block !important; }
|
||||||
|
[class*='cipf_display_'].cipf_display_compte_carte_expiree.cipf_flex { display: flex !important; }
|
||||||
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
[class*='cipf_display_'].cipf_display_compte_carte_valide { display: block !important; }
|
||||||
|
[class*='cipf_display_'].cipf_display_compte_carte_valide.cipf_flex { display: flex !important; }
|
||||||
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
[class*='cipf_display_'].cipf_display_compte_doit_payer { display: block !important; }
|
||||||
|
[class*='cipf_display_'].cipf_display_compte_doit_payer.cipf_flex { display: flex !important; }
|
||||||
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
[class*='cipf_display_'].cipf_display_compte_en_attente_invalide { display: block !important; }
|
||||||
|
[class*='cipf_display_'].cipf_display_compte_en_attente_invalide.cipf_flex { display: flex !important; }
|
||||||
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
[class*='cipf_display_'].cipf_display_compte_en_attente_valide { display: block !important; }
|
||||||
|
[class*='cipf_display_'].cipf_display_compte_en_attente_valide.cipf_flex { display: flex !important; }
|
||||||
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
[class*='cipf_display_'].cipf_display_compte_nouveau_prof { display: block !important; }
|
||||||
|
[class*='cipf_display_'].cipf_display_compte_nouveau_prof.cipf_flex { display: flex !important; }
|
||||||
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
[class*='cipf_display_'].cipf_display_page_partenaire_brouillon { display: block !important; }
|
||||||
|
[class*='cipf_display_'].cipf_display_page_partenaire_brouillon.cipf_flex { display: flex !important; }
|
||||||
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
[class*='cipf_display_'].cipf_display_page_partenaire_publiee { display: block !important; }
|
||||||
|
[class*='cipf_display_'].cipf_display_page_partenaire_publiee.cipf_flex { display: flex !important; }
|
||||||
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
[class*='cipf_display_'].cipf_display_paiement_aucun { display: block !important; }
|
||||||
|
[class*='cipf_display_'].cipf_display_paiement_aucun.cipf_flex { display: flex !important; }
|
||||||
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
[class*='cipf_display_'].cipf_display_paiement_echec { display: block !important; }
|
||||||
|
[class*='cipf_display_'].cipf_display_paiement_echec.cipf_flex { display: flex !important; }
|
||||||
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
[class*='cipf_display_'].cipf_display_paiement_en_cours { display: block !important; }
|
||||||
|
[class*='cipf_display_'].cipf_display_paiement_en_cours.cipf_flex { display: flex !important; }
|
||||||
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
[class*='cipf_display_'].cipf_display_paiement_reussi { display: block !important; }
|
||||||
|
[class*='cipf_display_'].cipf_display_paiement_reussi.cipf_flex { display: flex !important; }
|
||||||
|
|
||||||
4
plugins/cipf_plugin/css/display_states/type_paypal.css
Normal file
4
plugins/cipf_plugin/css/display_states/type_paypal.css
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
[class*='cipf_display_'].cipf_display_type_paypal { display: block !important; }
|
||||||
|
[class*='cipf_display_'].cipf_display_type_paypal.cipf_flex { display: flex !important; }
|
||||||
|
|
||||||
4
plugins/cipf_plugin/css/display_states/type_virement.css
Normal file
4
plugins/cipf_plugin/css/display_states/type_virement.css
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
[class*='cipf_display_'].cipf_display_type_virement { display: block !important; }
|
||||||
|
[class*='cipf_display_'].cipf_display_type_virement.cipf_flex { display: flex !important; }
|
||||||
|
|
||||||
34
plugins/cipf_plugin/css/fipf_user_profile.css
Normal file
34
plugins/cipf_plugin/css/fipf_user_profile.css
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* [/] Options personnelles,
|
||||||
|
* [/] À propos du compte,
|
||||||
|
* [/] Mots de passe d’application,
|
||||||
|
* [/] Login/Signup
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
*/
|
||||||
|
form#your-profile h2:has(+ .form-table .user-rich-editing-wrap),
|
||||||
|
form#your-profile .form-table:has(.user-rich-editing-wrap) {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
*/
|
||||||
|
form#your-profile h2:has(+ .form-table .user-description-wrap),
|
||||||
|
form#your-profile .form-table:has(.user-description-wrap) {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
*/
|
||||||
|
form#your-profile #application-passwords-section {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
*/
|
||||||
|
form#your-profile h2:has(+ .form-table.xoo-aff-form-table),
|
||||||
|
form#your-profile .form-table.xoo-aff-form-table {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
3
plugins/cipf_plugin/css/partner_page.css
Normal file
3
plugins/cipf_plugin/css/partner_page.css
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
.partenaire_propre_page_cipf {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
3
plugins/cipf_plugin/css/partner_page_own.css
Normal file
3
plugins/cipf_plugin/css/partner_page_own.css
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
div.partenaire_propre_page_cipf {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
Plugin Name: cipf_plugin
|
|
||||||
Plugin URI:
|
|
||||||
Description:
|
|
||||||
Author: hugogogo
|
|
||||||
Version: 1.1.0
|
|
||||||
Author URI:
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* it means someone outside wp is accessing the file, in this case kill it.
|
|
||||||
*/
|
|
||||||
if (!defined('ABSPATH')) {
|
|
||||||
die('You can not access this file!');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* plugin dir root
|
|
||||||
PLGNTLS_class::set_root_dir( plugin_dir_path(__FILE__), plugin_dir_url(__FILE__) );
|
|
||||||
*/
|
|
||||||
include_once( plugin_dir_path(__FILE__) . '/utils/plgntls_class.php');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* general inclusions
|
|
||||||
*/
|
|
||||||
// utils :
|
|
||||||
include_once(PLGNTLS_class::root_path() . 'php/utils/globals.php');
|
|
||||||
include_once(PLGNTLS_class::root_path() . 'utils/console_log.php');
|
|
||||||
|
|
||||||
include_once(PLGNTLS_class::root_path() . 'php/admin_menu/example_menu.php');
|
|
||||||
|
|
||||||
include_once(PLGNTLS_class::root_path() . 'php/paypal/paypal.php');
|
|
||||||
|
|
||||||
include_once(PLGNTLS_class::root_path() . '/php/user_infos.php');
|
|
||||||
//include_once(PLGNTLS_class::root_path() . '/php/hide_admin.php');
|
|
||||||
//include_once(PLGNTLS_class::root_path() . '/php/menus.php');
|
|
||||||
include_once(PLGNTLS_class::root_path() . 'php/register_partenaires.php');
|
|
||||||
include_once(PLGNTLS_class::root_path() . 'php/redirections.php');
|
|
||||||
include_once(PLGNTLS_class::root_path() . 'php/author_restriction.php');
|
|
||||||
include_once(PLGNTLS_class::root_path() . 'php/filter_mail.php');
|
|
||||||
include_once(PLGNTLS_class::root_path() . 'php/prof_check_page.php');
|
|
||||||
include_once(PLGNTLS_class::root_path() . 'php/renew_card.php');
|
|
||||||
//include_once(PLGNTLS_class::root_path() . 'php/reset_card_form.php');
|
|
||||||
include_once(PLGNTLS_class::root_path() . 'php/partner_check_page.php');
|
|
||||||
include_once(PLGNTLS_class::root_path() . 'php/format_user_infos.php');
|
|
||||||
include_once(PLGNTLS_class::root_path() . 'php/admin_modif_prof.php');
|
|
||||||
|
|
||||||
|
|
||||||
// form builder patch :
|
|
||||||
/*
|
|
||||||
include_once(PLGNTLS_class::root_path() . 'php/form_builder_patch/url_validation.php');
|
|
||||||
include_once(PLGNTLS_class::root_path() . 'php/form_builder_patch/multiple_modals.php');
|
|
||||||
include_once(PLGNTLS_class::root_path() . 'php/form_builder_patch/form_calculation.php');
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
||||||
197
plugins/cipf_plugin/html/menu/cipf_menu.html
Normal file
197
plugins/cipf_plugin/html/menu/cipf_menu.html
Normal file
@@ -0,0 +1,197 @@
|
|||||||
|
<style>
|
||||||
|
h1 {
|
||||||
|
margin-left: 15px;
|
||||||
|
margin-top: 50px;
|
||||||
|
}
|
||||||
|
form {
|
||||||
|
margin: 15px;
|
||||||
|
border: 1px solid black;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
form > div {
|
||||||
|
margin: 20px 0px;
|
||||||
|
}
|
||||||
|
.define_paypal_credentials_cipf input {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
form .vertical_wrapper_cipf {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
form textarea {
|
||||||
|
resize: vertical;
|
||||||
|
height: 120px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* form emails
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
form.emails_form_cipf {
|
||||||
|
margin: 10px;
|
||||||
|
padding: 10px;
|
||||||
|
> input[type="submit"] {
|
||||||
|
margin-left: 15px;
|
||||||
|
}
|
||||||
|
details.set_email_options_cipf {
|
||||||
|
margin: 15px;
|
||||||
|
padding: 0px 20px;
|
||||||
|
border: 1px solid black;
|
||||||
|
summary {
|
||||||
|
padding: 20px 0px;
|
||||||
|
cursor: grab;
|
||||||
|
h2 {
|
||||||
|
display: inline;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.email_type_wrapper_cipf {
|
||||||
|
margin-bottom: 50px;
|
||||||
|
.send_or_not_cipf {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
.send_or_not_cipf:has(input:not(:checked)) + .email_options_cipf {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.email_options_cipf {
|
||||||
|
padding-left: 20px;
|
||||||
|
border-left: 1px solid black;
|
||||||
|
label {
|
||||||
|
margin: 10px 0px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<!-- https://developer.wordpress.org/reference/hooks/admin_post_action/ -->
|
||||||
|
<h1>paypal credentials</h1>
|
||||||
|
<?php echo Plgntls::open_form_option($option_paypal['_name']); ?>
|
||||||
|
<div class="define_paypal_credentials_cipf define_paypal_client_id_cipf vertical_wrapper_cipf">
|
||||||
|
<label for="paypal_client_id_cipf">client id : </label>
|
||||||
|
<input type="text" id="paypal_client_id_cipf" name="client_id" value="<?php echo $option_paypal['client_id']; ?>" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="define_paypal_credentials_cipf define_paypal_secret_id_cipf vertical_wrapper_cipf">
|
||||||
|
<label for="paypal_client_secret_cipf">client secret : </label>
|
||||||
|
<input type="text" id="paypal_client_secret_cipf" name="client_secret" value="<?php echo $option_paypal['client_secret']; ?>" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="choose_sandbox_live_cipf choose_sandbox_cipf">
|
||||||
|
<input type="radio" id="sandbox" name="sandbox_or_live" value="sandbox" <?php if ($option_paypal['is_sandbox'] === true) {echo 'checked';} ?> />
|
||||||
|
<label for="sandbox">sandbox</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="choose_sandbox_live_cipf choose_live_cipf">
|
||||||
|
<input type="radio" id="live" name="sandbox_or_live" value="live" <?php if ($option_paypal['is_sandbox'] === false) {echo 'checked';} ?> />
|
||||||
|
<label for="live">live</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<input type="submit" value="send"/>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<!--
|
||||||
|
-->
|
||||||
|
<h1>messages apres paiement, avant redirection</h1>
|
||||||
|
<?php echo Plgntls::open_form_option($option_payment['_name']); ?>
|
||||||
|
<div class="define_payment_message_cipf vertical_wrapper_cipf">
|
||||||
|
<label for="define_payment_message_success_cipf">paiement réussi : </label>
|
||||||
|
<textarea id="define_payment_message_success_cipf" name="message_success"><?php echo esc_html(stripslashes($option_payment['success'])); ?></textarea>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="define_payment_message_cipf vertical_wrapper_cipf">
|
||||||
|
<label for="define_payment_message_failure_cipf">paiement echec : </label>
|
||||||
|
<textarea id="define_payment_message_failure_cipf" name="message_failure"><?php echo esc_html(stripslashes($option_payment['failure'])); ?></textarea>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="define_payment_message_cipf vertical_wrapper_cipf">
|
||||||
|
<label for="define_payment_message_problem_cipf">paiement problem (dans le cas où le paiement est réussi, mais il y eu une erreur dans son traitement sur le site) : </label>
|
||||||
|
<textarea id="define_payment_message_problem_cipf" name="message_problem"><?php echo esc_html(stripslashes($option_payment['problem'])); ?></textarea>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<input type="submit" value="send"/>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<!--
|
||||||
|
'payment_success'=>[
|
||||||
|
|
||||||
|
'notification_send'=>true,
|
||||||
|
'notification_to'=>'$$__admin_email__$$',
|
||||||
|
'notification_subject'=>"paiement réussi",
|
||||||
|
'notification_message'=>"par ici la monnaie",
|
||||||
|
|
||||||
|
'confirmation_send'=>true,
|
||||||
|
'confirmation_subject'=>"paiement réussi",
|
||||||
|
'confirmation_message'=>"donne l'argent",
|
||||||
|
-->
|
||||||
|
<h1>emails :</h1>
|
||||||
|
<?php echo Plgntls::open_form_option($option_emails['_name'], 'POST', 'emails_form_cipf'); ?>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
foreach($option_emails as $name => $email_options) {
|
||||||
|
if ($name === '_name') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<details class="set_email_options_cipf">
|
||||||
|
<summary><h2><?php echo esc_html(stripslashes($email_options['name'])); ?> :</h2></summary>
|
||||||
|
|
||||||
|
<div class="email_type_wrapper_cipf email_type_notification_wrapper_cipf">
|
||||||
|
|
||||||
|
<div class="send_or_not_cipf">
|
||||||
|
<input type="checkbox" id="<?php echo esc_html(stripslashes($name)); ?>_notification_cipf" name="<?php echo esc_html(stripslashes($name)); ?>_notification_send" <?php if ($email_options['notification_send'] === true) {echo 'checked';} ?> />
|
||||||
|
<label for="<?php echo esc_html(stripslashes($name)); ?>_notification_cipf">envoyer une notification ?</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="email_options_cipf">
|
||||||
|
|
||||||
|
<div class="vertical_wrapper_cipf">
|
||||||
|
<label for="<?php echo esc_html(stripslashes($name)); ?>_notification_to_cipf">destinataire : </label>
|
||||||
|
<input type="text" id="<?php echo esc_html(stripslashes($name)); ?>_notification_to_cipf" name="<?php echo esc_html(stripslashes($name)); ?>_notification_to" value="<?php echo esc_html(stripslashes($email_options['notification_to'])); ?>" />
|
||||||
|
</div>
|
||||||
|
<div class="vertical_wrapper_cipf">
|
||||||
|
<label for="<?php echo esc_html(stripslashes($name)); ?>_notification_subject_cipf">sujet : </label>
|
||||||
|
<input type="text" id="<?php echo esc_html(stripslashes($name)); ?>_notification_subject_cipf" name="<?php echo esc_html(stripslashes($name)); ?>_notification_subject" value="<?php echo esc_html(stripslashes($email_options['notification_subject'])); ?>" />
|
||||||
|
</div>
|
||||||
|
<div class="vertical_wrapper_cipf">
|
||||||
|
<label for="<?php echo esc_html(stripslashes($name)); ?>_notification_message_cipf">message : </label>
|
||||||
|
<textarea id="<?php echo esc_html(stripslashes($name)); ?>_notification_message_cipf" name="<?php echo esc_html(stripslashes($name)); ?>_notification_message"><?php echo esc_html(stripslashes($email_options['notification_message'])); ?></textarea>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="email_type_wrapper_cipf email_type_confirmation_wrapper_cipf">
|
||||||
|
|
||||||
|
<div class="send_or_not_cipf">
|
||||||
|
<input type="checkbox" id="<?php echo esc_html(stripslashes($name)); ?>_confirmation_cipf" name="<?php echo esc_html(stripslashes($name)); ?>_confirmation_send" <?php if ($email_options['confirmation_send'] === true) {echo 'checked';} ?> />
|
||||||
|
<label for="<?php echo esc_html(stripslashes($name)); ?>_confirmation_cipf">envoyer une confirmation ?</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="email_options_cipf">
|
||||||
|
|
||||||
|
<div class="vertical_wrapper_cipf">
|
||||||
|
<label for="<?php echo esc_html(stripslashes($name)); ?>_confirmation_subject_cipf">sujet : </label>
|
||||||
|
<input type="text" id="<?php echo esc_html(stripslashes($name)); ?>_confirmation_subject_cipf" name="<?php echo esc_html(stripslashes($name)); ?>_confirmation_subject" value="<?php echo esc_html(stripslashes($email_options['confirmation_subject'])); ?>" />
|
||||||
|
</div>
|
||||||
|
<div class="vertical_wrapper_cipf">
|
||||||
|
<label for="<?php echo esc_html(stripslashes($name)); ?>_confirmation_message_cipf">message : </label>
|
||||||
|
<textarea id="<?php echo esc_html(stripslashes($name)); ?>_confirmation_message_cipf" name="<?php echo esc_html(stripslashes($name)); ?>_confirmation_message"><?php echo esc_html(stripslashes($email_options['confirmation_message'])); ?></textarea>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</details>
|
||||||
|
<?php } ?>
|
||||||
|
|
||||||
|
<input type="submit" value="send"/>
|
||||||
|
</form>
|
||||||
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
<input type='text' id='mytext'>
|
|
||||||
<button id='mybutton'>send</button>
|
|
||||||
|
|
||||||
<input type='text' id='mytext_2'>
|
|
||||||
<button id='mybutton_2'>send</button>
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
cipf_admin_activate_prof_form
|
|
||||||
*/
|
|
||||||
|
|
||||||
function admin_activate_form_submit_prevent_CIPF() {
|
|
||||||
let form_activate_prof = document.querySelector('#cipf_admin_activate_prof_form form');
|
|
||||||
console.log("form:");
|
|
||||||
console.log(form_activate_prof);
|
|
||||||
if (form_activate_prof === null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
function handle_form(event) {
|
|
||||||
event.preventDefault();
|
|
||||||
let form_data = new FormData(event.target);
|
|
||||||
for (var pair of form_data.entries()) {
|
|
||||||
console.log(pair[0]+ ': ' + pair[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
form_activate_prof.addEventListener('submit', handle_form);
|
|
||||||
}
|
|
||||||
admin_activate_form_submit_prevent_CIPF();
|
|
||||||
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
|
|
||||||
import { test_fetch } from './example_submenu.js';
|
|
||||||
|
|
||||||
test_fetch();
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
|
|
||||||
const inputElement2 = document.getElementById('mytext_2');
|
|
||||||
const sendButton2 = document.getElementById('mybutton_2');
|
|
||||||
|
|
||||||
sendButton2.addEventListener('click', () => {
|
|
||||||
let inputValue = inputElement2.value;
|
|
||||||
inputValue = {
|
|
||||||
key1: 'value1',
|
|
||||||
key2: 'value2'
|
|
||||||
};
|
|
||||||
inputValue = JSON.stringify(inputValue);
|
|
||||||
console.log("inputValue:");
|
|
||||||
console.log(inputValue);
|
|
||||||
PLGNTLS_fetch('/plgntls/get_data', {
|
|
||||||
method: "POST",
|
|
||||||
})
|
|
||||||
//PLGNTLS_fetch('get_data', {body: {inputValue}})
|
|
||||||
.then((response) => response.json())
|
|
||||||
.then((data) => {
|
|
||||||
console.log("dataaa: ");
|
|
||||||
console.log(data);
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.log("error: ");
|
|
||||||
console.log(error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
|
|
||||||
import { PLGNTLS_fetch } from '../../utils/plgntls_fetch.js';
|
|
||||||
|
|
||||||
export function test_fetch() {
|
|
||||||
const inputElement = document.getElementById('mytext');
|
|
||||||
const sendButton = document.getElementById('mybutton');
|
|
||||||
|
|
||||||
sendButton.addEventListener('click', () => {
|
|
||||||
let inputValue = inputElement.value;
|
|
||||||
inputValue = {
|
|
||||||
key1: 'value1',
|
|
||||||
key2: 'value2'
|
|
||||||
};
|
|
||||||
inputValue = JSON.stringify(inputValue);
|
|
||||||
console.log("inputValue:");
|
|
||||||
console.log(inputValue);
|
|
||||||
PLGNTLS_fetch('/plgntls/get_data', {
|
|
||||||
method: "POST",
|
|
||||||
})
|
|
||||||
//PLGNTLS_fetch('get_data', {body: {inputValue}})
|
|
||||||
.then((response) => response.json())
|
|
||||||
.then((data) => {
|
|
||||||
console.log("dataaa: ");
|
|
||||||
console.log(data);
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.log("error: ");
|
|
||||||
console.log(error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
import { resultMessage } from './result_message.js';
|
import { resultMessage } from './result_message.js';
|
||||||
import { PLGNTLS_fetch } from '../../utils/plgntls_fetch.js';
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
|
|
||||||
import { resultMessage } from './result_message.js';
|
import { resultMessage } from './result_message.js';
|
||||||
import { PLGNTLS_fetch } from '../../utils/plgntls_fetch.js';
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @see https://developer.paypal.com/docs/checkout/standard/integrate/#link-integratebackend
|
* @see https://developer.paypal.com/docs/checkout/standard/integrate/#link-integratebackend
|
||||||
@@ -22,6 +20,7 @@ export async function onApprove(data, actions) {
|
|||||||
// (1) Recoverable INSTRUMENT_DECLINED -> call actions.restart()
|
// (1) Recoverable INSTRUMENT_DECLINED -> call actions.restart()
|
||||||
// (2) Other non-recoverable errors -> Show a failure message
|
// (2) Other non-recoverable errors -> Show a failure message
|
||||||
// (3) Successful transaction -> Show confirmation or thank you message
|
// (3) Successful transaction -> Show confirmation or thank you message
|
||||||
|
// + hugogogo treatment error but success order
|
||||||
|
|
||||||
const errorDetail = orderData?.details?.[0];
|
const errorDetail = orderData?.details?.[0];
|
||||||
|
|
||||||
@@ -35,23 +34,28 @@ export async function onApprove(data, actions) {
|
|||||||
throw new Error(`${errorDetail.description} (${orderData.debug_id})`);
|
throw new Error(`${errorDetail.description} (${orderData.debug_id})`);
|
||||||
}
|
}
|
||||||
else if (!orderData.purchase_units) {
|
else if (!orderData.purchase_units) {
|
||||||
|
if (orderData.ERROR_TREATMENT) {
|
||||||
|
console.log("Capture result",orderData);
|
||||||
|
resultMessage(PLGNTLS_data.paypal_message_problem);
|
||||||
|
}
|
||||||
|
else {
|
||||||
throw new Error(JSON.stringify(orderData));
|
throw new Error(JSON.stringify(orderData));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
// (3) Successful transaction -> Show confirmation or thank you message
|
// (3) Successful transaction -> Show confirmation or thank you message
|
||||||
// Or go to another URL: actions.redirect('thank_you.html');
|
// Or go to another URL: actions.redirect('thank_you.html');
|
||||||
const transaction =
|
const transaction =
|
||||||
orderData?.purchase_units?.[0]?.payments?.captures?.[0] ||
|
orderData?.purchase_units?.[0]?.payments?.captures?.[0] ||
|
||||||
orderData?.purchase_units?.[0]?.payments?.authorizations?.[0];
|
orderData?.purchase_units?.[0]?.payments?.authorizations?.[0];
|
||||||
// to show a message on page
|
console.log("Capture result",orderData);
|
||||||
//resultMessage(`Transaction ${transaction.status}: ${transaction.id}<br><br>See console for all available details`);
|
resultMessage(PLGNTLS_data.paypal_message_success);
|
||||||
resultMessage(eval(PLGNTLS_data.paypal_message_success));
|
|
||||||
actions.redirect(PLGNTLS_data.paypal_redirection_success);
|
actions.redirect(PLGNTLS_data.paypal_redirection_success);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
}
|
||||||
|
catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
//resultMessage(`Sorry, your transaction could not be processed...<br><br>${error}`);
|
resultMessage(PLGNTLS_data.paypal_message_failure);
|
||||||
resultMessage(eval(PLGNTLS_data.paypal_message_failure));
|
|
||||||
actions.redirect(PLGNTLS_data.paypal_redirection_failure);
|
actions.redirect(PLGNTLS_data.paypal_redirection_failure);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
|
|
||||||
//function PLGNTLS_fetch(url, options = {}) {
|
|
||||||
export function PLGNTLS_fetch(url, options = {}) {
|
|
||||||
console.log("inside PLGNTLS_fetch");
|
|
||||||
url = PLGNTLS_data.fetch_url + url;
|
|
||||||
|
|
||||||
options.headers = options.headers || {};
|
|
||||||
options.headers['X-WP-Nonce'] = PLGNTLS_data.fetch_nonce,
|
|
||||||
console.log("options:", options);
|
|
||||||
|
|
||||||
return fetch(url, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
95
plugins/cipf_plugin/php/admin_hide_bar.php
Normal file
95
plugins/cipf_plugin/php/admin_hide_bar.php
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
<?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!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* hide admin bar if access a front page and is not an admin
|
||||||
|
*/
|
||||||
|
function hide_admin_bar_CIPF() {
|
||||||
|
Plgntls::debug_infos(2);
|
||||||
|
$role_admin = Cipf::ROLE_ADMIN;
|
||||||
|
$role_fipf = Cipf::ROLE_FIPF;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* on admin page, don't hide bar of course
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (is_admin()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check multiple user roles
|
||||||
|
* https://developer.wordpress.org/reference/functions/current_user_can/#div-comment-4083
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$current_user = wp_get_current_user();
|
||||||
|
$allowed_roles = array($role_admin, $role_fipf);
|
||||||
|
if (array_intersect($allowed_roles, $current_user->roles)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
show_admin_bar(false);
|
||||||
|
}
|
||||||
|
add_action('after_setup_theme', 'hide_admin_bar_CIPF');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* prevent users to access admin page
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function restrict_admin_access_CIPF() {
|
||||||
|
Plgntls::debug_infos(2);
|
||||||
|
$role_admin = Cipf::ROLE_ADMIN;
|
||||||
|
$role_fipf = Cipf::ROLE_FIPF;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* this concerns logged_in users, for admin page
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (!is_user_logged_in()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!is_admin()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* some roles are allowed to access the admin panel
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$current_user = wp_get_current_user();
|
||||||
|
$allowed_roles = array($role_admin, $role_fipf);
|
||||||
|
if (array_intersect($allowed_roles, $current_user->roles))
|
||||||
|
return;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* every other roles are redirected
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
redirection_profil_CIPF();
|
||||||
|
}
|
||||||
|
//add_action('init', 'restrict_admin_access_CIPF', 100);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
242
plugins/cipf_plugin/php/admin_menu.php
Normal file
242
plugins/cipf_plugin/php/admin_menu.php
Normal file
@@ -0,0 +1,242 @@
|
|||||||
|
<?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!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* menu plugin
|
||||||
|
*/
|
||||||
|
function cipf_plugin_menu_CIPF() {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
Plgntls::add_menu('add_plugin_content_CIPF');
|
||||||
|
}
|
||||||
|
add_action('admin_menu', 'cipf_plugin_menu_CIPF');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function add_plugin_content_CIPF() {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$option_paypal_object = Cipf::OPTION_PAYPAL;
|
||||||
|
$option_payment_object = Cipf::OPTION_PAYMENT;
|
||||||
|
$option_emails_object = Cipf::OPTION_EMAILS;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* options
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$option_paypal = Plgntls::get_option_safe($option_paypal_object, true);
|
||||||
|
$option_payment = Plgntls::get_option_safe($option_payment_object, true);
|
||||||
|
//delete_option($option_emails_object['_name']);
|
||||||
|
$option_emails = Plgntls::get_option_safe($option_emails_object, true);
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
include(Plgntls::root_path() . '/html/menu/cipf_menu.html');
|
||||||
|
$html = ob_get_clean();
|
||||||
|
echo $html;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function update_payment_messages_option_CIPF($request, $option_name, $option_data, $option_default) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* success
|
||||||
|
* failure
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$success = '';
|
||||||
|
$failure = '';
|
||||||
|
$problem = '';
|
||||||
|
if (!isset($request['message_success'])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!isset($request['message_failure'])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!isset($request['message_problem'])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$success = $request['message_success'];
|
||||||
|
$failure = $request['message_failure'];
|
||||||
|
$problem = $request['message_problem'];
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* update the option with new values
|
||||||
|
*
|
||||||
|
set_payment_messages_option_CIPF($success, $failure);
|
||||||
|
*/
|
||||||
|
$data = array(
|
||||||
|
'success' => $success,
|
||||||
|
'failure' => $failure,
|
||||||
|
'problem' => $problem,
|
||||||
|
);
|
||||||
|
Plgntls::update_option_safe($option_name, $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function update_paypal_credentials_CIPF($request, $option_name, $option_data, $option_default) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* is sandbox or live ?
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$is_sandbox = false;
|
||||||
|
if (!isset($request['sandbox_or_live'])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ($request['sandbox_or_live'] === 'sandbox') {
|
||||||
|
$is_sandbox = true;
|
||||||
|
}
|
||||||
|
else if ($request['sandbox_or_live'] === 'live') {
|
||||||
|
$is_sandbox = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* client id
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$client_id = '';
|
||||||
|
if (!isset($request['client_id'])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$client_id = $request['client_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* client secret
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$client_secret = '';
|
||||||
|
if (!isset($request['client_secret'])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$client_secret = $request['client_secret'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* update the option with new credentials
|
||||||
|
*
|
||||||
|
set_paypal_options_CIPF($is_sandbox, $client_id, $client_secret);
|
||||||
|
*/
|
||||||
|
$data = array(
|
||||||
|
'is_sandbox' => $is_sandbox,
|
||||||
|
'client_id' => $client_id,
|
||||||
|
'client_secret' => $client_secret,
|
||||||
|
);
|
||||||
|
Plgntls::update_option_safe($option_name, $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* update emails
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
//error_log("option_data after : " . json_encode($option_data));
|
||||||
|
|
||||||
|
Plgntls::update_option_safe($option_name, $option_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* utility function to update the emails
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
//}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* set notification/confirmation_send to false by default,
|
||||||
|
* because the request only contains the value 'on' if checked, nothing for false
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$email_options['notification_send'] = false;
|
||||||
|
$email_options['confirmation_send'] = false;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* loop through all options to update them
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
foreach ($email_options as $option => $value) {
|
||||||
|
if (!isset($request[$email_type.'_'.$option])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$new_value = $request[$email_type.'_'.$option];
|
||||||
|
if ($new_value === $value) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
<?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!');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* menu plugin
|
|
||||||
*/
|
|
||||||
function cipfcard_plugin_menu() {
|
|
||||||
PLGNTLS_class::debug_infos();
|
|
||||||
add_menu_page
|
|
||||||
(
|
|
||||||
'cipf_card', // webpage title
|
|
||||||
'cipf_card', // menu title
|
|
||||||
'manage_options', // capability
|
|
||||||
'cipfcard-plugin', // menu_slug
|
|
||||||
'cipfcard_plugin_content' // callback function to display page content
|
|
||||||
);
|
|
||||||
}
|
|
||||||
add_action('admin_menu', 'cipfcard_plugin_menu');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function cipfcard_plugin_content() {
|
|
||||||
PLGNTLS_class::debug_infos();
|
|
||||||
$cipfcard = new PLGNTLS_class();
|
|
||||||
|
|
||||||
$my_css = '
|
|
||||||
#mytext {
|
|
||||||
background-color: lightblue;
|
|
||||||
}
|
|
||||||
#mytext_2 {
|
|
||||||
background-color: lightgreen;
|
|
||||||
}
|
|
||||||
';
|
|
||||||
echo $cipfcard->add_to_front( array(
|
|
||||||
array("js/menu/example_menu.js", 'type'=>'module'),
|
|
||||||
"css/menu/menu.css",
|
|
||||||
"PLGNTLS_menu_css" => array('css'=>$my_css),
|
|
||||||
"js/menu/example_menu_2.js",
|
|
||||||
"html/menu/example_menu.html",
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
||||||
ajax
|
|
||||||
- https://stackoverflow.com/questions/43557755/how-to-call-ajax-in-wordpress
|
|
||||||
- in `add_action( 'wp_ajax_get_data', 'my_ajax_handler' );`
|
|
||||||
the 'wp_ajax_get_data' is a hooks formated as 'wp_ajax_{$action}'
|
|
||||||
the `$action` param is passed in the data object of the ajax call
|
|
||||||
- to access the content of the data object properties of the ajax call :
|
|
||||||
use $_POST['property_name']
|
|
||||||
*/
|
|
||||||
function cipfcard_menu_fetch_handler() {
|
|
||||||
PLGNTLS_class::debug_infos();
|
|
||||||
return new WP_REST_Response('hello', 200);
|
|
||||||
}
|
|
||||||
function cipfcard_menu_endpoint() {
|
|
||||||
PLGNTLS_class::debug_infos();
|
|
||||||
register_rest_route('plgntls', '/get_data', array(
|
|
||||||
'methods' => 'POST',
|
|
||||||
'callback' => 'cipfcard_menu_fetch_handler',
|
|
||||||
));
|
|
||||||
};
|
|
||||||
add_action('rest_api_init', 'cipfcard_menu_endpoint');
|
|
||||||
|
|
||||||
?>
|
|
||||||
@@ -1,207 +0,0 @@
|
|||||||
<?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!');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* custom action in php on custom form submission
|
|
||||||
* custom forms are not processed by divi form builder
|
|
||||||
* so they don't change between hooks before and after process
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function admin_validate_prof_CIPF() {
|
|
||||||
PLGNTLS_class::debug_infos();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* calling the action to validate from the FormBuilder hook
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function custom_form_admin_validate_prof_CIPF($form_id, $post_array, $form_type) {
|
|
||||||
PLGNTLS_class::debug_infos();
|
|
||||||
$admin_validate_prof_field = PLGNTLS_class::ADMIN_VALIDATE_PROF_FIELD;
|
|
||||||
|
|
||||||
if ($form_type !== 'custom')
|
|
||||||
return;
|
|
||||||
error_log("---");
|
|
||||||
error_log("in test_form_CIPF");
|
|
||||||
// error_log("form_id");
|
|
||||||
// error_log(json_encode($form_id));
|
|
||||||
// error_log("post_array");
|
|
||||||
// error_log(json_encode($post_array));
|
|
||||||
// error_log("form_type");
|
|
||||||
// error_log(json_encode($form_type));
|
|
||||||
|
|
||||||
$field_id = $post_array['field_id'];
|
|
||||||
$contains_id = in_array($admin_validate_prof_field, $field_id);
|
|
||||||
if ($contains_id === false)
|
|
||||||
return;
|
|
||||||
|
|
||||||
admin_validate_prof_CIPF();
|
|
||||||
}
|
|
||||||
add_action('df_before_process', 'custom_form_admin_validate_prof_CIPF', 10, 3);
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* calling the action to validate from the
|
|
||||||
*
|
|
||||||
function custom_link_intercept() {
|
|
||||||
PLGNTLS_class::debug_infos();
|
|
||||||
$query_page_redirection = PLGNTLS_class::QUERY_REDIRECTION_PROFIL;
|
|
||||||
|
|
||||||
// Check if the request contains ?QUERY_REDIRECTION_PROFIL
|
|
||||||
if(isset($_GET[$query_page_redirection])) {
|
|
||||||
admin_validate_prof_CIPF();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
add_action('init', 'custom_link_intercept');
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
before :
|
|
||||||
|
|
||||||
|
|
||||||
in test_form_CIPF
|
|
||||||
form_id
|
|
||||||
""
|
|
||||||
post_array
|
|
||||||
{"field_title":["\u00c9tat du compte"],"field_name":["de_fb_compte-actif"],"field_id":["de_fb_field_1"],"form_type_confirm":""}
|
|
||||||
form_type
|
|
||||||
"custom"
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
after :
|
|
||||||
|
|
||||||
|
|
||||||
in test_form_CIPF
|
|
||||||
form_id
|
|
||||||
""
|
|
||||||
post_array
|
|
||||||
{"field_title":["\u00c9tat du compte"],"field_name":["de_fb_compte-actif"],"field_id":["de_fb_field_1"],"form_type_confirm":""}
|
|
||||||
form_type
|
|
||||||
"custom"
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
exploded view :
|
|
||||||
|
|
||||||
{
|
|
||||||
"field_title":["\u00c9tat du compte"],
|
|
||||||
"field_name":["de_fb_compte-actif"],
|
|
||||||
"field_id":["de_fb_field_1"],
|
|
||||||
"form_type_confirm":""
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
{
|
|
||||||
"field_title":["\u00c9tat du compte"],
|
|
||||||
"field_name":["de_fb_compte-actif"],
|
|
||||||
"field_id":["de_fb_field_1"],
|
|
||||||
"compte-actif":"Actif",
|
|
||||||
"form_type_confirm":""
|
|
||||||
}
|
|
||||||
CIPF_admin_activation_prof
|
|
||||||
{
|
|
||||||
"field_title":["\u00c9tat du compte"],
|
|
||||||
"field_name":["compte-actif"],
|
|
||||||
"field_id":["cipf_admin_activation_prof"],
|
|
||||||
"compte-actif":"Inactif",
|
|
||||||
"form_type_confirm":""
|
|
||||||
}
|
|
||||||
|
|
||||||
--- with field test :
|
|
||||||
|
|
||||||
{
|
|
||||||
"field_title":["\u00c9tat du compte","test"],
|
|
||||||
"field_name":["compte-actif","de_fb_field_3"],
|
|
||||||
"field_id":["cipf_admin_activation_prof","de_fb_field_3"],
|
|
||||||
"field_3":"",
|
|
||||||
"form_type_confirm":""
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* ABORTED
|
|
||||||
* tried to receive the form in ajax from front with wp REST API
|
|
||||||
* but I cannot verify if the user is logged in
|
|
||||||
* so it does not work
|
|
||||||
*
|
|
||||||
function admin_validate_prof_form_CIPF($request) {
|
|
||||||
PLGNTLS_class::debug_infos();
|
|
||||||
$slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION;
|
|
||||||
|
|
||||||
error_log("-----");
|
|
||||||
error_log("inside admin_validate_prof_form_CIPF");
|
|
||||||
error_log("request");
|
|
||||||
error_log(json_encode($request));
|
|
||||||
error_log("_POST");
|
|
||||||
error_log(json_encode($_POST));
|
|
||||||
// _POST : {"field_title":["\u00c9tat du compte"],"field_name":["compte-actif"],"field_id":["cipf_admin_activate_prof"],"form_key":"40781-1","unique_id":"91eed9aa-2b92-4da7-a0b4-e94f24515223","form_type":"custom","divi-form-submit":"yes","form_id":"","form_type_confirm":""}
|
|
||||||
|
|
||||||
// Set up nocache headers before redirecting : https://developer.wordpress.org/reference/functions/wp_safe_redirect/#user-contributed-notes
|
|
||||||
nocache_headers();
|
|
||||||
$redirect_url = home_url() . '/' . $slug_page_redirection;
|
|
||||||
wp_redirect($redirect_url, 301);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
function endpoint_form_admin_activate_prof_CIPF() {
|
|
||||||
PLGNTLS_class::debug_infos();
|
|
||||||
$base_rest_route = PLGNTLS_class::URL_BASE_REST_ROUTE;
|
|
||||||
|
|
||||||
register_rest_route($base_rest_route, '/admin_prof_activate_form', array(
|
|
||||||
'methods' => 'POST',
|
|
||||||
'callback' => 'admin_validate_prof_form_CIPF',
|
|
||||||
));
|
|
||||||
};
|
|
||||||
add_action('rest_api_init', 'endpoint_form_admin_activate_prof_CIPF');
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* ABORTED
|
|
||||||
* enqueue script that should prevent the form to submit, but does not work
|
|
||||||
*
|
|
||||||
function admin_validate_prof_prevent_CIPF() {
|
|
||||||
PLGNTLS_class::debug_infos();
|
|
||||||
$handle = 'admin_prevent_submit';
|
|
||||||
$url = PLGNTLS_class::root_url() . 'js/admin_prevent_submit.js';
|
|
||||||
$dependencies = array();
|
|
||||||
$version = null;
|
|
||||||
$defer = true;
|
|
||||||
wp_enqueue_script($handle, $url, $dependencies, $version, $defer);
|
|
||||||
}
|
|
||||||
add_action('wp_enqueue_scripts', 'admin_validate_prof_prevent_CIPF');
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
||||||
36
plugins/cipf_plugin/php/admin_user_profil.php
Normal file
36
plugins/cipf_plugin/php/admin_user_profil.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?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!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 278 : ../../../wordpress_docker/volumes/wp_volume/wp-admin/user-edit.php
|
||||||
|
*
|
||||||
|
function admin_user_profil_css_CIPF($user_id) {
|
||||||
|
*/
|
||||||
|
function admin_user_profil_css_CIPF() {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$role_fipf = Cipf::ROLE_FIPF;
|
||||||
|
|
||||||
|
if (!current_user_can($role_fipf)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Plgntls::add_to_front(array('css/fipf_user_profile.css'));
|
||||||
|
}
|
||||||
|
add_action('user_edit_form_tag', 'admin_user_profil_css_CIPF');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
<?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 restrict_author_page_CIPF() {
|
|
||||||
PLGNTLS_class::debug_infos();
|
|
||||||
$role_fipf = PLGNTLS_class::ROLE_FIPF;
|
|
||||||
$role_admin = PLGNTLS_class::ROLE_ADMIN;
|
|
||||||
|
|
||||||
if (!is_author())
|
|
||||||
return;
|
|
||||||
|
|
||||||
$current_user = wp_get_current_user();
|
|
||||||
|
|
||||||
/*
|
|
||||||
* check multiple user roles
|
|
||||||
* https://developer.wordpress.org/reference/functions/current_user_can/#div-comment-4083
|
|
||||||
* if user->role is found in array of allowed role, no redirection needed
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
$allowed_roles = array($role_admin, $role_fipf);
|
|
||||||
if (array_intersect($allowed_roles, $current_user->roles))
|
|
||||||
return;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* get_queried_object_id() would work too
|
|
||||||
* here get_the_author_meta works and is more explicit
|
|
||||||
*
|
|
||||||
$author_id = get_queried_object_id();
|
|
||||||
*/
|
|
||||||
$author_id = get_the_author_meta( 'ID' );
|
|
||||||
|
|
||||||
$current_user_id = get_current_user_id();
|
|
||||||
|
|
||||||
if ($current_user_id != $author_id) {
|
|
||||||
// Set up nocache headers before redirecting : https://developer.wordpress.org/reference/functions/wp_safe_redirect/#user-contributed-notes
|
|
||||||
nocache_headers();
|
|
||||||
wp_redirect(home_url(), 301);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
add_action('template_redirect', 'restrict_author_page_CIPF', 10);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
||||||
115
plugins/cipf_plugin/php/display_css.php
Normal file
115
plugins/cipf_plugin/php/display_css.php
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
<?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 display_states_css_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$css_for_states = array();
|
||||||
|
Plgntls::add_to_front(array('css/display_states/_default.css'));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* etat paiement
|
||||||
|
* - 'en_cours'
|
||||||
|
* - 'reussi'
|
||||||
|
* - 'echec'
|
||||||
|
* - 'aucun'
|
||||||
|
*/
|
||||||
|
if (is_payment_success_CIPF($user_id)) {
|
||||||
|
$css_for_states[] = 'css/display_states/paiement_reussi.css';
|
||||||
|
set_payment_nothing_CIPF($user_id);
|
||||||
|
}
|
||||||
|
else if (is_payment_failure_CIPF($user_id)) {
|
||||||
|
$css_for_states[] = 'css/display_states/paiement_echec.css';
|
||||||
|
set_payment_nothing_CIPF($user_id);
|
||||||
|
}
|
||||||
|
else if (is_payment_started_CIPF($user_id)) {
|
||||||
|
$css_for_states[] = 'css/display_states/paiement_en_cours.css';
|
||||||
|
}
|
||||||
|
else if (is_payment_nothing_CIPF($user_id)) {
|
||||||
|
$css_for_states[] = 'css/display_states/paiement_aucun.css';
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* etat compte ('etat_compte') :
|
||||||
|
* 1. new . 'nouveau prof'
|
||||||
|
* 2. to_pay . 'doit payer'
|
||||||
|
* 3. valid . 'carte valide'
|
||||||
|
* 4. waiting_invalid . 'en attente invalide'
|
||||||
|
* 5. waiting_valid . 'en attente valide'
|
||||||
|
* 6. expired . 'carte expiree'
|
||||||
|
*/
|
||||||
|
if (is_account_new_CIPF($user_id)) {
|
||||||
|
$css_for_states[] = 'css/display_states/compte_nouveau_prof.css';
|
||||||
|
}
|
||||||
|
else if (is_account_to_pay_CIPF($user_id)) {
|
||||||
|
$css_for_states[] = 'css/display_states/compte_doit_payer.css';
|
||||||
|
}
|
||||||
|
else if (is_account_valid_CIPF($user_id)) {
|
||||||
|
$css_for_states[] = 'css/display_states/compte_carte_valide.css';
|
||||||
|
}
|
||||||
|
else if (is_account_waiting_invalid_CIPF($user_id)) {
|
||||||
|
$css_for_states[] = 'css/display_states/compte_en_attente_invalide.css';
|
||||||
|
}
|
||||||
|
else if (is_account_waiting_valid_CIPF($user_id)) {
|
||||||
|
$css_for_states[] = 'css/display_states/compte_en_attente_valide.css';
|
||||||
|
}
|
||||||
|
else if (is_account_expired_CIPF($user_id)) {
|
||||||
|
$css_for_states[] = 'css/display_states/compte_carte_expiree.css';
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* etat carte
|
||||||
|
* - 'Commande'
|
||||||
|
* - 'Renouvellement'
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (is_card_new_CIPF($user_id)) {
|
||||||
|
$css_for_states[] = 'css/display_states/carte_commande.css';
|
||||||
|
}
|
||||||
|
else if (is_card_renew_CIPF($user_id)) {
|
||||||
|
$css_for_states[] = 'css/display_states/carte_renouvellement.css';
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* paiement
|
||||||
|
* - 'Paypal'
|
||||||
|
* - 'Virement'
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (is_payment_method_paypal_CIPF($user_id)) {
|
||||||
|
$css_for_states[] = 'css/display_states/type_paypal.css';
|
||||||
|
}
|
||||||
|
else if (is_payment_method_transfert_CIPF($user_id)) {
|
||||||
|
$css_for_states[] = 'css/display_states/type_virement.css';
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* page partenaire
|
||||||
|
* - 'Publiee'
|
||||||
|
* - 'Brouillon'
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (is_page_publish_CIPF($user_id)) {
|
||||||
|
$css_for_states[] = 'css/display_states/page_partenaire_publish.css';
|
||||||
|
}
|
||||||
|
else if (is_page_draft_CIPF($user_id)) {
|
||||||
|
$css_for_states[] = 'css/display_states/page_partenaire_draft.css';
|
||||||
|
}
|
||||||
|
|
||||||
|
Plgntls::add_to_front($css_for_states);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
204
plugins/cipf_plugin/php/emails.php
Normal file
204
plugins/cipf_plugin/php/emails.php
Normal file
@@ -0,0 +1,204 @@
|
|||||||
|
<?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!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* events and emails :
|
||||||
|
*
|
||||||
|
* 1. [/] profs : payment_success : paypal payment success
|
||||||
|
* 2. [/] profs : payment_echec : paypal payment echec
|
||||||
|
* 3. [/] profs : transfert_success : validation transfert prof reussi, send email
|
||||||
|
* 4. [ ] partners : offer_expired : offres temporaires -> gerer qu'elles disparaissent apres la date de validite -> la passer en masquer
|
||||||
|
* 5. [ ] partners : offer_will_expire : la gestion des offres à échéance
|
||||||
|
* 6. [ ] prof : account_deleted : schedule event pour supprimer le compte xx temps (6 mois ?) apres fin de validite de la carte
|
||||||
|
* 7. [ ] prof : account_will_expire : faire rappels emails avant expiration
|
||||||
|
* 8. [ ] prof : account_expired : desactiver carte expiree
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
function prepare_emails_CIPF($email_name, $user_id) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$emails_option_object = Cipf::OPTION_EMAILS;
|
||||||
|
|
||||||
|
if (!isset($emails_option_object['_default'][$email_name])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_null($user_id)) {
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
}
|
||||||
|
$user = get_user_by('id', $user_id);
|
||||||
|
$user_email = $user->user_email;
|
||||||
|
$headers = array('Content-Type: text/html; charset=UTF-8');
|
||||||
|
|
||||||
|
|
||||||
|
$emails_option = Plgntls::get_option_safe($emails_option_object);
|
||||||
|
if (!$emails_option) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!isset($emails_option[$email_name])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$email = $emails_option[$email_name];
|
||||||
|
|
||||||
|
|
||||||
|
$emails = array();
|
||||||
|
if ($email['notification_send']) {
|
||||||
|
$tmp_email = array();
|
||||||
|
$tmp_email['to'] = $email['notification_to'];
|
||||||
|
$tmp_email['subject'] = $email['notification_subject'];
|
||||||
|
$tmp_email['message'] = $email['notification_message'];
|
||||||
|
$tmp_email['headers'] = $headers;
|
||||||
|
$emails[] = $tmp_email;
|
||||||
|
}
|
||||||
|
if ($email['confirmation_send']) {
|
||||||
|
$tmp_email = array();
|
||||||
|
$tmp_email['to'] = $user_email;
|
||||||
|
$tmp_email['subject'] = $email['confirmation_subject'];
|
||||||
|
$tmp_email['message'] = $email['confirmation_message'];
|
||||||
|
$tmp_email['headers'] = $headers;
|
||||||
|
$emails[] = $tmp_email;
|
||||||
|
}
|
||||||
|
return $emails;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function send_emails_CIPF($email_name, $user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$emails = prepare_emails_CIPF($email_name, $user_id);
|
||||||
|
if (false === $emails) {
|
||||||
|
error_log('Email preparing failed!: ' . json_encode($emails));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($emails as $email) {
|
||||||
|
$sent = wp_mail($email['to'], $email['subject'], $email['message'], $email['headers']);
|
||||||
|
}
|
||||||
|
if (!$sent) {
|
||||||
|
error_log('Email sending failed!: ' . json_encode($email));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//function email_payment_success_CIPF($user_id = null) {
|
||||||
|
// Plgntls::debug_infos();
|
||||||
|
//error_log("email payment success: " . json_encode($email_payment_success));
|
||||||
|
//
|
||||||
|
// send_email_CIPF($email_payment_success, $user_id);
|
||||||
|
// $user = get_user_by('id', $user_id);
|
||||||
|
//// $to = $user->user_email;
|
||||||
|
// $to = '$$__admin_email__$$';
|
||||||
|
// $subject = 'My Custom Email Subject';
|
||||||
|
// $message = 'Hello, This is a test email sent from my WordPress plugin!';
|
||||||
|
// $headers = array('Content-Type: text/html; charset=UTF-8');
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// // Check if the email was sent successfully
|
||||||
|
//}
|
||||||
|
|
||||||
|
/*
|
||||||
|
'payment_success'=>[
|
||||||
|
'notification_send'=>true,
|
||||||
|
'notification_to'=>'$$__admin_email__$$',
|
||||||
|
'notification_subject'=>"paiement réussi",
|
||||||
|
'notification_message'=>"par ici la monnaie",
|
||||||
|
'confirmation_send'=>true,
|
||||||
|
'confirmation_subject'=>"paiement réussi",
|
||||||
|
'confirmation_mesage'=>"donne l'argent",
|
||||||
|
],
|
||||||
|
// 2. profs : email : payment_failure : validation payment prof echec, send email
|
||||||
|
'payment_echec'=>[
|
||||||
|
'notification_send'=>true,
|
||||||
|
'notification_to'=>'$$__admin_email__$$',
|
||||||
|
'notification_subject'=>"",
|
||||||
|
'notification_message'=>"",
|
||||||
|
'confirmation_send'=>true,
|
||||||
|
'confirmation_subject'=>"",
|
||||||
|
'confirmation_mesage'=>"",
|
||||||
|
],
|
||||||
|
// 3. profs : email : transfert_success : validation transfert prof reussi, send email
|
||||||
|
'transfert_success'=>[
|
||||||
|
'notification_send'=>true,
|
||||||
|
'notification_to'=>'$$__admin_email__$$',
|
||||||
|
'notification_subject'=>"",
|
||||||
|
'notification_message'=>"",
|
||||||
|
'confirmation_send'=>true,
|
||||||
|
'confirmation_subject'=>"",
|
||||||
|
'confirmation_mesage'=>"",
|
||||||
|
],
|
||||||
|
// 4. profs : email : transfert_failures : validation transfert prof echec, send email
|
||||||
|
'transfert_echec'=>[
|
||||||
|
'notification_send'=>true,
|
||||||
|
'notification_to'=>'$$__admin_email__$$',
|
||||||
|
'notification_subject'=>"",
|
||||||
|
'notification_message'=>"",
|
||||||
|
'confirmation_send'=>true,
|
||||||
|
'confirmation_subject'=>"",
|
||||||
|
'confirmation_mesage'=>"",
|
||||||
|
],
|
||||||
|
// 5. partners : email : offer_expired : offres temporaires -> gerer qu'elles disparaissent apres la date de validite -> la passer en masquer
|
||||||
|
'offer_expired'=>[
|
||||||
|
'notification_send'=>true,
|
||||||
|
'notification_to'=>'$$__admin_email__$$',
|
||||||
|
'notification_subject'=>"",
|
||||||
|
'notification_message'=>"",
|
||||||
|
'confirmation_send'=>true,
|
||||||
|
'confirmation_subject'=>"",
|
||||||
|
'confirmation_mesage'=>"",
|
||||||
|
],
|
||||||
|
// 6. partners : email : offer_will_expire : la gestion des offres à échéance
|
||||||
|
'offer_will_expire'=>[
|
||||||
|
'notification_send'=>true,
|
||||||
|
'notification_to'=>'$$__admin_email__$$',
|
||||||
|
'notification_subject'=>"",
|
||||||
|
'notification_message'=>"",
|
||||||
|
'confirmation_send'=>true,
|
||||||
|
'confirmation_subject'=>"",
|
||||||
|
'confirmation_mesage'=>"",
|
||||||
|
],
|
||||||
|
// 7. payments : email : account_deleted : schedule event pour supprimer le compte xx temps (6 mois ?) apres fin de validite de la carte
|
||||||
|
'account_deleted'=>[
|
||||||
|
'notification_send'=>true,
|
||||||
|
'notification_to'=>'$$__admin_email__$$',
|
||||||
|
'notification_subject'=>"",
|
||||||
|
'notification_message'=>"",
|
||||||
|
'confirmation_send'=>true,
|
||||||
|
'confirmation_subject'=>"",
|
||||||
|
'confirmation_mesage'=>"",
|
||||||
|
],
|
||||||
|
// 8. payments : email : account_will_expire : faire rappels emails avant expiration
|
||||||
|
'eccount_will_expire'=>[
|
||||||
|
'notification_send'=>true,
|
||||||
|
'notification_to'=>'$$__admin_email__$$',
|
||||||
|
'notification_subject'=>"",
|
||||||
|
'notification_message'=>"",
|
||||||
|
'confirmation_send'=>true,
|
||||||
|
'confirmation_subject'=>"",
|
||||||
|
'confirmation_mesage'=>"",
|
||||||
|
],
|
||||||
|
// 9. payments : email : account_expired : desactiver carte expiree
|
||||||
|
'account_expired'=>[
|
||||||
|
'notification_send'=>true,
|
||||||
|
'notification_to'=>'$$__admin_email__$$',
|
||||||
|
'notification_subject'=>"",
|
||||||
|
'notification_message'=>"",
|
||||||
|
'confirmation_send'=>true,
|
||||||
|
'confirmation_subject'=>"",
|
||||||
|
'confirmation_mesage'=>"",
|
||||||
|
],
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -1,140 +0,0 @@
|
|||||||
<?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!');
|
|
||||||
}
|
|
||||||
|
|
||||||
include_once(PLGNTLS_class::root_path() . 'php/format_user_infos.php');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* callback to provide the user info corresponding to the $$key_word$$
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function replace_words_CIPF($matches, $user_id = null) {
|
|
||||||
PLGNTLS_class::debug_infos();
|
|
||||||
if ($user_id !== null) {
|
|
||||||
$current_user = get_user_by('id', $user_id);
|
|
||||||
}
|
|
||||||
else if (is_user_logged_in()) {
|
|
||||||
$current_user = wp_get_current_user();
|
|
||||||
$user_id = get_current_user_id();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($current_user === false)
|
|
||||||
return "";
|
|
||||||
|
|
||||||
$query = $matches[1];
|
|
||||||
$result = format_user_info_CIPF($query, $current_user, $user_id);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* if result is array, take the first element (not ideal)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
if (is_array($result))
|
|
||||||
$result = reset($result);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* if is special query __author_page__
|
|
||||||
* return author page url
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
if ($query === '__author_page__') {
|
|
||||||
$current_user_id = get_current_user_id();
|
|
||||||
$result = get_author_posts_url($current_user_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* if no match, return $$<query>$$
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
if (empty($result))
|
|
||||||
return $matches[0];
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* filter emails in the form-builder hook, before the wp_mail hook
|
|
||||||
* it receives the id of the user, no need to have the user still logged-in
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function filter_email_fb_CIPF($reply_body, $post_array) {
|
|
||||||
PLGNTLS_class::debug_infos();
|
|
||||||
$id = $post_array['ID'];
|
|
||||||
// pattern : anything surrounded by '$$', ex : $$value$$
|
|
||||||
$pattern = '/\$\$(.*?)\$\$/';
|
|
||||||
|
|
||||||
// inline callback, with 'use' to get the id
|
|
||||||
$new_body = preg_replace_callback($pattern, function($matches) use ($id) {
|
|
||||||
return replace_words_CIPF($matches, $id);
|
|
||||||
}, $reply_body);
|
|
||||||
|
|
||||||
return $new_body;
|
|
||||||
}
|
|
||||||
add_filter('df_confirmation_body', 'filter_email_fb_CIPF', 10, 2); // the receive an email
|
|
||||||
add_filter('df_notification_body', 'filter_email_fb_CIPF', 10, 2); // the admin receive a notification
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* filter emails at the final point : the wp_mail hook
|
|
||||||
* it uses a callback that rely on the logged-in user
|
|
||||||
* it will works well most of the time, but it's possible
|
|
||||||
* that a user logged out before the email is sent
|
|
||||||
* or event that a different user has already logged in
|
|
||||||
*/
|
|
||||||
function filter_email_wp_CIPF($args) {
|
|
||||||
PLGNTLS_class::debug_infos();
|
|
||||||
// pattern : anything surrounded by '$$', ex : $$value$$
|
|
||||||
$pattern = '/\$\$(.*?)\$\$/';
|
|
||||||
|
|
||||||
$old_body = $args['message'];
|
|
||||||
$new_body = preg_replace_callback($pattern, 'replace_words_CIPF', $old_body);
|
|
||||||
$args['message'] = $new_body;
|
|
||||||
|
|
||||||
return $args;
|
|
||||||
}
|
|
||||||
add_filter('wp_mail', 'filter_email_wp_CIPF', 10, 1);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
all filters in form_builder :
|
|
||||||
|
|
||||||
1 $body = apply_filters( 'df_notification_body', $body, $post_array );
|
|
||||||
2 $email = apply_filters( 'df_notifcation_recipient', $email, $form_id, $post_array );
|
|
||||||
3 $title = apply_filters( 'wpml_translate_single_string', $title_get, 'divi-form-builder', 'Edit Post Button Title Text' );
|
|
||||||
|
|
||||||
4 $body = apply_filters( 'df_contact_body', $body, $post_array );
|
|
||||||
5 $body = apply_filters( 'df_contact_body', $body, $post_array );
|
|
||||||
|
|
||||||
6 $email = apply_filters( 'df_contact_recipient', $email, $form_id, $post_array );
|
|
||||||
7 $email = apply_filters( 'df_contact_recipient', $email, $form_id, $processed_post_array );
|
|
||||||
|
|
||||||
8 $reply_body = apply_filters( 'df_confirmation_body', $reply_body, $post_array );
|
|
||||||
9 $reply_body = apply_filters( 'df_confirmation_body', $reply_body, $post_array );
|
|
||||||
10 $reply_body = apply_filters( 'df_confirmation_body', $reply_body, $post_array );
|
|
||||||
11 $reply_body = apply_filters( 'df_confirmation_body', $reply_body, $post_array );
|
|
||||||
|
|
||||||
12 $message_content = apply_filters( 'the_content', get_post_field( 'post_content', $message_array['layout'] ) );
|
|
||||||
13 $content = apply_filters( 'the_content', get_post_field( 'post_content', $message_array['layout'] ) );
|
|
||||||
14 $content = apply_filters( 'the_content', get_post_field( 'post_content', $html_content_divi_layout) );
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
<?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 add_form_calculation_patch_CIPF() {
|
|
||||||
PLGNTLS_class::debug_infos();
|
|
||||||
$handle = 'form_calculation_patch';
|
|
||||||
$url = PLGNTLS_class::root_url() . 'js/form_builder_patch/form_calculation.js';
|
|
||||||
$dependencies = array('de_fb_calc');
|
|
||||||
$version = null;
|
|
||||||
$defer = true;
|
|
||||||
wp_enqueue_script( $handle, $url, $dependencies, $version, $defer);
|
|
||||||
}
|
|
||||||
add_action('wp_enqueue_scripts', 'add_form_calculation_patch_CIPF', 999);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
<?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 test_modal_PLGNTLS() {
|
|
||||||
PLGNTLS_class::debug_infos();
|
|
||||||
$cipf_modal = new PLGNTLS_class();
|
|
||||||
$cipf_modal->add_to_front(
|
|
||||||
array(
|
|
||||||
'js/form_builder_patch/multiple_modals.js',
|
|
||||||
));
|
|
||||||
}
|
|
||||||
add_shortcode('test_modal', 'test_modal_PLGNTLS');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
<?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 format_user_info_CIPF($query, &$current_user, $user_id) {
|
|
||||||
PLGNTLS_class::debug_infos();
|
|
||||||
$output_date_format = PLGNTLS_class::USER_INFO_DATE_FORMAT;
|
|
||||||
|
|
||||||
$is_acf = false;
|
|
||||||
$is_date = false;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* check if it's an acf field
|
|
||||||
* first method : check if _field exist
|
|
||||||
*
|
|
||||||
$_acf_field = '_'.$query;
|
|
||||||
$acf_field = $current_user->$_acf_field;
|
|
||||||
if (!empty($acf_field))
|
|
||||||
$is_acf = true;
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* check if it's an acf field, and a date
|
|
||||||
* second method : check what get_field_object() returns
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
$acf_id = 'user_'.$user_id;
|
|
||||||
$acf_object = get_field_object($query, $acf_id);
|
|
||||||
if ($acf_object !== false)
|
|
||||||
$is_acf = true;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* if is acf, use the acf return format
|
|
||||||
* otherwise, use the default wordpress value
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
if ($is_acf)
|
|
||||||
$output = get_field($query, $acf_id);
|
|
||||||
else
|
|
||||||
$output = $current_user->$query;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* check if is date
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
if ($is_acf) {
|
|
||||||
$acf_type = $acf_object['type'];
|
|
||||||
if ($acf_type && $acf_type === "date_picker")
|
|
||||||
$is_date = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* if is date, transform format
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
if ($is_date) {
|
|
||||||
$acf_date_string = $acf_object['value'];
|
|
||||||
$acf_date_format = $acf_object['return_format'];
|
|
||||||
$date = date_create_from_format($acf_date_format, $acf_date_string);
|
|
||||||
$output = $date->format($output_date_format);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* return the result
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
while (is_array($output) && count($output) === 1)
|
|
||||||
$output = reset($output);
|
|
||||||
if (is_array($output) && count($output) === 0)
|
|
||||||
$output = '';
|
|
||||||
if (!is_string($output))
|
|
||||||
$output = json_encode($output, JSON_UNESCAPED_SLASHES);
|
|
||||||
return esc_html($output);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
<?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!');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* hide admin bar if access a front page and is not an admin
|
|
||||||
*/
|
|
||||||
function hide_admin_bar_CIPF() {
|
|
||||||
PLGNTLS_class::debug_infos();
|
|
||||||
$role_admin = PLGNTLS_class::ROLE_ADMIN;
|
|
||||||
|
|
||||||
if (!current_user_can($role_admin) && !is_admin()) {
|
|
||||||
show_admin_bar(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
add_action('after_setup_theme', 'hide_admin_bar_CIPF');
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
||||||
@@ -23,7 +23,7 @@ if (!defined('ABSPATH')) {
|
|||||||
* - $menu_redirect = 'www.un_autre_site.net/contact' -> https://www.un_autre_site.net/contact
|
* - $menu_redirect = 'www.un_autre_site.net/contact' -> https://www.un_autre_site.net/contact
|
||||||
*/
|
*/
|
||||||
function change_menu_logout($items){
|
function change_menu_logout($items){
|
||||||
PLGNTLS_class::debug_infos();
|
Plgntls::debug_infos();
|
||||||
$menu_title = 'special logout';
|
$menu_title = 'special logout';
|
||||||
|
|
||||||
// quelques urls utiles :
|
// quelques urls utiles :
|
||||||
|
|||||||
@@ -1,125 +0,0 @@
|
|||||||
<?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!');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* series of actions to do before printing a partner author page
|
|
||||||
*
|
|
||||||
function check_partner_page_CIPF() {
|
|
||||||
PLGNTLS_class::debug_infos();
|
|
||||||
|
|
||||||
// the way to find the id of the author of an author_page
|
|
||||||
$author_id = get_queried_object_id();
|
|
||||||
|
|
||||||
}
|
|
||||||
add_action('template_redirect', 'check_partner_page_CIPF', 11);
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
in test_partner_CIPF
|
|
||||||
|
|
||||||
form_id
|
|
||||||
"crea_partenaire"
|
|
||||||
|
|
||||||
post_array
|
|
||||||
{
|
|
||||||
"post_status":"publish",
|
|
||||||
"field_title":[
|
|
||||||
"Nom commercial",
|
|
||||||
"Votre site Internet",
|
|
||||||
"Dans quelle rubrique devez-vous para\u00eetre ? ",
|
|
||||||
"L\\'accroche en t\u00eate de page",
|
|
||||||
"Pr\u00e9sentez-vous",
|
|
||||||
"Votre logo ",
|
|
||||||
"Image principale",
|
|
||||||
"Voulez-vous afficher cette offre ?",
|
|
||||||
"Titre",
|
|
||||||
"Texte de l\\'offre",
|
|
||||||
"Image (facultatif)",
|
|
||||||
"Voulez-vous ajouter une offre ?",
|
|
||||||
"Voulez-vous afficher cette offre ?",
|
|
||||||
"Titre",
|
|
||||||
"Texte de l\\'offre",
|
|
||||||
"Image (facultatif)",
|
|
||||||
"Voulez-vous ajouter une offre ?",
|
|
||||||
"Voulez-vous afficher l\\'offre ?",
|
|
||||||
"Titre",
|
|
||||||
"Texte de l\\'offre",
|
|
||||||
"Image (facultatif)",
|
|
||||||
"slug"
|
|
||||||
],
|
|
||||||
"post_title":"test page partner",
|
|
||||||
"meta_input":[
|
|
||||||
"de_fb_url_partenaire",
|
|
||||||
"de_fb_logo_partenaire",
|
|
||||||
"de_fb_afficher_offre_1",
|
|
||||||
"de_fb_offre_1_titre",
|
|
||||||
"de_fb_offre_1_txt",
|
|
||||||
"de_fb_offre_1_image",
|
|
||||||
"de_fb_ajouter_offre_2",
|
|
||||||
"de_fb_afficher_offre_2",
|
|
||||||
"de_fb_offre_2_titre",
|
|
||||||
"de_fb_offre_2_txt",
|
|
||||||
"de_fb_offre_2_image",
|
|
||||||
"de_fb_ajouter_offre_3",
|
|
||||||
"de_fb_afficher_offre_3",
|
|
||||||
"de_fb_offre_3_titre",
|
|
||||||
"de_fb_offre_3_txt",
|
|
||||||
"de_fb_offre_3_image"
|
|
||||||
],
|
|
||||||
"url_partenaire":"",
|
|
||||||
"tax_input":["de_fb_category"],
|
|
||||||
"category":"autres",
|
|
||||||
"post_excerpt":"accroche test page partner",
|
|
||||||
"post_content":"presentation test page partner",
|
|
||||||
"_ajax_linking_nonce":"2088c0ea4f",
|
|
||||||
"logo_partenaire":"40763",
|
|
||||||
"post_thumbnail":"40764",
|
|
||||||
"afficher_offre_1":"Afficher",
|
|
||||||
"offre_1_titre":"titre offre 1",
|
|
||||||
"offre_1_txt":"text offre 1",
|
|
||||||
"offre_1_image":"",
|
|
||||||
"ajouter_offre_2":"Oui",
|
|
||||||
"afficher_offre_2":"Masquer",
|
|
||||||
"offre_2_titre":"titre offre 2",
|
|
||||||
"offre_2_txt":"text offre 2",
|
|
||||||
"offre_2_image":"",
|
|
||||||
"ajouter_offre_3":"Oui",
|
|
||||||
"afficher_offre_3":"Afficher",
|
|
||||||
"offre_3_titre":"titre offre 3",
|
|
||||||
"offre_3_txt":"text offre 3",
|
|
||||||
"offre_3_image":"",
|
|
||||||
"post_name":"test-page-partner",
|
|
||||||
"ID":"40765",
|
|
||||||
"form_type_confirm":""
|
|
||||||
}
|
|
||||||
|
|
||||||
form_type
|
|
||||||
"post"
|
|
||||||
|
|
||||||
|
|
||||||
function test_partner_CIPF($form_id, $post_array) {
|
|
||||||
error_log("---");
|
|
||||||
error_log("in test_partner_CIPF");
|
|
||||||
error_log("form_id");
|
|
||||||
error_log(json_encode($form_id));
|
|
||||||
error_log("post_array");
|
|
||||||
error_log(json_encode($post_array));
|
|
||||||
}
|
|
||||||
add_action( 'df_before_process', 'test_partner_CIPF', 10, 2);
|
|
||||||
add_action( 'df_after_process', 'test_partner_CIPF', 10, 2);
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
||||||
66
plugins/cipf_plugin/php/partners_form.php
Normal file
66
plugins/cipf_plugin/php/partners_form.php
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
<?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!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check if partner can access the form to create a new page
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function partner_form_creation_page_CIPF() {
|
||||||
|
Plgntls::debug_infos(2);
|
||||||
|
$role_partner = Cipf::ROLE_PARTNER;
|
||||||
|
$slug_partner_create_page = Cipf::SLUG_PARTNER_CREATE_PAGE;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* only for the partner form creation page
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (!is_page($slug_partner_create_page)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* redirect anyone that is not a partner
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (!is_user_logged_in()) {
|
||||||
|
redirect_home_CIPF();
|
||||||
|
}
|
||||||
|
if (!current_user_can($role_partner)) {
|
||||||
|
redirect_home_CIPF();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if a partner already has a page, redirect it
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
redirection_profil_CIPF();
|
||||||
|
}
|
||||||
|
add_action('template_redirect', 'partner_form_creation_page_CIPF');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
188
plugins/cipf_plugin/php/partners_page.php
Normal file
188
plugins/cipf_plugin/php/partners_page.php
Normal file
@@ -0,0 +1,188 @@
|
|||||||
|
<?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!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* utility function that checks if the current page is owned by the logged in partner
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function is_own_partner() {
|
||||||
|
Plgntls::debug_infos(2);
|
||||||
|
$role_partner = Cipf::ROLE_PARTNER;
|
||||||
|
|
||||||
|
if (!is_single()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!is_user_logged_in()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!current_user_can($role_partner)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
global $post;
|
||||||
|
if (is_null($post)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* upload scripts and styles on partner page
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function partner_page_scripts_CIPF() {
|
||||||
|
Plgntls::debug_infos(2);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if on post, load css
|
||||||
|
* - to hide partner own stuff
|
||||||
|
* - for states
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (!is_single()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
Plgntls::add_to_front(array('css/partner_page.css'));
|
||||||
|
$post_id = get_the_ID();
|
||||||
|
display_states_css_CIPF($post_id);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* then check if is partner own page
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (!is_own_partner()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* on partner own page, load css to show own stuff
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
Plgntls::add_to_front(array('css/partner_page_own.css'));
|
||||||
|
}
|
||||||
|
add_action('wp_enqueue_scripts', 'partner_page_scripts_CIPF', 11);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* listen to the front button to toggle page publish/draft
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function toggle_partner_page_CIPF() {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$toggle_partner_page = Cipf::QUERY_TOGGLE_PARTNER_PAGE;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check if :
|
||||||
|
* - is own partner
|
||||||
|
* - has query action
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (!is_own_partner()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
if (!isset($_GET['action'])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ($_GET['action'] !== $toggle_partner_page) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* get the post id and object
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$post_id = get_the_ID();
|
||||||
|
$current_post = get_post($post_id);
|
||||||
|
if (is_null($current_post)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* toogle the status
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if ($current_post->post_status === 'publish') {
|
||||||
|
wp_update_post(array(
|
||||||
|
'ID' => $post_id,
|
||||||
|
'post_status' => 'draft',
|
||||||
|
));
|
||||||
|
set_page_draft_CIPF($post_id);
|
||||||
|
}
|
||||||
|
else if ($current_post->post_status === 'draft') {
|
||||||
|
wp_update_post(array(
|
||||||
|
'ID' => $post_id,
|
||||||
|
'post_status' => 'publish',
|
||||||
|
));
|
||||||
|
set_page_publish_CIPF($post_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* redirects without the query
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$url = remove_query_arg('action');
|
||||||
|
error_log("url: " . $url);
|
||||||
|
wp_safe_redirect($url);
|
||||||
|
exit;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
add_action('template_redirect', 'toggle_partner_page_CIPF');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* early checks on partner page
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function page_partner_check_CIPF() {
|
||||||
|
Plgntls::debug_infos(2);
|
||||||
|
|
||||||
|
// is partner own page
|
||||||
|
if (!is_own_partner()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
|
||||||
|
$post_id = get_the_ID();
|
||||||
|
$current_post = get_post($post_id);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* checks if the acf state field is set accrodingly to page state
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if ($current_post->post_status === 'publish') {
|
||||||
|
set_page_publish_CIPF($post_id);
|
||||||
|
}
|
||||||
|
else if ($current_post->post_status === 'draft') {
|
||||||
|
set_page_draft_CIPF($post_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_action('wp', 'page_partner_check_CIPF', 11);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
71
plugins/cipf_plugin/php/partners_register.php
Normal file
71
plugins/cipf_plugin/php/partners_register.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!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* hook to add a field in the xootix form
|
||||||
|
* 30 : ../../../wordpress_docker/volumes/wp_volume/wp-content/plugins/easy-login-woocommerce/templates/global/xoo-el-register-section.php
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function add_fields_register_CIPF($args) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$role_partner = Cipf::ROLE_PARTNER;
|
||||||
|
$slug_partner_registration = Cipf::SLUG_PARTNER_REGISTRATION;
|
||||||
|
$input_hidden_role = Cipf::INPUT_HIDDEN_ROLE;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* compare current slug to partner-register slug
|
||||||
|
* if it match, add a hidden field
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
global $wp;
|
||||||
|
$current_slug = $wp->request;
|
||||||
|
if ($current_slug === $slug_partner_registration) {
|
||||||
|
echo "<input type='hidden' name='$input_hidden_role' value='$role_partner'>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_action('xoo_el_register_add_fields', 'add_fields_register_CIPF');
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* filter to modify user before xootix create new user
|
||||||
|
* 437 : ../../../wordpress_docker/volumes/wp_volume/wp-content/plugins/easy-login-woocommerce/includes/class-xoo-el-form-handler.php
|
||||||
|
*
|
||||||
|
* at registration, if form query is for partner
|
||||||
|
* -> change role to 'partenaire'
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function add_role_partners_CIPF($customer_data){
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$role_partner = Cipf::ROLE_PARTNER;
|
||||||
|
$input_hidden_role = Cipf::INPUT_HIDDEN_ROLE;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check query of form submit
|
||||||
|
* if contains parner, change role for partner
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (!isset($_POST[$input_hidden_role])) {
|
||||||
|
return $customer_data;
|
||||||
|
}
|
||||||
|
if ($_POST[$input_hidden_role] === $role_partner) {
|
||||||
|
$customer_data['role'] = $role_partner;
|
||||||
|
}
|
||||||
|
return $customer_data;
|
||||||
|
}
|
||||||
|
add_filter('xoo_el_register_new_customer_data', 'add_role_partners_CIPF', 10, 1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
133
plugins/cipf_plugin/php/payments.php
Normal file
133
plugins/cipf_plugin/php/payments.php
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
<?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 set_paypal_options_CIPF($is_sandbox, $client_id, $client_secret) {
|
||||||
|
// Plgntls::debug_infos();
|
||||||
|
// $option_paypal = Cipf::OPTION_PAYPAL;
|
||||||
|
//
|
||||||
|
// $option_data = array();
|
||||||
|
// $option_data['is_sandbox'] = $is_sandbox;
|
||||||
|
// $option_data['client_id'] = $client_id;
|
||||||
|
// $option_data['client_secret'] = $client_secret;
|
||||||
|
//
|
||||||
|
// update_option($option_paypal['_name'], serialize($option_data), '', 'no');
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//function get_paypal_options_CIPF() {
|
||||||
|
// Plgntls::debug_infos();
|
||||||
|
// $option_paypal = Cipf::OPTION_PAYPAL;
|
||||||
|
//
|
||||||
|
// $paypal_credentials_serialized = get_option($option_paypal['_name']);
|
||||||
|
// if (false === $paypal_credentials_serialized) {
|
||||||
|
// add_option($option_paypal['_name'], serialize($option_paypal['_default']), '', 'no');
|
||||||
|
// $paypal_credentials_serialized = get_option($option_paypal['_name']);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return unserialize($paypal_credentials_serialized);
|
||||||
|
//}
|
||||||
|
function get_paypal_options_CIPF() {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$option_paypal = Cipf::OPTION_PAYPAL;
|
||||||
|
|
||||||
|
return Plgntls::get_option_safe($option_paypal);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function get_paypal_client_id_CIPF() {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$paypal_credentials = get_paypal_options_CIPF();
|
||||||
|
return $paypal_credentials['client_id'];
|
||||||
|
}
|
||||||
|
function get_paypal_client_secret_CIPF() {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$paypal_credentials = get_paypal_options_CIPF();
|
||||||
|
return $paypal_credentials['client_secret'];
|
||||||
|
}
|
||||||
|
function get_paypal_api_base_url_CIPF() {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$paypal_credentials = get_paypal_options_CIPF();
|
||||||
|
|
||||||
|
$paypal_base_url = '';
|
||||||
|
$is_sandbox = $paypal_credentials['is_sandbox'];
|
||||||
|
if ($is_sandbox) {
|
||||||
|
$paypal_base_url = Cipf::PAYPAL_SBOX_API_BASE_URL;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$paypal_base_url = Cipf::PAYPAL_LIVE_API_BASE_URL;
|
||||||
|
}
|
||||||
|
return $paypal_base_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* OPTIONS MESSAGES PAIMENT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
//function set_payment_messages_option_CIPF($success, $failure) {
|
||||||
|
// Plgntls::debug_infos();
|
||||||
|
// $option_payment = Cipf::OPTION_PAYMENT;
|
||||||
|
//
|
||||||
|
// $option_data = array();
|
||||||
|
// $option_data['success'] = $success;
|
||||||
|
// $option_data['failure'] = $failure;
|
||||||
|
//
|
||||||
|
// update_option($option_payment['_name'], serialize($option_data), '', 'no');
|
||||||
|
//}
|
||||||
|
|
||||||
|
//function get_payment_messages_option_CIPF() {
|
||||||
|
// Plgntls::debug_infos();
|
||||||
|
// $option_payment = Cipf::OPTION_PAYMENT;
|
||||||
|
//
|
||||||
|
// $payment_option_serialized = get_option($option_payment['_name']);
|
||||||
|
// if (false === $payment_option_serialized) {
|
||||||
|
// add_option($option_payment['_name'], serialize($option_payment['_default']), '', 'no');
|
||||||
|
// $payment_option_serialized = get_option($option_payment['_name']);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return unserialize($payment_option_serialized);
|
||||||
|
//}
|
||||||
|
function get_payment_messages_option_CIPF() {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$option_payment = Cipf::OPTION_PAYMENT;
|
||||||
|
|
||||||
|
return Plgntls::get_option_safe($option_payment);
|
||||||
|
}
|
||||||
|
function get_payment_message_success_CIPF() {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$payment_option = get_payment_messages_option_CIPF();
|
||||||
|
return $payment_option['success'];
|
||||||
|
}
|
||||||
|
function get_payment_message_failure_CIPF() {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$payment_option = get_payment_messages_option_CIPF();
|
||||||
|
return $payment_option['failure'];
|
||||||
|
}
|
||||||
|
function get_payment_message_problem_CIPF() {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$payment_option = get_payment_messages_option_CIPF();
|
||||||
|
return $payment_option['problem'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
100
plugins/cipf_plugin/php/paypal/payment_page.php
Normal file
100
plugins/cipf_plugin/php/paypal/payment_page.php
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
<?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!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* early checks on payment page
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function payment_page_checks_CIPF() {
|
||||||
|
Plgntls::debug_infos(2);
|
||||||
|
$slug_paypal_page = Cipf::SLUG_PAYPAL_PAGE;
|
||||||
|
|
||||||
|
// check the slug
|
||||||
|
if (!is_page($slug_paypal_page)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
|
||||||
|
// get the user id
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
|
||||||
|
// do checks here
|
||||||
|
}
|
||||||
|
add_action('wp', 'payment_page_checks_CIPF');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* only profs can access this page
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function payment_page_redirects_CIPF() {
|
||||||
|
Plgntls::debug_infos(2);
|
||||||
|
$slug_paypal_page = Cipf::SLUG_PAYPAL_PAGE;
|
||||||
|
$role_prof = Cipf::ROLE_PROF;
|
||||||
|
|
||||||
|
// don't redirect if it is the divi builder mode
|
||||||
|
if (et_fb_is_enabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// check the slug
|
||||||
|
if (!is_page($slug_paypal_page)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if prof, don't redirect
|
||||||
|
* for everyone else, redirect
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (current_user_can($role_prof)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
redirect_home_CIPF();
|
||||||
|
|
||||||
|
}
|
||||||
|
add_action('template_redirect', 'payment_page_redirects_CIPF');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* time to upload some scripts and styles on prof profil page
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function payment_page_scripts_CIPF() {
|
||||||
|
Plgntls::debug_infos(2);
|
||||||
|
$slug_paypal_page = Cipf::SLUG_PAYPAL_PAGE;
|
||||||
|
|
||||||
|
// check the slug
|
||||||
|
if (!is_page($slug_paypal_page)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
|
||||||
|
// get the user id
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
|
||||||
|
// enqueue files here
|
||||||
|
display_states_css_CIPF($user_id);
|
||||||
|
}
|
||||||
|
add_action('wp_enqueue_scripts', 'payment_page_scripts_CIPF');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -9,14 +9,15 @@ if (!defined('ABSPATH')) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
include_once(PLGNTLS_class::root_path() . '/php/utils/http_errors.php');
|
include_once(Plgntls::root_path() . '/php/utils/http_errors.php');
|
||||||
include_once(PLGNTLS_class::root_path() . '/php/paypal/route_api_utils.php');
|
include_once(Plgntls::root_path() . '/php/paypal/route_api_utils.php');
|
||||||
include_once(PLGNTLS_class::root_path() . '/php/paypal/user_can_pay.php');
|
include_once(Plgntls::root_path() . '/php/paypal/user_can_pay.php');
|
||||||
include_once(PLGNTLS_class::root_path() . '/php/paypal/update_user_payment.php');
|
include_once(Plgntls::root_path() . '/php/paypal/update_user_payment.php');
|
||||||
include_once(PLGNTLS_class::root_path() . '/php/paypal/shortcode.php');
|
include_once(Plgntls::root_path() . '/php/paypal/shortcode.php');
|
||||||
include_once(PLGNTLS_class::root_path() . '/php/paypal/route_api_orders.php');
|
include_once(Plgntls::root_path() . '/php/paypal/route_api_orders.php');
|
||||||
include_once(PLGNTLS_class::root_path() . '/php/paypal/route_api_orders_capture.php');
|
include_once(Plgntls::root_path() . '/php/paypal/route_api_orders_capture.php');
|
||||||
include_once(PLGNTLS_class::root_path() . '/php/paypal/routes.php');
|
include_once(Plgntls::root_path() . '/php/paypal/routes.php');
|
||||||
|
include_once(Plgntls::root_path() . '/php/paypal/payment_page.php');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ if (!defined('ABSPATH')) {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function handle_orders_request_CIPF($request_data) {
|
function handle_orders_request_CIPF($request_data) {
|
||||||
PLGNTLS_class::debug_infos();
|
Plgntls::debug_infos();
|
||||||
|
|
||||||
// declaring outside the try..catch scope
|
// declaring outside the try..catch scope
|
||||||
$order_response = array();
|
$order_response = array();
|
||||||
@@ -90,14 +90,16 @@ function handle_orders_request_CIPF($request_data) {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function create_order_CIPF() {
|
function create_order_CIPF() {
|
||||||
PLGNTLS_class::debug_infos();
|
Plgntls::debug_infos();
|
||||||
$paypal_api_base_url = PLGNTLS_class::PAYPAL_API_BASE_URL;
|
$paypal_api_base_url = get_paypal_api_base_url_CIPF();
|
||||||
|
$acf_card_price_total = Cipf::ACF_CARD_PRICE_TOTAL;
|
||||||
|
|
||||||
$access_token = generate_access_token_CIPF();
|
$access_token = generate_access_token_CIPF();
|
||||||
|
|
||||||
$user_id = get_current_user_id();
|
$user_id = get_current_user_id();
|
||||||
$acf_id = 'user_' . $user_id;
|
$acf_id = 'user_' . $user_id;
|
||||||
$price = get_field('somme_a_regler', $acf_id);
|
$price = get_field($acf_card_price_total['_name'], $acf_id);
|
||||||
|
// $price = 0.01;
|
||||||
|
|
||||||
$url = $paypal_api_base_url . '/v2/checkout/orders';
|
$url = $paypal_api_base_url . '/v2/checkout/orders';
|
||||||
$payload = array(
|
$payload = array(
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ if (!defined('ABSPATH')) {
|
|||||||
|
|
||||||
|
|
||||||
function handle_orders_capture_request_CIPF($request) {
|
function handle_orders_capture_request_CIPF($request) {
|
||||||
PLGNTLS_class::debug_infos();
|
Plgntls::debug_infos();
|
||||||
$order_id = $request['orderID'];
|
$order_id = $request['orderID'];
|
||||||
// declaring outside the try..catch scope
|
// declaring outside the try..catch scope
|
||||||
$response_json = array();
|
$response_json = array();
|
||||||
@@ -59,11 +59,11 @@ function handle_orders_capture_request_CIPF($request) {
|
|||||||
}
|
}
|
||||||
catch (HttpException $error) {
|
catch (HttpException $error) {
|
||||||
$status_code = $error->getStatusCode();
|
$status_code = $error->getStatusCode();
|
||||||
$message = 'Failed to handle order after capture in server :' . $error->getMessage();
|
$message = array('ERROR_TREATMENT'=>true, 'message'=>'Failed to handle order after capture in server: ' . $error->getMessage());
|
||||||
return new WP_REST_Response($message, $status_code);
|
return new WP_REST_Response($message, $status_code);
|
||||||
}
|
}
|
||||||
catch (Exception $error) {
|
catch (Exception $error) {
|
||||||
$message = 'Failed to handle order after capture in server :' . $error->getMessage();
|
$message = array('ERROR_TREATMENT'=>true, 'message'=>'Failed to handle order after capture in server: ' . $error->getMessage());
|
||||||
return new WP_REST_Response($message, 500);
|
return new WP_REST_Response($message, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,8 +75,8 @@ function handle_orders_capture_request_CIPF($request) {
|
|||||||
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_capture
|
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_capture
|
||||||
*/
|
*/
|
||||||
function capture_order_CIPF($order_id) {
|
function capture_order_CIPF($order_id) {
|
||||||
PLGNTLS_class::debug_infos();
|
Plgntls::debug_infos();
|
||||||
$paypal_api_base_url = PLGNTLS_class::PAYPAL_API_BASE_URL;
|
$paypal_api_base_url = get_paypal_api_base_url_CIPF();
|
||||||
$access_token = generate_access_token_CIPF();
|
$access_token = generate_access_token_CIPF();
|
||||||
$url = $paypal_api_base_url . '/v2/checkout/orders/' . $order_id . '/capture';
|
$url = $paypal_api_base_url . '/v2/checkout/orders/' . $order_id . '/capture';
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ if (!defined('ABSPATH')) {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function handle_json_response_CIPF($response, $ch) {
|
function handle_json_response_CIPF($response, $ch) {
|
||||||
PLGNTLS_class::debug_infos();
|
Plgntls::debug_infos();
|
||||||
if ($response === false)
|
if ($response === false)
|
||||||
throw new HttpException('cURL error: ' . curl_error($ch), 502);
|
throw new HttpException('cURL error: ' . curl_error($ch), 502);
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ function handle_json_response_CIPF($response, $ch) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
function handle_response_CIPF($response) {
|
function handle_response_CIPF($response) {
|
||||||
PLGNTLS_class::debug_infos();
|
Plgntls::debug_infos();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Decode JSON response
|
// Decode JSON response
|
||||||
@@ -60,10 +60,10 @@ function handle_response_CIPF($response) {
|
|||||||
* @see https://developer.paypal.com/api/rest/authentication/
|
* @see https://developer.paypal.com/api/rest/authentication/
|
||||||
*/
|
*/
|
||||||
function generate_access_token_CIPF() {
|
function generate_access_token_CIPF() {
|
||||||
PLGNTLS_class::debug_infos();
|
Plgntls::debug_infos();
|
||||||
$paypal_client_id = PLGNTLS_class::PAYPAL_CLIENT_ID;
|
$paypal_client_id = get_paypal_client_id_CIPF();
|
||||||
$paypal_client_secret = PLGNTLS_class::PAYPAL_CLIENT_SECRET;
|
$paypal_client_secret = get_paypal_client_secret_CIPF();
|
||||||
$paypal_api_base_url = PLGNTLS_class::PAYPAL_API_BASE_URL;
|
$paypal_api_base_url = get_paypal_api_base_url_CIPF();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -12,8 +12,11 @@ if (!defined('ABSPATH')) {
|
|||||||
// handling routes and endpoints
|
// handling routes and endpoints
|
||||||
// diff routes and endpoints : https://stackoverflow.com/q/56075017/9497573
|
// diff routes and endpoints : https://stackoverflow.com/q/56075017/9497573
|
||||||
function routes_endpoints_CIPF() {
|
function routes_endpoints_CIPF() {
|
||||||
PLGNTLS_class::debug_infos();
|
Plgntls::debug_infos();
|
||||||
$base_rest_route = PLGNTLS_class::URL_BASE_REST_ROUTE;
|
if (is_admin()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$base_rest_route = Cipf::URL_BASE_REST_ROUTE;
|
||||||
register_rest_route($base_rest_route, '/orders', array(
|
register_rest_route($base_rest_route, '/orders', array(
|
||||||
'methods' => 'POST',
|
'methods' => 'POST',
|
||||||
'callback' => 'handle_orders_request_CIPF',
|
'callback' => 'handle_orders_request_CIPF',
|
||||||
|
|||||||
@@ -16,16 +16,16 @@ if (!defined('ABSPATH')) {
|
|||||||
* call to paypal_shortcode_content()
|
* call to paypal_shortcode_content()
|
||||||
*/
|
*/
|
||||||
function paypal_shortcode_content_CIPF() {
|
function paypal_shortcode_content_CIPF() {
|
||||||
PLGNTLS_class::debug_infos();
|
Plgntls::debug_infos();
|
||||||
$slug_paypal_redirection_success = PLGNTLS_class::SLUG_PAYPAL_REDIRECTION_SUCCESS;
|
$slug_paypal_redirection_success = Cipf::SLUG_PAYPAL_REDIRECTION_SUCCESS;
|
||||||
$slug_paypal_redirection_failure = PLGNTLS_class::SLUG_PAYPAL_REDIRECTION_FAILURE;
|
$slug_paypal_redirection_failure = Cipf::SLUG_PAYPAL_REDIRECTION_FAILURE;
|
||||||
$paypal_client_id = PLGNTLS_class::PAYPAL_CLIENT_ID;
|
$paypal_client_id = get_paypal_client_id_CIPF();
|
||||||
$paypal_message_success = PLGNTLS_class::PAYPAL_MESSAGE_SUCCESS;
|
$paypal_message_success = get_payment_message_success_CIPF();
|
||||||
$paypal_message_failure = PLGNTLS_class::PAYPAL_MESSAGE_FAILURE;
|
$paypal_message_failure = get_payment_message_failure_CIPF();
|
||||||
|
$paypal_message_problem = get_payment_message_problem_CIPF();
|
||||||
|
|
||||||
// if (!can_pay_now_CIPF())
|
// if (!can_pay_now_CIPF())
|
||||||
// return no_payment_CIPF();
|
// return no_payment_CIPF();
|
||||||
$cipfcard_paypal = new PLGNTLS_class();
|
|
||||||
|
|
||||||
$pp_client_id = $paypal_client_id;
|
$pp_client_id = $paypal_client_id;
|
||||||
$pp_sdk_currency = "EUR";
|
$pp_sdk_currency = "EUR";
|
||||||
@@ -35,7 +35,7 @@ function paypal_shortcode_content_CIPF() {
|
|||||||
$paypal_redirection_success = home_url() . '/' . $slug_paypal_redirection_success;
|
$paypal_redirection_success = home_url() . '/' . $slug_paypal_redirection_success;
|
||||||
$paypal_redirection_failure = home_url() . '/' . $slug_paypal_redirection_failure;
|
$paypal_redirection_failure = home_url() . '/' . $slug_paypal_redirection_failure;
|
||||||
|
|
||||||
$added_to_front = $cipfcard_paypal->add_to_front(
|
$added_to_front = Plgntls::add_to_front(
|
||||||
array(
|
array(
|
||||||
$pp_sdk_url,
|
$pp_sdk_url,
|
||||||
array("js/paypal/paypal.js", 'type'=>'module'),
|
array("js/paypal/paypal.js", 'type'=>'module'),
|
||||||
@@ -46,6 +46,7 @@ function paypal_shortcode_content_CIPF() {
|
|||||||
'paypal_redirection_failure',
|
'paypal_redirection_failure',
|
||||||
'paypal_message_success',
|
'paypal_message_success',
|
||||||
'paypal_message_failure',
|
'paypal_message_failure',
|
||||||
|
'paypal_message_problem',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -55,7 +56,7 @@ add_shortcode('cipf_paypal_shortcode', 'paypal_shortcode_content_CIPF');
|
|||||||
|
|
||||||
|
|
||||||
function no_payment_CIPF() {
|
function no_payment_CIPF() {
|
||||||
PLGNTLS_class::debug_infos();
|
Plgntls::debug_infos();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,9 +35,9 @@ if (!defined('ABSPATH')) {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function update_user_pre_order_CIPF($message) {
|
function update_user_pre_order_CIPF($message) {
|
||||||
PLGNTLS_class::debug_infos();
|
Plgntls::debug_infos();
|
||||||
$acf_payment_status = PLGNTLS_class::ACF_CARD_PAYMENT_STATE;
|
$acf_payment_status = Cipf::ACF_CARD_PAYMENT_STATE;
|
||||||
$meta_order_id = PLGNTLS_class::META_ORDER_ID;
|
$meta_order_id = Cipf::META_ORDER_ID;
|
||||||
|
|
||||||
$order_id = $message->id;
|
$order_id = $message->id;
|
||||||
$user_id = get_current_user_id();
|
$user_id = get_current_user_id();
|
||||||
@@ -60,7 +60,7 @@ function update_user_pre_order_CIPF($message) {
|
|||||||
* - 'nothing' -> output nothing on author page
|
* - 'nothing' -> output nothing on author page
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
update_field($acf_payment_status['_name'], $acf_payment_status['started'], $acf_id);
|
set_payment_started_CIPF($user_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ function update_user_pre_order_CIPF($message) {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function update_user_post_capture_CIPF($message) {
|
function update_user_post_capture_CIPF($message) {
|
||||||
PLGNTLS_class::debug_infos();
|
Plgntls::debug_infos();
|
||||||
|
|
||||||
$order_id = $message->id;
|
$order_id = $message->id;
|
||||||
$user_id = get_current_user_id();
|
$user_id = get_current_user_id();
|
||||||
@@ -101,7 +101,7 @@ function update_user_post_capture_CIPF($message) {
|
|||||||
throw new HttpException('cannot find user with this order_id', 502);
|
throw new HttpException('cannot find user with this order_id', 502);
|
||||||
if ($status === 'COMPLETED') {
|
if ($status === 'COMPLETED') {
|
||||||
// proceed to validate payment for user
|
// proceed to validate payment for user
|
||||||
validate_payment_for_user_CIPF($user_id_to_update, $order_id);
|
success_payment_for_user_CIPF($user_id_to_update, $order_id);
|
||||||
}
|
}
|
||||||
else if ($status === 'PENDING') {
|
else if ($status === 'PENDING') {
|
||||||
// i don't know what to do yet, maybe make more checks and output a message to contact diego ?
|
// i don't know what to do yet, maybe make more checks and output a message to contact diego ?
|
||||||
@@ -127,18 +127,11 @@ function update_user_post_capture_CIPF($message) {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function failure_payment_for_user_CIPF($user_id, $order_id, $status) {
|
function failure_payment_for_user_CIPF($user_id, $order_id, $status) {
|
||||||
PLGNTLS_class::debug_infos();
|
Plgntls::debug_infos();
|
||||||
|
$meta_order_id = Cipf::META_ORDER_ID;
|
||||||
$acf_card_state = PLGNTLS_class::ACF_CARD_STATE;
|
|
||||||
$acf_card_expiration = PLGNTLS_class::ACF_CARD_EXPIRATION;
|
|
||||||
$card_duration = PLGNTLS_class::CARD_VALIDITY_TIME;
|
|
||||||
$prof_is_activ = PLGNTLS_class::ACF_PROF_IS_ACTIV;
|
|
||||||
$acf_payment_status = PLGNTLS_class::ACF_CARD_PAYMENT_STATE;
|
|
||||||
$meta_order_id = PLGNTLS_class::META_ORDER_ID;
|
|
||||||
|
|
||||||
$acf_id = 'user_'.$user_id;
|
$acf_id = 'user_'.$user_id;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* remove the order_id from user meta
|
* remove the order_id from user meta
|
||||||
*
|
*
|
||||||
@@ -146,23 +139,9 @@ function failure_payment_for_user_CIPF($user_id, $order_id, $status) {
|
|||||||
delete_user_meta($user_id, $meta_order_id, $order_id);
|
delete_user_meta($user_id, $meta_order_id, $order_id);
|
||||||
|
|
||||||
|
|
||||||
/*
|
set_payment_failure_CIPF($user_id);
|
||||||
* change payement status to failed
|
set_account_to_pay_CIPF($user_id);
|
||||||
* - 'started' -> at order creation
|
send_emails_CIPF('payment_echec', $user_id);
|
||||||
* - 'success' -> at capture success (on author page, it means success, then mark it 'nothing')
|
|
||||||
* - 'failure' -> at capture failure (on author page, it means failure, then mark it 'nothing')
|
|
||||||
* - 'nothing' -> output nothing on author page
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
update_field($acf_payment_status['_name'], $acf_payment_status['failure'], $acf_id);
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* other changes on user :
|
|
||||||
* - pofil is inactive
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
update_field($prof_is_activ['_name'], $prof_is_activ['inactiv'], $acf_id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -170,149 +149,36 @@ function failure_payment_for_user_CIPF($user_id, $order_id, $status) {
|
|||||||
* things to do when a payment is a success
|
* things to do when a payment is a success
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function validate_payment_for_user_CIPF($user_id, $order_id) {
|
function success_payment_for_user_CIPF($user_id, $order_id) {
|
||||||
PLGNTLS_class::debug_infos();
|
Plgntls::debug_infos();
|
||||||
|
$meta_order_id = Cipf::META_ORDER_ID;
|
||||||
$acf_card_state = PLGNTLS_class::ACF_CARD_STATE;
|
|
||||||
$acf_card_expiration = PLGNTLS_class::ACF_CARD_EXPIRATION;
|
|
||||||
$acf_card_number = PLGNTLS_class::ACF_CARD_NUMBER;
|
|
||||||
$card_duration = PLGNTLS_class::CARD_VALIDITY_TIME;
|
|
||||||
$prof_is_activ = PLGNTLS_class::ACF_PROF_IS_ACTIV;
|
|
||||||
$acf_payment_status = PLGNTLS_class::ACF_CARD_PAYMENT_STATE;
|
|
||||||
$meta_order_id = PLGNTLS_class::META_ORDER_ID;
|
|
||||||
/*
|
|
||||||
$acf_cgv = PLGNTLS_class::ACF_PROF_CGV;
|
|
||||||
$acf_payement = PLGNTLS_class::ACF_CARD_PAYMENT_METHOD;
|
|
||||||
$acf_delivery = PLGNTLS_class::ACF_CARD_PRICE_DELIVERY;
|
|
||||||
$acf_price = PLGNTLS_class::ACF_CARD_PRICE_CHOICE;
|
|
||||||
*/
|
|
||||||
|
|
||||||
$acf_id = 'user_'.$user_id;
|
$acf_id = 'user_'.$user_id;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* remove the order_id from user meta
|
* remove the order_id from user meta
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
delete_user_meta($user_id, $meta_order_id, $order_id);
|
delete_user_meta($user_id, $meta_order_id, $order_id);
|
||||||
|
|
||||||
/*
|
|
||||||
* acf uses 'Y-m-d H:i:s' format : https://www.advancedcustomfields.com/resources/date-time-picker/
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
$acf_date_format = 'Y-m-d H:i:s';
|
|
||||||
$acf_id = 'user_'.$user_id;
|
|
||||||
|
|
||||||
$date_now = date_create('today');
|
update_card_expiration_CIPF($user_id);
|
||||||
|
|
||||||
/*
|
if (is_card_new_CIPF()) {
|
||||||
* get current date limit
|
set_card_number_CIPF($user_id);
|
||||||
* if no date, use now
|
set_card_renew_CIPF($user_id);
|
||||||
* if paste date, use now
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
$current_date_limit_object = get_field_object($acf_card_expiration['_name'], $acf_id);
|
|
||||||
|
|
||||||
if ($current_date_limit_object === false) {
|
|
||||||
$current_date_limit = $date_now;
|
|
||||||
}
|
|
||||||
else if (empty($current_date_limit_object['value'])) {
|
|
||||||
$current_date_limit = $date_now;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$current_date_limit_string = $current_date_limit_object['value'];
|
|
||||||
$current_format_field = $current_date_limit_object['return_format'];
|
|
||||||
// compare 2 dates : https://stackoverflow.com/q/8722806/9497573
|
|
||||||
// also I dont use strtotime to compare 2 ints,
|
|
||||||
// because i don't know if it will fail one day (2000 bug alike)
|
|
||||||
$current_date_limit = date_create_from_format($current_format_field, $current_date_limit_string);
|
|
||||||
$date_diff = date_diff($date_now, $current_date_limit);
|
|
||||||
$date_is_in_past = $date_diff->format('%R%a') < 0;
|
|
||||||
|
|
||||||
if ($date_is_in_past)
|
|
||||||
$current_date_limit = $date_now;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
set_payment_success_CIPF($user_id);
|
||||||
* update date limit validity to add 1 year
|
set_account_valid_CIPF($user_id);
|
||||||
*
|
send_emails_CIPF('payment_success', $user_id);
|
||||||
*/
|
|
||||||
$date_plus_one_year = $current_date_limit->add(date_interval_create_from_date_string('+'.$card_duration));
|
|
||||||
update_field($acf_card_expiration['_name'], $date_plus_one_year->format($acf_date_format), $acf_id);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* - if card status is command, create card id
|
|
||||||
* - make card status to renewal
|
|
||||||
*/
|
|
||||||
$card_status = get_field($acf_card_state['_name'], $acf_id);
|
|
||||||
if ($card_status === $acf_card_state['new']) {
|
|
||||||
$card_id = $date_now->format('Ymd') . $user_id;
|
|
||||||
error_log("-------");
|
|
||||||
error_log("card_id");
|
|
||||||
error_log($card_id);
|
|
||||||
update_field($acf_card_number['_name'], $card_id, $acf_id);
|
|
||||||
}
|
|
||||||
update_field($acf_card_state['_name'], $acf_card_state['renew'], $acf_id);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* change user :
|
|
||||||
* - profile is active
|
|
||||||
* - card state is renewal
|
|
||||||
* - payement status is success
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
update_field($prof_is_activ['_name'], $prof_is_activ['activ'], $acf_id);
|
|
||||||
update_field($acf_payment_status['_name'], $acf_payment_status['success'], $acf_id);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* reset some fields for the form to buy the card
|
|
||||||
* - cgv
|
|
||||||
* - paiement
|
|
||||||
* - livraison
|
|
||||||
* - tarif
|
|
||||||
*
|
|
||||||
* could make sense to put it here,
|
|
||||||
* but actually it needs to be put at begining of form
|
|
||||||
*
|
|
||||||
update_field($acf_cgv['_name'] , array(""), 'user_'.$user_id);
|
|
||||||
update_field($acf_payement['_name'], array(""), 'user_'.$user_id);
|
|
||||||
update_field($acf_delivery['_name'], array(""), 'user_'.$user_id);
|
|
||||||
update_field($acf_price['_name'] , array(""), 'user_'.$user_id);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* add a schedule event to delete this order_id
|
|
||||||
* after 3 days ?
|
|
||||||
* time() + 60 = one minute from now
|
|
||||||
* time() + MINUTE_IN_SECONDS = one minute from now
|
|
||||||
* -> https://codex.wordpress.org/Easier_Expression_of_Time_Constants
|
|
||||||
* -> also strtotime : https://www.php.net/manual/en/function.strtotime.php
|
|
||||||
*
|
|
||||||
function schedule_delete_orderid_CIPF($user_id, $order_id)
|
|
||||||
{
|
|
||||||
$delay = time() + MINUTE_IN_SECONDS;
|
|
||||||
wp_schedule_single_event($delay, 'orderid_deletion_event_CIPF', array($user_id, $order_id));
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* action hook for the scheduled event
|
|
||||||
* TODO: ne marche pas je ne sais pas pourquoi, pas urgent a resoudre
|
|
||||||
*
|
|
||||||
function delete_order_id_later_CIPF($user_id, $order_id)
|
|
||||||
{
|
|
||||||
delete_user_meta($user_id, 'cipf_order_id', $order_id);
|
|
||||||
}
|
|
||||||
add_action('orderid_deletion_event_CIPF', 'delete_order_id_later_CIPF', 5, 2);
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -321,9 +187,9 @@ add_action('orderid_deletion_event_CIPF', 'delete_order_id_later_CIPF', 5, 2);
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function find_user_with_order_id_CIPF($current_user_id, $order_id) {
|
function find_user_with_order_id_CIPF($current_user_id, $order_id) {
|
||||||
PLGNTLS_class::debug_infos();
|
Plgntls::debug_infos();
|
||||||
$meta_order_id = PLGNTLS_class::META_ORDER_ID;
|
$meta_order_id = Cipf::META_ORDER_ID;
|
||||||
$role_prof = PLGNTLS_class::ROLE_PROF;
|
$role_prof = Cipf::ROLE_PROF;
|
||||||
|
|
||||||
$user_metas = get_user_meta($current_user_id, $meta_order_id, false);
|
$user_metas = get_user_meta($current_user_id, $meta_order_id, false);
|
||||||
if (in_array($order_id, $user_metas)) {
|
if (in_array($order_id, $user_metas)) {
|
||||||
@@ -347,33 +213,6 @@ function find_user_with_order_id_CIPF($current_user_id, $order_id) {
|
|||||||
else if (count($users) === 1)
|
else if (count($users) === 1)
|
||||||
return reset($users);
|
return reset($users);
|
||||||
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @return mixed num - user_id
|
|
||||||
* bool false - if no match found
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function delete_order_id_on_success_CIPF($current_user_id, $order_id) {
|
|
||||||
PLGNTLS_class::debug_infos();
|
|
||||||
$meta_order_id = PLGNTLS_class::META_ORDER_ID;
|
|
||||||
|
|
||||||
$del_ret = delete_user_meta($current_user_id, $meta_order_id, $order_id);
|
|
||||||
if ($del_ret === true)
|
|
||||||
return $current_user_id;
|
|
||||||
|
|
||||||
// it means the current user didn't have this order_id
|
|
||||||
// so we look for another user
|
|
||||||
$users = get_users();
|
|
||||||
foreach ($users as $user) {
|
|
||||||
$user_id = $user->ID;
|
|
||||||
$del_ret = delete_user_meta($user_id, $meta_order_id, $order_id);
|
|
||||||
if ($del_ret === true)
|
|
||||||
return $user_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,31 @@ if (!defined('ABSPATH')) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* return value of an acf field, no matter if the field is set up to return label or value
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function get_acf_value_CIPF($acf_field, $acf_id) {
|
||||||
|
$field = get_field_init_CIPF($acf_field['_name'], $acf_id);
|
||||||
|
$field_object = get_field_object($acf_field['_name'], $acf_id);
|
||||||
|
$return_format = $field_object['return_format'];
|
||||||
|
|
||||||
|
$value = null;
|
||||||
|
if ($return_format === 'array') {
|
||||||
|
$value = $field['value'];
|
||||||
|
}
|
||||||
|
else if ($return_format === 'value') {
|
||||||
|
$value = $field;
|
||||||
|
}
|
||||||
|
else if ($return_format === 'label') {
|
||||||
|
$choices = $field_object['choices'];
|
||||||
|
$value = array_search($field, $choices);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* can pay in certain conditions
|
* can pay in certain conditions
|
||||||
@@ -17,13 +42,13 @@ if (!defined('ABSPATH')) {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function check_can_pay_CIPF() {
|
function check_can_pay_CIPF() {
|
||||||
PLGNTLS_class::debug_infos();
|
Plgntls::debug_infos();
|
||||||
$acf_card_payment_method = PLGNTLS_class::ACF_CARD_PAYMENT_METHOD;
|
$acf_card_payment_method = Cipf::ACF_CARD_PAYMENT_METHOD;
|
||||||
$acf_card_price_choice = PLGNTLS_class::ACF_CARD_PRICE_CHOICE;
|
$acf_card_price_choice = Cipf::ACF_CARD_PRICE_CHOICE;
|
||||||
$acf_card_price_delivery = PLGNTLS_class::ACF_CARD_PRICE_DELIVERY;
|
$acf_card_price_delivery = Cipf::ACF_CARD_PRICE_DELIVERY;
|
||||||
$acf_card_price_total = PLGNTLS_class::ACF_CARD_PRICE_TOTAL;
|
$acf_card_price_total = Cipf::ACF_CARD_PRICE_TOTAL;
|
||||||
$acf_card_expiration = PLGNTLS_class::ACF_CARD_EXPIRATION;
|
$acf_card_expiration = Cipf::ACF_CARD_EXPIRATION;
|
||||||
$card_renew_period = PLGNTLS_class::CARD_RENEW_PERIOD;
|
$card_renew_period = Cipf::CARD_RENEW_PERIOD;
|
||||||
|
|
||||||
$current_user = wp_get_current_user();
|
$current_user = wp_get_current_user();
|
||||||
$user_id = get_current_user_id();
|
$user_id = get_current_user_id();
|
||||||
@@ -38,16 +63,24 @@ function check_can_pay_CIPF() {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
* ABANDONNED : bug with formbuilder
|
||||||
* calculate price
|
* calculate price
|
||||||
* update the price even if form builder already did it
|
* update the price even if form builder already did it
|
||||||
* in case it was changed from admin pannel
|
* in case it was changed from admin pannel
|
||||||
*
|
*
|
||||||
*/
|
$tarif = get_acf_value_CIPF($acf_card_price_choice, $acf_id);
|
||||||
$tarif = (int)get_field($acf_card_price_choice['_name'], $acf_id);
|
$livraison = get_acf_value_CIPF($acf_card_price_delivery, $acf_id);
|
||||||
$livraison = (int)get_field($acf_card_price_delivery['_name'], $acf_id);
|
if ($tarif !== null && $livraison !== null) {
|
||||||
$price = $tarif + $livraison;
|
$price = $tarif + $livraison;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$price = 0;
|
||||||
|
}
|
||||||
update_field($acf_card_price_total['_name'], $price, $acf_id);
|
update_field($acf_card_price_total['_name'], $price, $acf_id);
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* price is not empty or 0
|
* price is not empty or 0
|
||||||
|
|||||||
@@ -1,134 +0,0 @@
|
|||||||
<?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_prof_is_activ_CIPF($author_id) {
|
|
||||||
PLGNTLS_class::debug_infos();
|
|
||||||
$acf_prof_is_activ = PLGNTLS_class::ACF_PROF_IS_ACTIV;
|
|
||||||
$slug_wait_activation = PLGNTLS_class::SLUG_PROF_INACTIV;
|
|
||||||
|
|
||||||
$acf_id = 'user_' . $author_id;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* if prof is activ, do nothing more
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
$is_activ = get_field($acf_prof_is_activ['_name'], $acf_id);
|
|
||||||
if ($is_activ === $acf_prof_is_activ['activ'])
|
|
||||||
return;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* else if prof inactiv
|
|
||||||
* if is admin or other allowed roles, see the page anyway
|
|
||||||
* no need to handle allowed roles, it's already
|
|
||||||
* taken care by author_restriction.php
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
$user_id = get_current_user_id();
|
|
||||||
if ($user_id !== $author_id)
|
|
||||||
return;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* if prof is activ
|
|
||||||
* redirect to waiting page
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
$redirection_prof_inactiv = home_url() . '/' . $slug_wait_activation;
|
|
||||||
|
|
||||||
// Set up nocache headers before redirecting : https://developer.wordpress.org/reference/functions/wp_safe_redirect/#user-contributed-notes
|
|
||||||
nocache_headers();
|
|
||||||
wp_redirect($redirection_prof_inactiv, 301);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* check acf field payment_status
|
|
||||||
* if field value is 'success'
|
|
||||||
* - show block 'failure'
|
|
||||||
* - and update field to 'nothing', so it will not show next time
|
|
||||||
* if field value is 'failure'
|
|
||||||
* - show bloc success
|
|
||||||
* - and update field to 'nothing', so it will not show next time
|
|
||||||
* if field value is 'nothing'
|
|
||||||
* - do nothing (keep blocs hidden)
|
|
||||||
* if field value is 'started'
|
|
||||||
* - do nothing (keep blocs hidden)
|
|
||||||
*
|
|
||||||
* .cipf_prof_paiement_message -> on row, added display none in page css
|
|
||||||
* #cipf_prof_paiement_reussi -> on row
|
|
||||||
* #cipf_prof_paiement_echoue -> on row
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function show_prof_paiement_messages_CIPF($user_id) {
|
|
||||||
PLGNTLS_class::debug_infos();
|
|
||||||
$acf_prof_is_activ = PLGNTLS_class::ACF_PROF_IS_ACTIV;
|
|
||||||
$acf_payment_status = PLGNTLS_class::ACF_CARD_PAYMENT_STATE;
|
|
||||||
|
|
||||||
$acf_id = 'user_' . $user_id;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* if prof is inactive, do nothing more
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
$is_activ = get_field($acf_prof_is_activ['_name'], $acf_id);
|
|
||||||
if (is_null($is_activ))
|
|
||||||
return;
|
|
||||||
if (empty($is_activ))
|
|
||||||
return;
|
|
||||||
if ($is_activ === $acf_prof_is_activ['activ'])
|
|
||||||
return;
|
|
||||||
|
|
||||||
$cipf_prof_payement = new PLGNTLS_class();
|
|
||||||
|
|
||||||
$payement_status = get_field($acf_payment_status['_name'], $acf_id);
|
|
||||||
if ($payement_status === $acf_payment_status['success']) {
|
|
||||||
$cipf_prof_payement->add_to_front(array(
|
|
||||||
array( 'css' => '.cipf_prof_paiement_message#cipf_prof_paiement_reussi {display: block;}' )
|
|
||||||
));
|
|
||||||
}
|
|
||||||
else if ($payement_status === $acf_payment_status['failure']) {
|
|
||||||
$cipf_prof_payement->add_to_front(array(
|
|
||||||
array( 'css' => '.cipf_prof_paiement_message#cipf_prof_paiement_echoue {display: block;}' )
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
update_field($acf_payment_status['_name'], $acf_payment_status['nothing'], $acf_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* series of check to do before printing a prof author page
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function check_prof_page_CIPF() {
|
|
||||||
PLGNTLS_class::debug_infos();
|
|
||||||
|
|
||||||
// is an author page
|
|
||||||
if (!is_author())
|
|
||||||
return;
|
|
||||||
|
|
||||||
// the way to find the id of the author of an author_page
|
|
||||||
$author_id = get_queried_object_id();
|
|
||||||
|
|
||||||
handle_prof_is_activ_CIPF($author_id);
|
|
||||||
|
|
||||||
show_prof_paiement_messages_CIPF($author_id);
|
|
||||||
|
|
||||||
}
|
|
||||||
add_action('template_redirect', 'check_prof_page_CIPF', 11);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
||||||
206
plugins/cipf_plugin/php/profs_dates.php
Normal file
206
plugins/cipf_plugin/php/profs_dates.php
Normal file
@@ -0,0 +1,206 @@
|
|||||||
|
<?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!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* returns the date limit as a DateTime object
|
||||||
|
* or false if not set
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function get_date_limit_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$acf_card_expiration = Cipf::ACF_CARD_EXPIRATION;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* define ids
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (is_null($user_id)) {
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
}
|
||||||
|
$acf_id = 'user_'.$user_id;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* get acf date field
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$current_date_limit_object = get_field_object($acf_card_expiration['_name'], $acf_id);
|
||||||
|
if ($current_date_limit_object === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if (empty($current_date_limit_object['value'])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* create date object from acf date
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$current_date_limit_string = $current_date_limit_object['value'];
|
||||||
|
$current_format_field = $current_date_limit_object['return_format'];
|
||||||
|
// compare 2 dates : https://stackoverflow.com/q/8722806/9497573
|
||||||
|
// also I dont use strtotime to compare 2 ints,
|
||||||
|
// because i don't know if it will fail one day (2000y bug style)
|
||||||
|
$current_date_limit = date_create_from_format($current_format_field, $current_date_limit_string);
|
||||||
|
if ($current_date_limit === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* returns the date object
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
return $current_date_limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* returns the diff in days between today and the expiration date of the card
|
||||||
|
* returns false if the expiration date field is empty
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function card_date_diff_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
/*
|
||||||
|
* get date limit as DateTime object
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$current_date_limit = get_date_limit_CIPF($user_id);
|
||||||
|
if ($current_date_limit === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* returns diff in days
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$date_now = date_create('today');
|
||||||
|
$date_diff = date_diff($date_now, $current_date_limit);
|
||||||
|
return (int)$date_diff->format('%R%a');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* returns true if date is in paste or is empty
|
||||||
|
* use is_card_date_exists_CIPF to check if the field is empty
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function is_card_date_expired_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* define user_id
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (is_null($user_id)) {
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check if expired
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$date_diff = card_date_diff_CIPF($user_id);
|
||||||
|
if ($date_diff === false) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if ($date_diff < 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* returns true if date is empty
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function card_date_exists_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$acf_card_expiration = Cipf::ACF_CARD_EXPIRATION;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* define ids
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (is_null($user_id)) {
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
}
|
||||||
|
$acf_id = 'user_'.$user_id;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* get acf date field
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$date_now = date_create('today');
|
||||||
|
$current_date = get_field($acf_card_expiration['_name'], $acf_id);
|
||||||
|
|
||||||
|
if (empty($current_date)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (is_null($current_date)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* will add card_duration to card
|
||||||
|
* card_duration is expected in a string format : https://www.php.net/manual/en/class.dateinterval.php
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function update_card_expiration_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$acf_card_expiration = Cipf::ACF_CARD_EXPIRATION;
|
||||||
|
$card_duration = Cipf::CARD_VALIDITY_TIME;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* define acf id and acf date format
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (is_null($user_id)) {
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
}
|
||||||
|
$acf_id = 'user_'.$user_id;
|
||||||
|
$acf_date_format = 'Y-m-d H:i:s';
|
||||||
|
|
||||||
|
/*
|
||||||
|
* get date limit as DateTime object
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$current_date_limit = get_date_limit_CIPF($user_id);
|
||||||
|
if ($current_date_limit === false) {
|
||||||
|
$current_date_limit = date_create('today');
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* update date limit validity to add 1 year
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$date_plus_one_year = $current_date_limit->add(date_interval_create_from_date_string('+'.$card_duration));
|
||||||
|
update_field($acf_card_expiration['_name'], $date_plus_one_year->format($acf_date_format), $acf_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
127
plugins/cipf_plugin/php/profs_form_commande.php
Normal file
127
plugins/cipf_plugin/php/profs_form_commande.php
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
<?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!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* actions after prof form commande is validated
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function prof_after_form_commande_CIPF($form_id, $post_array, $form_type) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$acf_account_state = Cipf::ACF_ACCOUNT_STATE;
|
||||||
|
$form_prof_commande_id = Cipf::FORM_PROF_COMMANDE_ID;
|
||||||
|
|
||||||
|
if ($form_prof_commande_id !== $form_id) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//$user_id = get_current_user_id();
|
||||||
|
$user_id = $post_array['ID'];
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* reset cgv
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
reset_acf_cgv_CIPF($user_id);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* change status to :
|
||||||
|
* if paypal & new prof : 'to pay'
|
||||||
|
* if paypal & expired card : 'to_pay'
|
||||||
|
* if transfert $ expired card : 'waiting_invalid', reset transfert validation
|
||||||
|
* if transfert $ valid card : 'waiting_valid' , reset transfert validation
|
||||||
|
* if transfert $ neither valid nor expired state : 'waiting_invalid' , reset transfert validation
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (is_payment_method_paypal_CIPF($user_id)) {
|
||||||
|
if (is_account_new_CIPF($user_id)) {
|
||||||
|
set_account_to_pay_CIPF($user_id);
|
||||||
|
}
|
||||||
|
if (is_account_expired_CIPF($user_id)) {
|
||||||
|
set_account_to_pay_CIPF($user_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (is_payment_method_transfert_CIPF($user_id)) {
|
||||||
|
if (is_account_expired_CIPF($user_id)) {
|
||||||
|
set_account_waiting_invalid_CIPF($user_id);
|
||||||
|
}
|
||||||
|
else if (is_account_valid_CIPF($user_id)) {
|
||||||
|
set_account_waiting_valid_CIPF($user_id);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
set_account_waiting_invalid_CIPF($user_id);
|
||||||
|
}
|
||||||
|
reset_acf_transfert_CIPF($user_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_action('df_after_process', 'prof_after_form_commande_CIPF', 10, 3);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* only profs can access this form
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function prof_form_restrictions_CIPF(){
|
||||||
|
Plgntls::debug_infos(2);
|
||||||
|
$slug_command_card = Cipf::SLUG_COMMAND_CARD;
|
||||||
|
$role_prof = Cipf::ROLE_PROF;
|
||||||
|
|
||||||
|
// don't redirect if it is the divi builder mode
|
||||||
|
if (et_fb_is_enabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!is_page($slug_command_card)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if prof, don't redirect
|
||||||
|
* for everyone else, redirect
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (current_user_can($role_prof)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
redirect_home_CIPF();
|
||||||
|
}
|
||||||
|
add_action('template_redirect', 'prof_form_restrictions_CIPF');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* enqueue scripts and styles on page prof
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function renew_page_filter_message_CIPF(){
|
||||||
|
Plgntls::debug_infos(2);
|
||||||
|
$slug_command_card = Cipf::SLUG_COMMAND_CARD;
|
||||||
|
|
||||||
|
if (!is_page($slug_command_card))
|
||||||
|
return;
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
|
||||||
|
display_states_css_CIPF($user_id);
|
||||||
|
}
|
||||||
|
add_action('wp_enqueue_scripts', 'renew_page_filter_message_CIPF');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
88
plugins/cipf_plugin/php/profs_handle_states.php
Normal file
88
plugins/cipf_plugin/php/profs_handle_states.php
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
<?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!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if the acf field for transfert validation is checked,
|
||||||
|
* it means we need to validate the transfert
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function handle_transfert_validation_CIPF($user_id) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check and reset the acf fielf for transfert
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (false === is_transfert_success_CIPF($user_id)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
reset_acf_transfert_CIPF($user_id);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if the account is not in transfert state, nothing to do
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (false === is_account_waiting_transfert_CIPF($user_id)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* set account valid
|
||||||
|
* create card number
|
||||||
|
* add one year
|
||||||
|
* change state 'commande'->'renouvellement'
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
set_account_valid_CIPF($user_id);
|
||||||
|
update_card_expiration_CIPF($user_id);
|
||||||
|
set_card_number_CIPF($user_id);
|
||||||
|
set_card_renew_CIPF($user_id);
|
||||||
|
send_emails_CIPF('transfert_success', $user_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if card expire, makes some changes
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function handle_card_expire_CIPF($user_id) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
if (false === card_date_exists_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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (is_account_waiting_transfert_CIPF($user_id)) {
|
||||||
|
set_account_waiting_valid_CIPF($user_id);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
set_account_valid_CIPF($user_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
154
plugins/cipf_plugin/php/profs_profil.php
Normal file
154
plugins/cipf_plugin/php/profs_profil.php
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
<?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!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* actions after prof form transfert validation is processed
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function prof_after_form_transfert_validation_CIPF($form_id, $post_array, $form_type) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$acf_account_state = Cipf::ACF_ACCOUNT_STATE;
|
||||||
|
$form_prof_transfert_id = Cipf::FORM_PROF_TRANSFERT_ID;
|
||||||
|
|
||||||
|
if ($form_prof_transfert_id !== $form_id) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//$user_id = get_current_user_id();
|
||||||
|
$user_id = $post_array['ID'];
|
||||||
|
|
||||||
|
// the check is not really connected to the form, it check the acf value, whatever the form value is, the form validation is just a trigger for this check
|
||||||
|
handle_transfert_validation_CIPF($user_id);
|
||||||
|
}
|
||||||
|
add_action('df_after_process', 'prof_after_form_transfert_validation_CIPF', 10, 3);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* early checks on profil page
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function prof_profil_check_CIPF() {
|
||||||
|
Plgntls::debug_infos(2);
|
||||||
|
|
||||||
|
// is an author page
|
||||||
|
if (!is_author())
|
||||||
|
return;
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
|
||||||
|
// the way to find the id of the author of an author_page
|
||||||
|
$author_id = get_queried_object_id();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* in case event didn't fire, handle card changes
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
handle_transfert_validation_CIPF($author_id);
|
||||||
|
handle_card_expire_CIPF($author_id);
|
||||||
|
}
|
||||||
|
add_action('wp', 'prof_profil_check_CIPF', 11);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if profil needs redirection, it happens here
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function prof_profil_redirects_CIPF() {
|
||||||
|
Plgntls::debug_infos(2);
|
||||||
|
$role_fipf = Cipf::ROLE_FIPF;
|
||||||
|
$role_admin = Cipf::ROLE_ADMIN;
|
||||||
|
$role_partner = Cipf::ROLE_PARTNER;
|
||||||
|
|
||||||
|
// is an author page
|
||||||
|
if (!is_author())
|
||||||
|
return;
|
||||||
|
// don't redirect if it is the divi builder mode
|
||||||
|
if (et_fb_is_enabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check multiple user roles
|
||||||
|
* https://developer.wordpress.org/reference/functions/current_user_can/#div-comment-4083
|
||||||
|
* if user->role is found in array of allowed role, no redirection needed
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$current_user = wp_get_current_user();
|
||||||
|
$allowed_roles = array($role_admin, $role_fipf);
|
||||||
|
if (array_intersect($allowed_roles, $current_user->roles))
|
||||||
|
return;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if partner, redirect
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (current_user_can($role_partner)) {
|
||||||
|
redirect_home_CIPF();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if connected user is not author, get out
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
// the way to find the id of the author of an author_page
|
||||||
|
$author_id = get_queried_object_id();
|
||||||
|
$current_user_id = get_current_user_id();
|
||||||
|
if ($current_user_id != $author_id) {
|
||||||
|
redirect_home_CIPF();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if connected prof is new, redirect to form commande
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (is_account_new_CIPF()) {
|
||||||
|
redirect_command_CIPF();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_action('template_redirect', 'prof_profil_redirects_CIPF', 11);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* time to upload some scripts and styles on prof profil page
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function prof_profil_scripts_CIPF() {
|
||||||
|
Plgntls::debug_infos(2);
|
||||||
|
|
||||||
|
// is an author page
|
||||||
|
if (!is_author())
|
||||||
|
return;
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
|
||||||
|
// the way to find the id of the author of an author_page
|
||||||
|
$author_id = get_queried_object_id();
|
||||||
|
|
||||||
|
display_states_css_CIPF($author_id);
|
||||||
|
}
|
||||||
|
add_action('wp_enqueue_scripts', 'prof_profil_scripts_CIPF', 11);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
40
plugins/cipf_plugin/php/random_posts.php
Normal file
40
plugins/cipf_plugin/php/random_posts.php
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<?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!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* randomize post output
|
||||||
|
* posts are to randomize if the query ask for a negative number of posts
|
||||||
|
* -1 is already used by worpdress to means ALL posts
|
||||||
|
* -> so this randomization will not work for 1 post
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function randomize_post_output_CIPF($query) {
|
||||||
|
Plgntls::debug_infos(2);
|
||||||
|
$posts_per_page = $query->get('posts_per_page');
|
||||||
|
if (is_null($posts_per_page)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ($posts_per_page >= -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
|
||||||
|
$query->set('orderby', 'rand');
|
||||||
|
}
|
||||||
|
add_action('pre_get_posts', 'randomize_post_output_CIPF');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -9,53 +9,18 @@ if (!defined('ABSPATH')) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* redirect users to profil
|
|
||||||
* if prof -> author page
|
|
||||||
* if partenaire -> post page || home page
|
|
||||||
*/
|
|
||||||
function redirection_profil_page_CIPF(){
|
|
||||||
PLGNTLS_class::debug_infos();
|
|
||||||
$role_prof = PLGNTLS_class::ROLE_PROF;
|
|
||||||
$role_partner = PLGNTLS_class::ROLE_PARTNER;
|
|
||||||
|
|
||||||
$base_url = home_url();
|
/*
|
||||||
$current_user_id = get_current_user_id();
|
* redirects to home
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function redirect_home_CIPF(){
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
|
||||||
// Set up nocache headers before redirecting : https://developer.wordpress.org/reference/functions/wp_safe_redirect/#user-contributed-notes
|
// Set up nocache headers before redirecting : https://developer.wordpress.org/reference/functions/wp_safe_redirect/#user-contributed-notes
|
||||||
nocache_headers();
|
nocache_headers();
|
||||||
|
|
||||||
if (!is_user_logged_in()) {
|
wp_redirect(home_url(), 301);
|
||||||
wp_redirect($base_url, 301);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (current_user_can($role_prof)) {
|
|
||||||
$user_page = get_author_posts_url($current_user_id);
|
|
||||||
wp_redirect($user_page, 301);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
else if (current_user_can($role_partner)) {
|
|
||||||
$args = array(
|
|
||||||
'post_type' => 'post',
|
|
||||||
'author' => $current_user_id,
|
|
||||||
'posts_per_page' => 1,
|
|
||||||
);
|
|
||||||
$posts = get_posts($args);
|
|
||||||
if (empty($posts))
|
|
||||||
$redirect_url = $base_url;
|
|
||||||
else {
|
|
||||||
$query = reset($posts);
|
|
||||||
$post_id = $query->ID;
|
|
||||||
$redirect_url = get_permalink($query->ID);
|
|
||||||
}
|
|
||||||
wp_redirect($redirect_url, 301);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
wp_redirect($base_url, 301);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,17 +28,119 @@ function redirection_profil_page_CIPF(){
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* redirects when someone reaches the page with slug defined in SLUG_PAGE_REDIRECTION
|
* redirects new prof to commande
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function redirect_command_CIPF(){
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$slug_command_card = Cipf::SLUG_COMMAND_CARD;
|
||||||
|
|
||||||
|
// Set up nocache headers before redirecting : https://developer.wordpress.org/reference/functions/wp_safe_redirect/#user-contributed-notes
|
||||||
|
nocache_headers();
|
||||||
|
|
||||||
|
wp_redirect(home_url($slug_command_card), 301);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* redirect users to profil
|
||||||
|
* if prof -> author page
|
||||||
|
* if partenaire -> post page || home page
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function redirection_profil_CIPF(){
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$role_prof = Cipf::ROLE_PROF;
|
||||||
|
$role_partner = Cipf::ROLE_PARTNER;
|
||||||
|
$slug_partner_create_page = Cipf::SLUG_PARTNER_CREATE_PAGE;
|
||||||
|
|
||||||
|
$partner_page_creation = home_url($slug_partner_create_page);
|
||||||
|
$current_user_id = get_current_user_id();
|
||||||
|
|
||||||
|
// Set up nocache headers before redirecting : https://developer.wordpress.org/reference/functions/wp_safe_redirect/#user-contributed-notes
|
||||||
|
nocache_headers();
|
||||||
|
|
||||||
|
if (!is_user_logged_in()) {
|
||||||
|
redirect_home_CIPF();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if prof
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (current_user_can($role_prof)) {
|
||||||
|
$user_page = get_author_posts_url($current_user_id);
|
||||||
|
wp_redirect($user_page, 301);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if partner
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (current_user_can($role_partner)) {
|
||||||
|
$args = array(
|
||||||
|
'post_type' => 'post',
|
||||||
|
'author' => $current_user_id,
|
||||||
|
'posts_per_page' => 1,
|
||||||
|
);
|
||||||
|
$posts = get_posts($args);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if post exists, redirects to it
|
||||||
|
* otherwise redirects to post creation
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (empty($posts)) {
|
||||||
|
$redirect_url = $partner_page_creation;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$query = reset($posts);
|
||||||
|
$redirect_url = get_permalink($query->ID);
|
||||||
|
}
|
||||||
|
wp_redirect($redirect_url, 301);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
redirect_home_CIPF();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* redirects when trying to access the page with SLUG_PAGE_REDIRECTION
|
||||||
|
* no matter if it exists or not
|
||||||
|
*
|
||||||
|
* get current page url : https://wordpress.stackexchange.com/q/274569/226939
|
||||||
|
* -> global $wp; add_query_arg( $wp->query_vars, home_url( $wp->request ) );
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function redirection_page_CIPF(){
|
function redirection_page_CIPF(){
|
||||||
PLGNTLS_class::debug_infos();
|
Plgntls::debug_infos(2);
|
||||||
$slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION;
|
$slug_page_redirection = Cipf::SLUG_PAGE_REDIRECTION;
|
||||||
|
|
||||||
if (!is_page($slug_page_redirection))
|
|
||||||
|
/*
|
||||||
|
* why is_page($slug_page_redirection); didn't work ?
|
||||||
|
* or maybe it did ? it seemed to fail,
|
||||||
|
* maybe because the page does not actually exist
|
||||||
|
* anyway $wp->request works
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
global $wp;
|
||||||
|
$current_slug = $wp->request;
|
||||||
|
if ($current_slug !== $slug_page_redirection) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
|
||||||
redirection_profil_page_CIPF();
|
redirection_profil_CIPF();
|
||||||
}
|
}
|
||||||
add_action('template_redirect', 'redirection_page_CIPF');
|
add_action('template_redirect', 'redirection_page_CIPF');
|
||||||
|
|
||||||
@@ -81,46 +148,6 @@ add_action('template_redirect', 'redirection_page_CIPF');
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* redirects when someone reaches the page with query ?QUERY_REDIRECTION_PROFIL
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function redirection_query_CIPF() {
|
|
||||||
PLGNTLS_class::debug_infos();
|
|
||||||
$query_redirection = PLGNTLS_class::QUERY_REDIRECTION_PROFIL;
|
|
||||||
|
|
||||||
// Check if the request contains ?QUERY_REDIRECTION_PROFIL
|
|
||||||
if(isset($_GET[$query_redirection])) {
|
|
||||||
redirection_profil_page_CIPF();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
add_action('init', 'redirection_query_CIPF');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* DOES NOT WORK so far
|
|
||||||
* because to use is_user_logged_in() in redirection_profil_page_CIPF
|
|
||||||
* the request should include the X-WP-Nonce header, but it does not
|
|
||||||
* redirects when someone enter the url or redirection
|
|
||||||
* /wp-json/cipf_plugin/api/v1/redirection_cipf
|
|
||||||
*
|
|
||||||
function endpoint_for_redirection_CIPF() {
|
|
||||||
PLGNTLS_class::debug_infos();
|
|
||||||
$slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION;
|
|
||||||
$base_rest_route = PLGNTLS_class::URL_BASE_REST_ROUTE;
|
|
||||||
|
|
||||||
register_rest_route($base_rest_route, '/' . $slug_page_redirection, array(
|
|
||||||
'methods' => 'GET',
|
|
||||||
'callback' => 'redirection_profil_page_CIPF',
|
|
||||||
));
|
|
||||||
};
|
|
||||||
add_action('rest_api_init', 'endpoint_for_redirection_CIPF');
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,98 +0,0 @@
|
|||||||
<?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!');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* at registration, add role 'partenaire' when page url has path 'creation-du-compte-partenaire'
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function add_partenaires_CIPF($customer_data){
|
|
||||||
PLGNTLS_class::debug_infos();
|
|
||||||
$role_partner = PLGNTLS_class::ROLE_PARTNER;
|
|
||||||
error_log("----");
|
|
||||||
error_log("in add_partenaires");
|
|
||||||
error_log("_POST");
|
|
||||||
error_log(json_encode($_POST));
|
|
||||||
error_log("_SERVER");
|
|
||||||
error_log(json_encode($_SERVER));
|
|
||||||
|
|
||||||
$current_url = $_SERVER['HTTP_REFERER']; // not reliable to use referer, TODO: find another solution
|
|
||||||
$path_brut = parse_url($current_url, PHP_URL_PATH);
|
|
||||||
$path = trim($path_brut, '/');
|
|
||||||
if ($path === 'creation-du-compte-partenaire')
|
|
||||||
$customer_data['role'] = $role_partner;
|
|
||||||
return $customer_data;
|
|
||||||
}
|
|
||||||
add_filter( 'xoo_el_register_new_customer_data', 'add_partenaires_CIPF', 10, 1 );
|
|
||||||
/*
|
|
||||||
|
|
||||||
in add_partenaires
|
|
||||||
_POST
|
|
||||||
{
|
|
||||||
"xoo_el_reg_username":"tistilarde",
|
|
||||||
"xoo_el_reg_email":"tistilarde@gufum.com",
|
|
||||||
"xoo_el_reg_pass":"pouetpouet",
|
|
||||||
"_xoo_el_form":"register",
|
|
||||||
"xoo_el_redirect":"\/creation-du-compte-partenaire\/",
|
|
||||||
"action":"xoo_el_form_action",
|
|
||||||
"display":"popup"
|
|
||||||
}
|
|
||||||
|
|
||||||
_SERVER
|
|
||||||
{
|
|
||||||
"SERVER_SOFTWARE":"nginx\/1.20.2",
|
|
||||||
"REQUEST_URI":"\/wp-admin\/admin-ajax.php",
|
|
||||||
"USER":"www-data",
|
|
||||||
"HOME":"\/home\/www-data",
|
|
||||||
"HTTP_SEC_FETCH_SITE":"same-origin",
|
|
||||||
"HTTP_SEC_FETCH_MODE":"cors",
|
|
||||||
"HTTP_SEC_FETCH_DEST":"empty",
|
|
||||||
"HTTP_COOKIE":"wordpress_test_cookie=WP%20Cookie%20check; wp-postpass_351da2be51e3820c1ef099eec9d2e669=%24P%24BjEiJgHo.cgrpONdnfmxwpIYzraFCP.; mjx.menu=renderer%3ANativeMML%26%3Bsemantics%3Atrue%26%3Bcontext%3ABrowser%26%3Bzoom%3ANone",
|
|
||||||
"HTTP_REFERER":"https:\/\/local-cipf-plugin.com\/creation-du-compte-partenaire\/",
|
|
||||||
"HTTP_CONNECTION":"keep-alive",
|
|
||||||
"HTTP_SEC_GPC":"1",
|
|
||||||
"HTTP_DNT":"1",
|
|
||||||
"HTTP_ORIGIN":"https:\/\/local-cipf-plugin.com",
|
|
||||||
"HTTP_CONTENT_LENGTH":"211",
|
|
||||||
"HTTP_X_REQUESTED_WITH":"XMLHttpRequest",
|
|
||||||
"HTTP_CONTENT_TYPE":"application\/x-www-form-urlencoded; charset=UTF-8",
|
|
||||||
"HTTP_ACCEPT_ENCODING":"gzip, deflate, br",
|
|
||||||
"HTTP_ACCEPT_LANGUAGE":"en-US,en;q=0.5",
|
|
||||||
"HTTP_ACCEPT":"*\/*",
|
|
||||||
"HTTP_USER_AGENT":"Mozilla\/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko\/20100101 Firefox\/123.0",
|
|
||||||
"HTTP_HOST":"local-cipf-plugin.com",
|
|
||||||
"REDIRECT_STATUS":"200",
|
|
||||||
"SERVER_NAME":"local-cipf-plugin.com",
|
|
||||||
"SERVER_PORT":"443",
|
|
||||||
"SERVER_ADDR":"172.20.0.4",
|
|
||||||
"REMOTE_PORT":"58976",
|
|
||||||
"REMOTE_ADDR":"172.20.0.1",
|
|
||||||
"GATEWAY_INTERFACE":"CGI\/1.1",
|
|
||||||
"HTTPS":"on",
|
|
||||||
"REQUEST_SCHEME":"https",
|
|
||||||
"SERVER_PROTOCOL":"HTTP\/1.1",
|
|
||||||
"DOCUMENT_ROOT":"\/var\/www\/html",
|
|
||||||
"DOCUMENT_URI":"\/wp-admin\/admin-ajax.php",
|
|
||||||
"SCRIPT_NAME":"\/wp-admin\/admin-ajax.php",
|
|
||||||
"CONTENT_LENGTH":"211",
|
|
||||||
"CONTENT_TYPE":"application\/x-www-form-urlencoded; charset=UTF-8",
|
|
||||||
"REQUEST_METHOD":"POST",
|
|
||||||
"QUERY_STRING":"",
|
|
||||||
"SCRIPT_FILENAME":"\/var\/www\/html\/wp-admin\/admin-ajax.php",
|
|
||||||
"FCGI_ROLE":"RESPONDER",
|
|
||||||
"PHP_SELF":"\/wp-admin\/admin-ajax.php",
|
|
||||||
"REQUEST_TIME_FLOAT":1710328883.257681,
|
|
||||||
"REQUEST_TIME":1710328883
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
||||||
@@ -1,125 +0,0 @@
|
|||||||
<?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!');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* on renew page :
|
|
||||||
* - check restrictions
|
|
||||||
* - change some acf fields (if access granted)
|
|
||||||
*
|
|
||||||
* prevent users to fill the renew form if :
|
|
||||||
* - they are not prof and logged in,
|
|
||||||
* - and if their card is not in renewable state
|
|
||||||
* - except admins and editor
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function renew_page_restrictions_CIPF(){
|
|
||||||
PLGNTLS_class::debug_infos();
|
|
||||||
$slug_renew_card = PLGNTLS_class::SLUG_RENEW_CARD;
|
|
||||||
$slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION;
|
|
||||||
$role_prof = PLGNTLS_class::ROLE_PROF;
|
|
||||||
$role_fipf = PLGNTLS_class::ROLE_FIPF;
|
|
||||||
$role_admin = PLGNTLS_class::ROLE_ADMIN;
|
|
||||||
|
|
||||||
$base_url = home_url();
|
|
||||||
|
|
||||||
wp_reset_query();
|
|
||||||
|
|
||||||
if (!is_page('commande'))
|
|
||||||
return;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* is it good ?
|
|
||||||
* -> dont' redirect if user not logged in, because new users need to acces this page
|
|
||||||
*
|
|
||||||
if (!is_user_logged_in()) {
|
|
||||||
// Set up nocache headers before redirecting : https://developer.wordpress.org/reference/functions/wp_safe_redirect/#user-contributed-notes
|
|
||||||
nocache_headers();
|
|
||||||
wp_redirect($base_url, 301);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
$current_user_id = get_current_user_id();
|
|
||||||
$current_user = wp_get_current_user();
|
|
||||||
$acf_id = 'user_'.$current_user_id;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* check multiple user roles
|
|
||||||
* https://developer.wordpress.org/reference/functions/current_user_can/#div-comment-4083
|
|
||||||
*
|
|
||||||
$allowed_roles = array($role_admin, $role_fipf, $role_prof);
|
|
||||||
if (!array_intersect($allowed_roles, $current_user->roles))
|
|
||||||
return;
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* if prof, check card state
|
|
||||||
* if cannot renew, redirect
|
|
||||||
*
|
|
||||||
if (current_user_can($role_prof)) {
|
|
||||||
$can_renew = get_field($acf_prof_can_renew['_name'], $acf_id);
|
|
||||||
if ($can_renew === false) {
|
|
||||||
// Set up nocache headers before redirecting : https://developer.wordpress.org/reference/functions/wp_safe_redirect/#user-contributed-notes
|
|
||||||
nocache_headers();
|
|
||||||
$redirect_url = home_url() . '/' . $slug_page_redirection;
|
|
||||||
wp_redirect($redirect_url, 301);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
add_action('template_redirect', 'renew_page_restrictions_CIPF');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* on the renew card page for prof
|
|
||||||
* output the right message, depending of the status of the card
|
|
||||||
* 'renouveler' or 'commander'
|
|
||||||
*
|
|
||||||
* #cipf_prof_carte_commande -> default display: block;
|
|
||||||
* #cipf_prof_carte_renouvellement -> default display: none;
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function renew_page_filter_message_CIPF(){
|
|
||||||
PLGNTLS_class::debug_infos();
|
|
||||||
$slug_renew_card = PLGNTLS_class::SLUG_RENEW_CARD;
|
|
||||||
$acf_card_state = PLGNTLS_class::ACF_CARD_STATE;
|
|
||||||
|
|
||||||
if (!is_page($slug_renew_card))
|
|
||||||
return;
|
|
||||||
|
|
||||||
$user_id = get_current_user_id();
|
|
||||||
$acf_id = 'user_'.$user_id;
|
|
||||||
|
|
||||||
$cipf_renew = new PLGNTLS_class();
|
|
||||||
|
|
||||||
$card_state = get_field($acf_card_state['_name'], $acf_id);
|
|
||||||
|
|
||||||
if ($card_state === 'Renouvellement') {
|
|
||||||
$cipf_renew->add_to_front(array(
|
|
||||||
array( 'css' => 'div#cipf_prof_carte_renouvellement {display: block;}' ),
|
|
||||||
array( 'css' => 'div#cipf_prof_carte_commande {display: none;}' ),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
add_action('wp_enqueue_scripts', 'renew_page_filter_message_CIPF');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
<?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!');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
* NOT USEFUL ANYMORE :
|
|
||||||
* it was to fix pbms in formbuilder with calculation field
|
|
||||||
* but I made 2 better fixes (css and js)
|
|
||||||
*
|
|
||||||
* reset some fields for the form to buy the card
|
|
||||||
* - cgv
|
|
||||||
* - paiement
|
|
||||||
* - livraison
|
|
||||||
* - tarif
|
|
||||||
* this action is called after redirection hook
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function reset_some_fields_CIPF() {
|
|
||||||
PLGNTLS_class::debug_infos();
|
|
||||||
$slug_renew_card = PLGNTLS_class::SLUG_RENEW_CARD;
|
|
||||||
$acf_cgv = PLGNTLS_class::ACF_PROF_CGV;
|
|
||||||
$acf_payement = PLGNTLS_class::ACF_CARD_PAYMENT_METHOD;
|
|
||||||
$acf_delivery = PLGNTLS_class::ACF_CARD_PRICE_DELIVERY;
|
|
||||||
$acf_price = PLGNTLS_class::ACF_CARD_PRICE_CHOICE;
|
|
||||||
|
|
||||||
if (!is_page($slug_renew_card))
|
|
||||||
return;
|
|
||||||
|
|
||||||
$user_id = get_current_user_id();
|
|
||||||
update_field($acf_cgv['_name'] , array(""), 'user_'.$user_id);
|
|
||||||
update_field($acf_payement['_name'], array(""), 'user_'.$user_id);
|
|
||||||
update_field($acf_delivery['_name'], array(""), 'user_'.$user_id);
|
|
||||||
update_field($acf_price['_name'] , array(""), 'user_'.$user_id);
|
|
||||||
}
|
|
||||||
add_action('wp', 'reset_some_fields_CIPF');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
||||||
95
plugins/cipf_plugin/php/scheduled_events.php
Normal file
95
plugins/cipf_plugin/php/scheduled_events.php
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
<?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!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* schedule events :
|
||||||
|
* - first use a function to add the event :
|
||||||
|
* - function launch_schedule_my_evet() {
|
||||||
|
* wp_schedule_single_event($delay, 'hook_event_name');
|
||||||
|
* }
|
||||||
|
* - this will enqueue an action hook when the time will come, that you must define :
|
||||||
|
* - add_action('hook_event_name', 'callback_function');
|
||||||
|
* - and finally, define the function 'callback_function()'
|
||||||
|
*
|
||||||
|
* to define the delay, you can use the strtotime notation
|
||||||
|
* - strtotime('+1 month');
|
||||||
|
* -> https://www.php.net/manual/en/function.strtotime.php
|
||||||
|
* or the time constants in seconds :
|
||||||
|
* - time() + 3 * MINUTE_IN_SECONDS
|
||||||
|
* -> https://codex.wordpress.org/Easier_Expression_of_Time_Constants
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* events and emails :
|
||||||
|
*
|
||||||
|
* - payments : action : : suppress old order_ids
|
||||||
|
* - profs : : email : validation payment prof, send email
|
||||||
|
* - profs : : email : validation transfert prof, send email
|
||||||
|
* - partners : action : : offres temporaires -> gerer qu'elles disparaissent apres la date de validite -> la passer en masquer
|
||||||
|
* - partners : action : : la gestion des offres à échéance
|
||||||
|
* - payments : action : email : schedule event pour supprimer le compte xx temps (6 mois ?) apres fin de validite de la carte
|
||||||
|
* - payments : action : email : schedule event pour supprimer les codes
|
||||||
|
* - payments : action : email : schedule event pour desactiver la carte
|
||||||
|
* - payments : action : email : faire rappels emails
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* add a schedule event to delete this order_id
|
||||||
|
* after 3 days ?
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function schedule_delete_orderid_CIPF($user_id, $order_id) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$delay = strtotime('+3 days');
|
||||||
|
wp_schedule_single_event($delay, 'orderid_deletion_event_CIPF', array($user_id, $order_id));
|
||||||
|
}
|
||||||
|
function delete_order_id_later_CIPF($user_id, $order_id) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
delete_user_meta($user_id, 'cipf_order_id', $order_id);
|
||||||
|
}
|
||||||
|
add_action('orderid_deletion_event_CIPF', 'delete_order_id_later_CIPF', 10, 2);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
498
plugins/cipf_plugin/php/states.php
Normal file
498
plugins/cipf_plugin/php/states.php
Normal file
@@ -0,0 +1,498 @@
|
|||||||
|
<?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!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* [/] etat compte ('etat_compte') :
|
||||||
|
* 1. new . 'nouveau prof' -> ok 1/1 : [1: at inscription - ok]
|
||||||
|
* 2. to_pay . 'doit payer' -> ko 3/4 : [1: after form & new - ok], [2: after form choose paypal & expired - ok], [3: after payment failed - ok], [4: after transfert failed - ko]
|
||||||
|
* 3. valid . 'carte valide' -> ko 1/2 : [1: after payment success - ok], [2: after transfert success - ko]
|
||||||
|
* 4. waiting_invalid . 'en attente invalide' -> ko 3/4 : [1: after form choose transfert & expired - ok], [2: after card changes to expired & was waiting valid - ok], [3: verify at prof profil page - ok], [4: when event for expire fire - ko]
|
||||||
|
* 5. waiting_valid . 'en attente valide' -> ok 1/1 : [1: after form choose transfert & not expired - ok]
|
||||||
|
* 6. expired . 'carte expiree' -> ko 1/2 : [1: when prof access profil & expired - ok], [2: when event card expired fire - ko]
|
||||||
|
*
|
||||||
|
* [/] etat carte ('etat_carte') :
|
||||||
|
* - 'Commande' -> ok 1/1 : [1: at inscription - ok]
|
||||||
|
* - 'Renouvellement' -> ko 1/1 : [1: after succees payement - ok]
|
||||||
|
*
|
||||||
|
* [/] etat paiement ('etat_paiement') :
|
||||||
|
* - 'en_cours' -> ok 1/1 : [1: start payment - ok]
|
||||||
|
* - 'reussi' -> ok 1/1 : [1: after payment success - ok]
|
||||||
|
* - 'echec' -> ok 1/1 : [1: after payment failure - ok]
|
||||||
|
* - 'aucun' -> ok 2/2 : [1: default - ko], [2: after payment message is shown one time on profil page - ok]
|
||||||
|
*
|
||||||
|
* [/] type paiement ('paiement') :
|
||||||
|
* - 'Paypal' -> ok 1/1 : [1: modified by diviformbuilder at form validation - ok]
|
||||||
|
* - 'Virement' -> ok 1/1 : [1: modified by diviformbuilder at form validation - ok]
|
||||||
|
*
|
||||||
|
* [/] etat partenaire ('etat_page_partenaire') :
|
||||||
|
* - 'publie'
|
||||||
|
* - 'brouillon'
|
||||||
|
*
|
||||||
|
* [/] numero de carte ('numero_de_la_carte') -> ok 1/1 : [1: after payment & card is 'commande' - ok]
|
||||||
|
*
|
||||||
|
* [/] etat_virement -> ko 2/3 : [1: at form validation - ok], [2: check on profil page - ko], [3: when transfert is started, reset - ok]]
|
||||||
|
*
|
||||||
|
* [/] cgv
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function get_field_init_CIPF($acf_field_name, $acf_id) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$acf_state = get_field($acf_field_name, $acf_id);
|
||||||
|
if ($acf_state !== null) {
|
||||||
|
return $acf_state;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if get_field returns null, it means it is not initialized
|
||||||
|
* - initialize it with 'temp' value
|
||||||
|
* - then find it's default value, and update with it
|
||||||
|
* - if no default value, update with first value
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
update_field($acf_field_name, 'temp', $acf_id);
|
||||||
|
$acf_object = get_field_object($acf_field_name, $acf_id);
|
||||||
|
$default = $acf_object['default_value'];
|
||||||
|
if (empty($default)) {
|
||||||
|
$choices = $acf_object['choices'];
|
||||||
|
if (!is_array($choices)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$default = reset($choices);
|
||||||
|
}
|
||||||
|
update_field($acf_field_name, $default, $acf_id);
|
||||||
|
$acf_state = get_field($acf_field_name, $acf_id);
|
||||||
|
|
||||||
|
return $acf_state;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* global 'setter' and 'izzer' for this file
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function is_acf_state_CIPF($acf_field, $state_name, $acf_id) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* when acf fields have not been initated a first time, you can't find them by name
|
||||||
|
* - one solution is to use key instead
|
||||||
|
* but it means knowing the key, in my case it prevents fabien to create a field himself
|
||||||
|
* - another solution would be to :
|
||||||
|
* try if is null,
|
||||||
|
* if yes it means it was not initalize,
|
||||||
|
* then initalize with any value,
|
||||||
|
* find the default value,
|
||||||
|
* and assign it
|
||||||
|
*
|
||||||
|
$acf_state = get_field($acf_field['_key'], $acf_id);
|
||||||
|
*/
|
||||||
|
$acf_state = get_field_init_CIPF($acf_field['_name'], $acf_id);;
|
||||||
|
|
||||||
|
if ($acf_state === $acf_field[$state_name]) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
function set_acf_state_CIPF($acf_field, $state_name, $acf_id) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
update_field($acf_field['_name'], $acf_field[$state_name], $acf_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* etat compte ('etat_compte') :
|
||||||
|
* 1. new . 'nouveau prof' -> ok : [1: a l'inscription - ok]
|
||||||
|
* 2. to_pay . 'doit payer' -> ko : [1: apres premier form - ok], [2: apres form qui suit carte expiree - ok], [3: apres paiement immediat echoue - ko], [4: apres virement echoue - ko]
|
||||||
|
* 3. valid . 'carte valide' ->
|
||||||
|
* 4. waiting_invalid . 'en attente invalide' ->
|
||||||
|
* 5. waiting_valid . 'en attente valide' ->
|
||||||
|
* 6. expired . 'carte expiree' ->
|
||||||
|
*
|
||||||
|
* receives the name of the state, and compare it to the current state
|
||||||
|
* either use the is_acf_card_state_CIPF() function directly,
|
||||||
|
* or one of the specific functions
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function is_account_state_CIPF($state_name, $user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$acf_account_state = Cipf::ACF_ACCOUNT_STATE;
|
||||||
|
if (is_null($user_id)) {
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
}
|
||||||
|
$acf_id = 'user_'.$user_id;
|
||||||
|
return is_acf_state_CIPF($acf_account_state, $state_name, $acf_id);
|
||||||
|
}
|
||||||
|
function is_account_new_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
return is_account_state_CIPF('new', $user_id);
|
||||||
|
}
|
||||||
|
function is_account_to_pay_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
return is_account_state_CIPF('to_pay', $user_id);
|
||||||
|
}
|
||||||
|
function is_account_valid_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
return is_account_state_CIPF('valid', $user_id);
|
||||||
|
}
|
||||||
|
function is_account_waiting_invalid_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
return is_account_state_CIPF('waiting_invalid', $user_id);
|
||||||
|
}
|
||||||
|
function is_account_waiting_valid_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
return is_account_state_CIPF('waiting_valid', $user_id);
|
||||||
|
}
|
||||||
|
function is_account_expired_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
return is_account_state_CIPF('expired', $user_id);
|
||||||
|
}
|
||||||
|
// additional : check both waitings
|
||||||
|
function is_account_waiting_transfert_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
if (is_account_waiting_valid_CIPF($user_id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (is_account_waiting_invalid_CIPF($user_id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* setters :
|
||||||
|
*/
|
||||||
|
function set_account_state_CIPF($state_name, $user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$acf_account_state = Cipf::ACF_ACCOUNT_STATE;
|
||||||
|
if (is_null($user_id)) {
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
}
|
||||||
|
$acf_id = 'user_'.$user_id;
|
||||||
|
set_acf_state_CIPF($acf_account_state, $state_name, $acf_id);
|
||||||
|
}
|
||||||
|
function set_account_new_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
set_account_state_CIPF('new', $user_id);
|
||||||
|
}
|
||||||
|
function set_account_to_pay_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
set_account_state_CIPF('to_pay', $user_id);
|
||||||
|
}
|
||||||
|
function set_account_valid_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
set_account_state_CIPF('valid', $user_id);
|
||||||
|
}
|
||||||
|
function set_account_waiting_invalid_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
set_account_state_CIPF('waiting_invalid', $user_id);
|
||||||
|
}
|
||||||
|
function set_account_waiting_valid_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
set_account_state_CIPF('waiting_valid', $user_id);
|
||||||
|
}
|
||||||
|
function set_account_expired_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
set_account_state_CIPF('expired', $user_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* etat carte ('etat_carte') :
|
||||||
|
* - 'Commande'
|
||||||
|
* - 'Renouvellement'
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function is_card_state_CIPF($state, $user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$acf_card_state = Cipf::ACF_CARD_STATE;
|
||||||
|
if (is_null($user_id)) {
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
}
|
||||||
|
$acf_id = 'user_'.$user_id;
|
||||||
|
return is_acf_state_CIPF($acf_card_state, $state, $acf_id);
|
||||||
|
}
|
||||||
|
function is_card_new_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
return is_card_state_CIPF('new', $user_id);
|
||||||
|
}
|
||||||
|
function is_card_renew_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
return is_card_state_CIPF('renew', $user_id);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* setters :
|
||||||
|
*/
|
||||||
|
function set_card_state_CIPF($state, $user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$acf_card_state = Cipf::ACF_CARD_STATE;
|
||||||
|
if (is_null($user_id)) {
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
}
|
||||||
|
$acf_id = 'user_'.$user_id;
|
||||||
|
set_acf_state_CIPF($acf_card_state, $state, $acf_id);
|
||||||
|
}
|
||||||
|
function set_card_new_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
set_card_state_CIPF('new', $user_id);
|
||||||
|
}
|
||||||
|
function set_card_renew_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
set_card_state_CIPF('renew', $user_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* etat page partenaire ('etat_page_partenaire') :
|
||||||
|
* - 'Publiee'
|
||||||
|
* - 'Brouillon'
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function is_page_state_CIPF($state, $post_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$acf_page_state = Cipf::ACF_PAGE_STATE;
|
||||||
|
if (is_null($post_id)) {
|
||||||
|
$post_id = get_the_ID();
|
||||||
|
}
|
||||||
|
$acf_id = $post_id;
|
||||||
|
return is_acf_state_CIPF($acf_page_state, $state, $acf_id);
|
||||||
|
}
|
||||||
|
function is_page_publish_CIPF($post_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
return is_page_state_CIPF('publish', $post_id);
|
||||||
|
}
|
||||||
|
function is_page_draft_CIPF($post_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
return is_page_state_CIPF('draft', $post_id);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* setters :
|
||||||
|
*/
|
||||||
|
function set_page_state_CIPF($state, $post_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$acf_page_state = Cipf::ACF_PAGE_STATE;
|
||||||
|
if (is_null($post_id)) {
|
||||||
|
$post_id = get_the_ID();
|
||||||
|
}
|
||||||
|
$acf_id = $post_id;
|
||||||
|
set_acf_state_CIPF($acf_page_state, $state, $acf_id);
|
||||||
|
}
|
||||||
|
function set_page_publish_CIPF($post_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
set_page_state_CIPF('publish', $post_id);
|
||||||
|
}
|
||||||
|
function set_page_draft_CIPF($post_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
set_page_state_CIPF('draft', $post_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* type paiement ('paiement') :
|
||||||
|
* - 'paypal'=>'Paypal'
|
||||||
|
* - 'transfert'=>'Virement'
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function is_card_method_CIPF($state, $user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$acf_card_payment_method = Cipf::ACF_CARD_PAYMENT_METHOD;
|
||||||
|
if (is_null($user_id)) {
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
}
|
||||||
|
$acf_id = 'user_'.$user_id;
|
||||||
|
return is_acf_state_CIPF($acf_card_payment_method, $state, $acf_id);
|
||||||
|
}
|
||||||
|
function is_payment_method_paypal_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
return is_card_method_CIPF('paypal', $user_id);
|
||||||
|
}
|
||||||
|
function is_payment_method_transfert_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
return is_card_method_CIPF('transfert', $user_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* etat paiement ('etat_paiement') :
|
||||||
|
* - 'en_cours'
|
||||||
|
* - 'reussi'
|
||||||
|
* - 'echec'
|
||||||
|
* - 'aucun'
|
||||||
|
*
|
||||||
|
* 'started'=>'en_cours', 'success'=>'reussi', 'failure'=>'echec', 'nothing'=>'aucun'
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function is_payment_state_CIPF($type, $user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$acf_card_payment_state = Cipf::ACF_CARD_PAYMENT_STATE;
|
||||||
|
if (is_null($user_id)) {
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
}
|
||||||
|
$acf_id = 'user_'.$user_id;
|
||||||
|
return is_acf_state_CIPF($acf_card_payment_state, $type, $acf_id);
|
||||||
|
}
|
||||||
|
function is_payment_started_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
return is_payment_state_CIPF('started', $user_id);
|
||||||
|
}
|
||||||
|
function is_payment_success_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
return is_payment_state_CIPF('success', $user_id);
|
||||||
|
}
|
||||||
|
function is_payment_failure_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
return is_payment_state_CIPF('failure', $user_id);
|
||||||
|
}
|
||||||
|
function is_payment_nothing_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
return is_payment_state_CIPF('nothing', $user_id);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* setters
|
||||||
|
*/
|
||||||
|
function set_payment_state_CIPF($type, $user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$acf_card_payment_state = Cipf::ACF_CARD_PAYMENT_STATE;
|
||||||
|
if (is_null($user_id)) {
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
}
|
||||||
|
$acf_id = 'user_'.$user_id;
|
||||||
|
set_acf_state_CIPF($acf_card_payment_state, $type, $acf_id);
|
||||||
|
}
|
||||||
|
function set_payment_started_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
set_payment_state_CIPF('started', $user_id);
|
||||||
|
}
|
||||||
|
function set_payment_success_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
set_payment_state_CIPF('success', $user_id);
|
||||||
|
}
|
||||||
|
function set_payment_failure_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
set_payment_state_CIPF('failure', $user_id);
|
||||||
|
}
|
||||||
|
function set_payment_nothing_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
set_payment_state_CIPF('nothing', $user_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* numero de carte
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function set_card_number_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$acf_card_number = Cipf::ACF_CARD_NUMBER;
|
||||||
|
|
||||||
|
if (is_null($user_id)) {
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
}
|
||||||
|
$acf_id = 'user_'.$user_id;
|
||||||
|
|
||||||
|
$date_now = date_create('today');
|
||||||
|
$card_id = $date_now->format('Ymd') . $user_id;
|
||||||
|
update_field($acf_card_number['_name'], $card_id, $acf_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* cgv
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function reset_acf_cgv_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$acf_cgv = Cipf::ACF_PROF_CGV;
|
||||||
|
|
||||||
|
if (is_null($user_id)) {
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
}
|
||||||
|
$acf_id = 'user_'.$user_id;
|
||||||
|
update_field($acf_cgv['_name'], array(""), $acf_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* etat virement
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function is_transfert_success_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$acf_transfert_state = Cipf::ACF_TRANSFERT_STATE;
|
||||||
|
|
||||||
|
if (is_null($user_id)) {
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
}
|
||||||
|
$acf_id = 'user_'.$user_id;
|
||||||
|
$transfert_state = get_field($acf_transfert_state['_name'], $acf_id);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* before first use : returns null
|
||||||
|
* if checked : returns value
|
||||||
|
* if unchecked : returns empty
|
||||||
|
*/
|
||||||
|
if (is_null($transfert_state)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if (empty($transfert_state)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function reset_acf_transfert_CIPF($user_id = null) {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$acf_transfert_state = Cipf::ACF_TRANSFERT_STATE;
|
||||||
|
|
||||||
|
if (is_null($user_id)) {
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
}
|
||||||
|
$acf_id = 'user_'.$user_id;
|
||||||
|
update_field($acf_transfert_state['_name'], array(""), $acf_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -1,170 +0,0 @@
|
|||||||
<?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!');
|
|
||||||
}
|
|
||||||
|
|
||||||
include_once(PLGNTLS_class::root_path() . 'php/format_user_infos.php');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function extract_if_array_size_one_CIPF($value) {
|
|
||||||
PLGNTLS_class::debug_infos();
|
|
||||||
if (is_array($value) && count($value) === 1)
|
|
||||||
return reset($value);
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
function merge_two_arrays_CIPF($array1, $array2) {
|
|
||||||
PLGNTLS_class::debug_infos();
|
|
||||||
$new_array = $array1;
|
|
||||||
foreach ($array2 as $key2 => $value2) {
|
|
||||||
$value = extract_if_array_size_one_CIPF($value2);
|
|
||||||
// if key was not in first array, add the new element to it
|
|
||||||
if (!isset($new_array[$key2])) {
|
|
||||||
$new_array[$key2] = $value2;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// if key was in first array, add both in an array
|
|
||||||
$value1 = extract_if_array_size_one_CIPF($new_array[$key2]);
|
|
||||||
if (empty($value1))
|
|
||||||
$new_array[$key2] = $value2;
|
|
||||||
else if (empty($value2))
|
|
||||||
$new_array[$key2] = $value1;
|
|
||||||
else {
|
|
||||||
$new_value = array($value1, $value2);
|
|
||||||
$new_array[$key] = $new_value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $new_array;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function output_list_front_CIPF($array, $current_user, $user_id) {
|
|
||||||
PLGNTLS_class::debug_infos();
|
|
||||||
$output = '<ul>';
|
|
||||||
foreach ($array as $key => $value) {
|
|
||||||
if (str_starts_with($key, '_'))
|
|
||||||
continue ;
|
|
||||||
$value = format_user_info_CIPF($key, $current_user, $user_id);
|
|
||||||
$output .= '<li>';
|
|
||||||
$output .= '<span>';
|
|
||||||
$output .= $key;
|
|
||||||
$output .= ' : ';
|
|
||||||
$output .= $value;
|
|
||||||
$output .= '</span>';
|
|
||||||
$output .= '</li>';
|
|
||||||
}
|
|
||||||
$output .= '</ul>';
|
|
||||||
return $output;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* shortcode to write user info of post author
|
|
||||||
* 0 or 1 argument, usage :
|
|
||||||
* - [cipf_user_info] -> list of all availables infos
|
|
||||||
* - [cipf_user_info user_email] -> display the email
|
|
||||||
* - [cipf_user_info user_email user_login] -> display the email
|
|
||||||
* - [cipf_user_info user_email author='logged_in'] -> display the email of the connected user
|
|
||||||
* - [cipf_user_info user_email author='post_creator'] -> display the email of the creator of the page/post
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function current_user_infos_CIPF($atts) {
|
|
||||||
PLGNTLS_class::debug_infos();
|
|
||||||
if (!is_user_logged_in())
|
|
||||||
return ;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* choose the default id target : logged in user, or post creator ?
|
|
||||||
*
|
|
||||||
$author_is = 'logged_in'; // logged in user
|
|
||||||
*/
|
|
||||||
$author_is = 'post_creator'; // creator of post (also for author pages)
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* has parameter 'author' ?
|
|
||||||
* if yes, removes it from $atts
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
if (is_array($atts)) {
|
|
||||||
if (isset($atts['author'])) {
|
|
||||||
$author_is = $atts['author'];
|
|
||||||
unset($atts['author']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* should output all or a specific parameter ?
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
$output_all = false;
|
|
||||||
if (empty($atts))
|
|
||||||
$output_all = true;
|
|
||||||
else if (count($atts) === 0)
|
|
||||||
$output_all = true;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* get author id outside loop and outside singular page : https://wordpress.stackexchange.com/q/65548
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
if ($author_is === 'logged_in') {
|
|
||||||
$current_user = wp_get_current_user();
|
|
||||||
$user_id = get_current_user_id();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (is_author()) {
|
|
||||||
$user_id = get_queried_object_id();
|
|
||||||
}
|
|
||||||
else if (in_the_loop()) {
|
|
||||||
$user_id = get_the_author_meta('ID');
|
|
||||||
}
|
|
||||||
else if (is_singular()) {
|
|
||||||
$user_id = get_queried_object()->post_author;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
global $wp_query;
|
|
||||||
if (!empty($wp_query->posts))
|
|
||||||
$user_id = $wp_query->posts[0]->post_author;
|
|
||||||
}
|
|
||||||
//$current_user = new WP_User($user_id);
|
|
||||||
$current_user = get_user_by('id', $user_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* output all the available parameters (for help)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
if ($output_all) {
|
|
||||||
$user_properties = (array) get_userdata($user_id)->data;
|
|
||||||
$user_metas = get_user_meta($user_id);
|
|
||||||
$user_infos = merge_two_arrays_CIPF($user_metas, $user_properties);
|
|
||||||
return output_list_front_CIPF($user_infos, $current_user, $user_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* real purpose of this shortcode :
|
|
||||||
* only return the first argument (that is not 'author')
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
if (is_array($atts))
|
|
||||||
$query = $atts[0];
|
|
||||||
else if (is_string($atts))
|
|
||||||
$query = $atts;
|
|
||||||
else
|
|
||||||
return '';
|
|
||||||
// $output = $current_user->$query;
|
|
||||||
return format_user_info_CIPF($query, $current_user, $user_id);
|
|
||||||
}
|
|
||||||
add_shortcode('cipf_user_info', 'current_user_infos_CIPF');
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
||||||
@@ -12,7 +12,7 @@ if (!defined('ABSPATH')) {
|
|||||||
https://stackify.com/how-to-log-to-console-in-php/
|
https://stackify.com/how-to-log-to-console-in-php/
|
||||||
*/
|
*/
|
||||||
function console_log(...$outputs) {
|
function console_log(...$outputs) {
|
||||||
PLGNTLS_class::debug_infos();
|
Plgntls::debug_infos();
|
||||||
if (CIPF_CONSOLE_OFF)
|
if (CIPF_CONSOLE_OFF)
|
||||||
return;
|
return;
|
||||||
foreach($outputs as $output)
|
foreach($outputs as $output)
|
||||||
1385
plugins/cipf_plugin/plgntls_class.php
Normal file
1385
plugins/cipf_plugin/plgntls_class.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,573 +0,0 @@
|
|||||||
<?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!');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* include those two lines at the top of the main plugin file
|
|
||||||
*
|
|
||||||
* include_once( plugin_dir_path(__FILE__) . '/php/utils/plugin_tools.php');
|
|
||||||
* PLGNTLS_class::set_root_dir( plugin_dir_path(__FILE__), plugin_dir_url(__FILE__) );
|
|
||||||
*
|
|
||||||
* PLGNTLS means PLUGIN TOOLS
|
|
||||||
*
|
|
||||||
* .add_to_front() : this method is made to add files and codes all at once
|
|
||||||
* otherwise use the wp functions (wp_enqueue_*, wp_add_inline_*, etc)
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* ex:
|
|
||||||
*
|
|
||||||
* $my_plugin_class = new PLGNTLS_class();
|
|
||||||
* $var_1 = 'value_1';
|
|
||||||
* $var_2 = 'value_2';
|
|
||||||
* $var_3 = 'value_3';
|
|
||||||
* return $my_plugin_class->add_to_front(
|
|
||||||
* array( // files added in order by types
|
|
||||||
* 'path/to/style1.css', //
|
|
||||||
* 'path/to/script1.js', //
|
|
||||||
* 'style1_css' => 'path/to/style2.css', // -> depends on style1.css
|
|
||||||
* 'http://my_url1.com', //
|
|
||||||
* 'script1_js' => 'path/to/script2.js', // -> depends on script1.js
|
|
||||||
* 'path/to/file1.html', // | will be returned
|
|
||||||
* 'path/to/file2.html', // -> | as expanded html
|
|
||||||
* 'path/to/file3.html', // | in the order included
|
|
||||||
* 'handle_name' => 'path/to/script3.js', // -> depends on the script with handle 'handle_name'
|
|
||||||
* array( //
|
|
||||||
* 'path/to/script4.js', // | add a script with attributes
|
|
||||||
* 'attribute_1' => 'value_1', // -> | first element of array must be
|
|
||||||
* 'attribute_2' => 'value_2', // | the script, without explicit key
|
|
||||||
* ), //
|
|
||||||
* array( 'js' => 'var_js' ), // -> add inline js, only first element will be used
|
|
||||||
* array( 'css' => 'var_css' ), // -> add inline css, only first element will be used
|
|
||||||
* ),
|
|
||||||
* compact( // these variables are added to html and js files
|
|
||||||
* 'var_1', // - in html files you can access them directly
|
|
||||||
* 'var_2', // - in js files they are properties of object PLGNTLS_data
|
|
||||||
* 'var_3', // like PLGNTLS_data.var_1;
|
|
||||||
* )
|
|
||||||
* );
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
class PLGNTLS_class
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* const declarations
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// ACF
|
|
||||||
const ACF_CARD_STATE = ['_name'=>'etat_carte', 'new'=>'Commande', 'renew'=>'Renouvellement']; // radio button
|
|
||||||
const ACF_CARD_PAYMENT_METHOD = ['_name'=>'paiement', 'paypal'=>'Paypal', 'transfert'=>'Virement']; // radio button
|
|
||||||
const ACF_CARD_PRICE_CHOICE = ['_name'=>'tarif', 'low'=>'10', 'high'=>'15']; // radio button
|
|
||||||
const ACF_CARD_PRICE_DELIVERY = ['_name'=>'livraison', 'pdf'=>'PDF', 'post'=>'Fabrication']; // radio button
|
|
||||||
const ACF_PROF_IS_ACTIV = ['_name'=>'compte-actif', 'activ'=>'Actif', 'inactiv'=>'Inactif']; // radio button
|
|
||||||
const ACF_PROF_CGV = ['_name'=>'cgv', 'cgv'=>'cgv']; // checkbox
|
|
||||||
const ACF_CARD_PRICE_TOTAL = ['_name'=>'somme_a_regler']; // number
|
|
||||||
const ACF_CARD_NUMBER = ['_name'=>'numero_de_la_carte']; // number
|
|
||||||
const ACF_CARD_EXPIRATION = ['_name'=>'fin_de_validite']; // date picker
|
|
||||||
const ACF_CARD_PAYMENT_STATE = ['_name'=>'etat_paiement', 'started'=>'en_cours', 'success'=>'reussi', 'failure'=>'echec', 'nothing'=>'aucun']; // radio button
|
|
||||||
|
|
||||||
// META
|
|
||||||
const META_PAYEMENT_STATUS = 'cipf_payement_status';
|
|
||||||
const META_ORDER_ID = 'cipf_order_id';
|
|
||||||
|
|
||||||
// SLUG & URL & QUERY
|
|
||||||
const SLUG_PROF_INACTIV = 'validation-en-cours';
|
|
||||||
const SLUG_RENEW_CARD = 'commande';
|
|
||||||
const SLUG_PAGE_REDIRECTION = 'redirection_cipf';
|
|
||||||
// const SLUG_PAYPAL_REDIRECTION_SUCCESS = self::SLUG_PAGE_REDIRECTION;
|
|
||||||
// const SLUG_PAYPAL_REDIRECTION_FAILURE = self::SLUG_PAGE_REDIRECTION;
|
|
||||||
const SLUG_PAYPAL_REDIRECTION_SUCCESS = '?'.self::QUERY_REDIRECTION_PROFIL;
|
|
||||||
const SLUG_PAYPAL_REDIRECTION_FAILURE = '?'.self::QUERY_REDIRECTION_PROFIL;
|
|
||||||
const URL_BASE_REST_ROUTE = 'cipf_plugin/api/v1'; // for routes, in php/paypal/routes.php && php/admin_modif_prof.php
|
|
||||||
const QUERY_REDIRECTION_PROFIL = 'redirection_cipf';
|
|
||||||
const QUERY_ADMIN_VALIDATE_PROF = 'admin_activate_prof_cipf'; // for admin_modif_prof.php
|
|
||||||
|
|
||||||
// PAYPAL
|
|
||||||
const PAYPAL_CLIENT_ID = "AfcmwxIXlG2ZxaMdjazX57I70BXz__aEqNWaTnqfSCI34a0V7nMbytswx7EViUjlpHs7opyrRwaH9YLl";
|
|
||||||
const PAYPAL_CLIENT_SECRET = "EGunIhGRjPvn0Z8wXO0JsdhET30OStTAH_IyRsmhimEN23_qiRSFD-ql4tvnulKJw6TitZ-vU-ytc4A-";
|
|
||||||
const PAYPAL_API_BASE_URL = "https://api-m.sandbox.paypal.com";
|
|
||||||
const PAYPAL_MESSAGE_SUCCESS = '`paiement reussi`';
|
|
||||||
const PAYPAL_MESSAGE_FAILURE = '`paiement raté`';
|
|
||||||
|
|
||||||
// ROLES
|
|
||||||
const ROLE_PROF = 'professeur__professeure';
|
|
||||||
const ROLE_PARTNER = 'partenaire';
|
|
||||||
const ROLE_FIPF = 'fipf';
|
|
||||||
const ROLE_ADMIN = 'administrator';
|
|
||||||
|
|
||||||
// OTHER
|
|
||||||
const CARD_RENEW_PERIOD = 31; // int : number of days before expiration when renew card start to be possible
|
|
||||||
const CARD_VALIDITY_TIME = '1 year'; // string : time of validity of the card (ex: '1 month' or '1 year' or '60 days')
|
|
||||||
const USER_INFO_DATE_FORMAT = 'd/m/Y'; // for user_infos.php (date format : https://www.php.net/manual/fr/datetime.format.php)
|
|
||||||
const ADMIN_VALIDATE_PROF_FIELD = 'admin_activate_prof_cipf'; // for admin_modif_prof.php
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static $_DEBUG_INFOS = true;
|
|
||||||
private static $_plugin_dir_path;
|
|
||||||
private static $_plugin_name;
|
|
||||||
private static $_file_dir_path;
|
|
||||||
private static $_file_name;
|
|
||||||
private static $_root_path;
|
|
||||||
private static $_root_url;
|
|
||||||
|
|
||||||
private $_first_script;
|
|
||||||
private $_first_style;
|
|
||||||
private $_prefix;
|
|
||||||
private $_js_dependencies;
|
|
||||||
private $_css_dependencies;
|
|
||||||
private $_scripts_attributes;
|
|
||||||
|
|
||||||
/*
|
|
||||||
*/
|
|
||||||
public function __construct() {
|
|
||||||
if (!isset(self::$_plugin_name, self::$_file_name, self::$_file_dir_path, self::$_plugin_dir_path))
|
|
||||||
self::set_root_dir();
|
|
||||||
$this->_prefix = "PLGNTLS";
|
|
||||||
$this->_first_script = null;
|
|
||||||
$this->_first_style = null;
|
|
||||||
$this->_js_dependencies = array();
|
|
||||||
$this->_css_dependencies = array();
|
|
||||||
$this->_scripts_attributes = array();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* ex:
|
|
||||||
* /home/www-data/cipf_plugin/php/test/test2/test3/test.php
|
|
||||||
* _plugin_dir_path /home/www-data
|
|
||||||
* _plugin_name cipf_plugin
|
|
||||||
* _file_dir_path php/test/test2/test3
|
|
||||||
* _file_name test.php
|
|
||||||
* _root_path /home/www-data/cipf_plugin/
|
|
||||||
*
|
|
||||||
* /home/www-data/cipf_plugin/test.php
|
|
||||||
* _plugin_dir_path /home/www-data
|
|
||||||
* _plugin_name cipf_plugin
|
|
||||||
* _file_dir_path ''
|
|
||||||
* _file_name test.php
|
|
||||||
* _root_path /home/www-data/cipf_plugin/
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static function set_root_dir() {
|
|
||||||
if (isset(self::$_plugin_name, self::$_file_name, self::$_file_dir_path, self::$_plugin_dir_path))
|
|
||||||
return ;
|
|
||||||
/*
|
|
||||||
* it uses exploded_path_path by removing data from the array
|
|
||||||
* so order is important !
|
|
||||||
* plugin_name / path / to / file.php
|
|
||||||
* exploded [plugin_name, path, to, file.php]
|
|
||||||
* plugin_name plugin_name [path, to, file.php]
|
|
||||||
* file_name [path, to] file.php
|
|
||||||
* file_dir_name path / to
|
|
||||||
*/
|
|
||||||
$exploded_plugin_path = explode('/', plugin_basename( __FILE__ ));
|
|
||||||
|
|
||||||
self::$_plugin_name = array_shift($exploded_plugin_path);
|
|
||||||
self::$_file_name = array_pop($exploded_plugin_path);
|
|
||||||
self::$_file_dir_path = implode('/', $exploded_plugin_path);
|
|
||||||
|
|
||||||
self::$_plugin_dir_path = str_replace('/'.plugin_basename(__DIR__).'/', '', plugin_dir_path(__FILE__));
|
|
||||||
self::$_root_path = self::$_plugin_dir_path.'/'.self::$_plugin_name.'/';
|
|
||||||
self::$_root_url = plugins_url(self::$_plugin_name.'/');
|
|
||||||
}
|
|
||||||
public static function root_path() {
|
|
||||||
if (!isset(self::$_plugin_name, self::$_file_name, self::$_file_dir_path, self::$_plugin_dir_path))
|
|
||||||
self::set_root_dir();
|
|
||||||
return(self::$_root_path);
|
|
||||||
}
|
|
||||||
public static function root_url() {
|
|
||||||
if (!isset(self::$_plugin_name, self::$_file_name, self::$_file_dir_path, self::$_plugin_dir_path))
|
|
||||||
self::set_root_dir();
|
|
||||||
return(self::$_root_url);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* for debug purposes
|
|
||||||
*/
|
|
||||||
public static function debug_infos() {
|
|
||||||
if (self::$_DEBUG_INFOS === false)
|
|
||||||
return;
|
|
||||||
$trace = debug_backtrace();
|
|
||||||
$function = $trace[1]['function'];
|
|
||||||
$file = $trace[0]['file'];
|
|
||||||
$line = $trace[0]['line'];
|
|
||||||
error_log("-debug: function '".$function."' (in ".$file.", line ".$line .')');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function add_to_front($srcs_arr = array(), $vars = array()) {
|
|
||||||
/*
|
|
||||||
* event if the function is called with no srcs
|
|
||||||
* add fetch, because it can be used just for that
|
|
||||||
*/
|
|
||||||
$this->add_fetch($srcs_arr, $vars);
|
|
||||||
$this->add_default_css($srcs_arr, $vars);
|
|
||||||
|
|
||||||
$srcs = array();
|
|
||||||
foreach($srcs_arr as $src_key => $src_value) {
|
|
||||||
$init = $this->init_src($src_key, $src_value);
|
|
||||||
if ($init !== null)
|
|
||||||
$srcs[] = $init;
|
|
||||||
}
|
|
||||||
if (!is_null($srcs_arr))
|
|
||||||
$this->add_srcs_to_front($srcs);
|
|
||||||
|
|
||||||
if (!is_null($vars))
|
|
||||||
$this->add_vars_to_front($vars);
|
|
||||||
return $this->create_html($srcs, $vars);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
||||||
* PRIVATES FUNCTIONS
|
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* for fetch, we add the file script that contains the fetch function
|
|
||||||
* it is an es6 module with the export keyword
|
|
||||||
* that way, it can also be used by modules scripts
|
|
||||||
* to achieve that, we wouldn't need to include it here though
|
|
||||||
* but we need that the fetch function is also available for inline scripts
|
|
||||||
* so we could attach a copy of the script file without the export keyword
|
|
||||||
* but instead, inside the file, we add the fetch function to the global scope
|
|
||||||
*/
|
|
||||||
private function add_fetch(&$srcs_arr, &$vars) {
|
|
||||||
// add fetch script at beginning of scripts list
|
|
||||||
array_unshift($srcs_arr, array(self::$_file_dir_path."/plgntls_fetch.js", 'type'=>'module'));
|
|
||||||
// for the custom endpoints in rest api to work
|
|
||||||
// they need to have a nonce named 'wp_rest'
|
|
||||||
// see : https://developer.wordpress.org/rest-api/using-the-rest-api/authentication/
|
|
||||||
$fetch_nonce = array("fetch_nonce" => wp_create_nonce('wp_rest'));
|
|
||||||
$fetch_url = array("fetch_url" => get_site_url() . "/wp-json");
|
|
||||||
$vars = array_merge($vars, $fetch_nonce);
|
|
||||||
$vars = array_merge($vars, $fetch_url);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function add_default_css(&$srcs_arr, &$vars) {
|
|
||||||
// add default css file at beginning of style list
|
|
||||||
array_unshift($srcs_arr, self::$_file_dir_path."/plgntls_default.css");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @param two arguments :
|
|
||||||
* 1. html files to include in front
|
|
||||||
* - can be a string of 1 filename
|
|
||||||
* - or an array of strings of filenames
|
|
||||||
* ( https://stackoverflow.com/q/4747876/9497573 )
|
|
||||||
* - it's probably better to only add 1 file, and let it include other files
|
|
||||||
* 2. list of variables to make available to this files
|
|
||||||
* - in the form of key => val
|
|
||||||
* - recommanded to do it with compact()
|
|
||||||
* ex: create_html( "file.html", compact("var1","var2",) );
|
|
||||||
* ex: create_html( array("file1.html", "file2.html"), array("var1"=>"value") );
|
|
||||||
* @return a string of html code
|
|
||||||
*
|
|
||||||
* using ob_start() and ob_get_clean()
|
|
||||||
* allows to have php expansion inside the html loaded
|
|
||||||
* in opposition to the methode file_get_contents()
|
|
||||||
*
|
|
||||||
* https://stackoverflow.com/a/4402045/9497573
|
|
||||||
*/
|
|
||||||
private function create_html($files = null, $vars = null) {
|
|
||||||
if (is_null($files))
|
|
||||||
return null;
|
|
||||||
$plgn_dir = $this->root_path();
|
|
||||||
if (!is_null($vars))
|
|
||||||
extract($vars);
|
|
||||||
|
|
||||||
ob_start();
|
|
||||||
foreach($files as $file) {
|
|
||||||
if ($file->ext === 'html')
|
|
||||||
include($file->path);
|
|
||||||
}
|
|
||||||
$html = ob_get_clean();
|
|
||||||
|
|
||||||
return $html;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* pass variables to js front as global variables
|
|
||||||
* @param array : list of key => value
|
|
||||||
* with the key being name of the variable, like this :
|
|
||||||
* 'my_var' => 'value',
|
|
||||||
* simpler way to do it is to use compact when calling the function :
|
|
||||||
* add_var_to_front(compact("var1", "var2", "var3"));
|
|
||||||
* @param string (optionnal) : name of first embended script that need these variables
|
|
||||||
* (it will be available to this script and all followings)
|
|
||||||
* this name is the filename + "_" + extension :
|
|
||||||
* init.js -> init_js
|
|
||||||
*/
|
|
||||||
private function add_vars_to_front($vars_arr)
|
|
||||||
{
|
|
||||||
if (is_null($this->_first_script))
|
|
||||||
return ;
|
|
||||||
if (is_null($vars_arr))
|
|
||||||
return ;
|
|
||||||
$handle = $this->_first_script;
|
|
||||||
$object_name = $this->_prefix . "_data";
|
|
||||||
|
|
||||||
$vars_json = json_encode($vars_arr);
|
|
||||||
$front = "let $object_name = $vars_json;";
|
|
||||||
wp_add_inline_script($handle, $front, 'before');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array : list of files :
|
|
||||||
* - with their path from root of their type of file (ex: from js/ to .js files)
|
|
||||||
* - and with their extension
|
|
||||||
* @param boolean
|
|
||||||
* - to add ajax script and variables
|
|
||||||
* - default to true
|
|
||||||
*/
|
|
||||||
private function add_srcs_to_front($srcs_arr) {
|
|
||||||
//wp_enqueue_script(<give_it_a_name>, /url/to/script, [depends on], version, defer? );
|
|
||||||
//wp_enqueue_style( <give_it_a_name>, /url/to/script, [depends on], version, media );
|
|
||||||
|
|
||||||
$previous_css_basename = '';
|
|
||||||
$previous_js_basename = '';
|
|
||||||
foreach ($srcs_arr as $src) {
|
|
||||||
if ($src->inline !== null) {
|
|
||||||
if ($src->inline === "js")
|
|
||||||
$this->add_inline_script($src);
|
|
||||||
else if ($src->inline === "css")
|
|
||||||
$this->add_inline_style($src);
|
|
||||||
}
|
|
||||||
else if (in_array($src->ext, array("js", "url"))) {
|
|
||||||
$this->add_script($src, $previous_js_basename);
|
|
||||||
$previous_js_basename = $src->handle;
|
|
||||||
}
|
|
||||||
else if ($src->ext === "css") {
|
|
||||||
$this->add_style($src, $previous_css_basename);
|
|
||||||
$previous_css_basename = $src->handle;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://developer.wordpress.org/reference/hooks/wp_script_attributes/
|
|
||||||
// https://wordpress.stackexchange.com/questions/66843/attach-a-private-function-at-a-hook
|
|
||||||
add_filter( 'wp_script_attributes', fn($attr)=>$this->add_attributes_to_script($attr), 10, 1 );
|
|
||||||
|
|
||||||
/*
|
|
||||||
* uncomment to print all enqueued files, can be usefull
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
global $wp_scripts;
|
|
||||||
error_log("wp_scripts->queue:");
|
|
||||||
error_log(json_encode($wp_scripts->queue));
|
|
||||||
global $wp_styles;
|
|
||||||
error_log("wp_styles->queue:");
|
|
||||||
error_log(json_encode($wp_styles->queue));
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
private function add_script($script, $previous_js_basename) {
|
|
||||||
if (is_null($this->_first_script))
|
|
||||||
$this->_first_script = $script->handle;
|
|
||||||
$depends_on = $this->check_dependencies($script, $previous_js_basename);
|
|
||||||
if ($depends_on !== null)
|
|
||||||
wp_enqueue_script( $script->handle, $script->url, $depends_on, $script->version, true);
|
|
||||||
}
|
|
||||||
private function add_style($style, $previous_css_basename) {
|
|
||||||
if (is_null($this->_first_style))
|
|
||||||
$this->_first_style = $style->handle;
|
|
||||||
$depends_on = $this->check_dependencies($style, $previous_css_basename);
|
|
||||||
if ($depends_on !== null)
|
|
||||||
wp_enqueue_style( $style->handle, $style->url, $depends_on, $style->version, '');
|
|
||||||
}
|
|
||||||
private function add_inline_script($src) {
|
|
||||||
$handle = $src->depends;
|
|
||||||
if ($handle === null || empty($handle))
|
|
||||||
$handle = $this->_first_script;
|
|
||||||
wp_add_inline_script($handle, $src->src, 'before');
|
|
||||||
}
|
|
||||||
private function add_inline_style($src) {
|
|
||||||
$handle = $src->depends;
|
|
||||||
if ($handle === null || empty($handle))
|
|
||||||
$handle = $this->_first_style;
|
|
||||||
wp_add_inline_style($handle, $src->src);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private function add_attributes_to_script($attr) {
|
|
||||||
if (empty($attr['id']))
|
|
||||||
return $attr;
|
|
||||||
$handle = $attr['id'];
|
|
||||||
if (isset($this->_scripts_attributes[$handle]))
|
|
||||||
$script = $this->_scripts_attributes[$handle];
|
|
||||||
else
|
|
||||||
return $attr;
|
|
||||||
|
|
||||||
foreach($script as $key => $value){
|
|
||||||
$attr[$key] = $value;
|
|
||||||
}
|
|
||||||
unset($this->_scripts_attributes[$handle]);
|
|
||||||
|
|
||||||
return $attr;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function check_dependencies(&$src, $previous_basename)
|
|
||||||
{
|
|
||||||
if (in_array($src->ext, array("js", "url")))
|
|
||||||
{
|
|
||||||
global $wp_scripts;
|
|
||||||
$already_enqueued = array_search($src->handle, $wp_scripts->queue);
|
|
||||||
if ($already_enqueued !== false)
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
else if ($src->ext === "css")
|
|
||||||
{
|
|
||||||
global $wp_styles;
|
|
||||||
$already_enqueued = array_search($src->handle, $wp_styles->queue);
|
|
||||||
if ($already_enqueued !== false)
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$depends_on = array();
|
|
||||||
if (isset($src->depends) && $src->depends !== '')
|
|
||||||
$depends_on[] = $src->depends;
|
|
||||||
if (isset($previous_basename) && $previous_basename !== '')
|
|
||||||
$depends_on[] = $previous_basename;
|
|
||||||
|
|
||||||
return $depends_on;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string : name of the file, with its path from its extension directory
|
|
||||||
* - from js/ root for .js files
|
|
||||||
* - from css/ root for .css files
|
|
||||||
* @return object / null :
|
|
||||||
* - null if file is not valid
|
|
||||||
* - or an object with all the necessary infos :
|
|
||||||
* 0. src : array("name.js", ...) -> "name.js"
|
|
||||||
* "name.js" -> "name.js"
|
|
||||||
* 1. ext : name.js -> "js"
|
|
||||||
* 2. basename : name.js -> "name"
|
|
||||||
* 3. handle : name.js -> "name_js"
|
|
||||||
* 4. url : url to file in wordpress
|
|
||||||
* 5. path : path to file in server
|
|
||||||
* 6. version : used to avoid browser caching
|
|
||||||
* 7. depends : string if depends on a handle, or ''
|
|
||||||
* 8. attr : associative array of html attribute like 'type'=>'module'
|
|
||||||
* 9. inline : array("js" => "name.js") -> js
|
|
||||||
* array("css" => "name.css") -> css
|
|
||||||
*/
|
|
||||||
private function init_src($key, $value) {
|
|
||||||
if (empty($value))
|
|
||||||
return null;
|
|
||||||
$src = (object)[
|
|
||||||
'src' => null,
|
|
||||||
'ext' => null,
|
|
||||||
'basename' => null,
|
|
||||||
'handle' => null,
|
|
||||||
'url' => null,
|
|
||||||
'path' => null,
|
|
||||||
'version' => null,
|
|
||||||
'depends' => null,
|
|
||||||
'attr' => null,
|
|
||||||
'inline' => null,
|
|
||||||
];
|
|
||||||
|
|
||||||
// 7. depends
|
|
||||||
if (is_string($key))
|
|
||||||
$src->depends = $key;
|
|
||||||
|
|
||||||
// 0. src
|
|
||||||
// 8. attr
|
|
||||||
// 9. inline
|
|
||||||
// first element of array is used, so must not be empty
|
|
||||||
// value => ['path/to/file', 'key1'=>'value1', 'key2'=>'value2']
|
|
||||||
// src => 'path/to/file'
|
|
||||||
// attr => ['key1'=>'value1', 'key2'=>'value2']
|
|
||||||
if (is_array($value)){
|
|
||||||
$first_key = array_keys($value)[0];
|
|
||||||
if (empty($value[$first_key]))
|
|
||||||
return null;
|
|
||||||
if ($first_key === 0) { // is a script file or url with attributes
|
|
||||||
$src->src = array_shift($value);
|
|
||||||
$src->attr = $value;
|
|
||||||
}
|
|
||||||
else if ($first_key === "js" || $first_key === "css") { // is an inline code
|
|
||||||
$src->src = $value[$first_key];
|
|
||||||
$src->inline = $first_key;
|
|
||||||
return $src; // inline only needs 'depends', 'src' and 'inline'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$src->src = $value;
|
|
||||||
$src->attr = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 1. ext
|
|
||||||
if(filter_var($src->src, FILTER_VALIDATE_URL))
|
|
||||||
$src->ext = "url";
|
|
||||||
else
|
|
||||||
$src->ext = pathinfo($src->src, PATHINFO_EXTENSION);
|
|
||||||
if (! in_array($src->ext, array("js", "css", "html", "url")))
|
|
||||||
return null;
|
|
||||||
|
|
||||||
// 2. basename
|
|
||||||
// 3. handle
|
|
||||||
// basename handle
|
|
||||||
// https://www.url.com/route -> www.url.com/route -> www_url_com_route
|
|
||||||
// path/to/script.js -> script.js -> script_js
|
|
||||||
if ($src->ext === "url") {
|
|
||||||
$url = parse_url($src->src);
|
|
||||||
$src->basename = $url['host'] . $url['path'];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
$src->basename = pathinfo($src->src, PATHINFO_BASENAME);
|
|
||||||
$src->handle = "PLGNTLS_" . str_replace(array('.', '/'), "_", $src->basename);
|
|
||||||
|
|
||||||
// 4. url
|
|
||||||
// 5. path
|
|
||||||
// 6. version
|
|
||||||
if ($src->ext === "url") {
|
|
||||||
$src->url = $src->src;
|
|
||||||
$src->path = null;
|
|
||||||
$src->version = null;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$src->url = $this->root_url().$src->src;
|
|
||||||
$src->path = $this->root_path().$src->src;
|
|
||||||
$src->version = date("ymd-Gis", filemtime($src->path));
|
|
||||||
}
|
|
||||||
|
|
||||||
// if ext is 'js' or 'url' and attr is not empty
|
|
||||||
// also add to global variable to access in 'wp_script_attributes' filter
|
|
||||||
if ($src->ext === 'js' || $src->ext === 'url') {
|
|
||||||
if ($src->attr !== null) {
|
|
||||||
$this->_scripts_attributes[$src->handle.'-js'] = $src->attr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $src;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
/*
|
|
||||||
* this css file will be automatically added to front by PLGNTLS_class
|
|
||||||
* no need to write any style here, but you can if you want
|
|
||||||
*/
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
* this file is there for scripts that uses modules import
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
export function PLGNTLS_fetch(url, options = {}) {
|
|
||||||
console.log("inside PLGNTLS_fetch");
|
|
||||||
url = PLGNTLS_data.fetch_url + url;
|
|
||||||
|
|
||||||
options.headers = options.headers || {};
|
|
||||||
options.headers['X-WP-Nonce'] = PLGNTLS_data.fetch_nonce,
|
|
||||||
console.log("options:", options);
|
|
||||||
|
|
||||||
return fetch(url, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* For non-module scripts, attach to the global scope
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
if (typeof window !== 'undefined') {
|
|
||||||
window.PLGNTLS_fetch = PLGNTLS_fetch;
|
|
||||||
}
|
|
||||||
|
|
||||||
48
plugins/custer/admin_menu.php
Normal file
48
plugins/custer/admin_menu.php
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
namespace CUSTER;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* the construction of the admin menu page
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function custer_plugin_content() {
|
||||||
|
echo "<p>hello</p>";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* menu plugin
|
||||||
|
*/
|
||||||
|
function custer_plugin_menu() {
|
||||||
|
$menu_page_title = 'custer';
|
||||||
|
$menu_title = 'custer';
|
||||||
|
$menu_capability = 'manage_options';
|
||||||
|
$menu_slug = 'custer-plugin';
|
||||||
|
$menu_callback = __NAMESPACE__.'\custer_plugin_content';
|
||||||
|
|
||||||
|
\CUSTER\toggle_menu($menu_page_title, $menu_title, $menu_capability, $menu_slug, $menu_callback);
|
||||||
|
}
|
||||||
|
add_action('admin_menu', __NAMESPACE__.'\custer_plugin_menu');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
108
plugins/custer/admin_menu_toggle.php
Normal file
108
plugins/custer/admin_menu_toggle.php
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
<?php
|
||||||
|
namespace CUSTER;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 toggle_menu($menu_page_title, $menu_title, $menu_capability, $menu_slug, $menu_callback) {
|
||||||
|
$toggle_menu = Custer::OPTION_TOGGLE_MENU;
|
||||||
|
|
||||||
|
if (false === get_option($toggle_menu['_name'])) {
|
||||||
|
add_option($toggle_menu['_name'], $toggle_menu['hide'], '', 'no');
|
||||||
|
}
|
||||||
|
|
||||||
|
$toggle = get_option($toggle_menu['_name']);
|
||||||
|
|
||||||
|
if ($toggle === $toggle_menu['hide']) {
|
||||||
|
remove_menu_page($menu_slug);
|
||||||
|
}
|
||||||
|
else if ($toggle === $toggle_menu['show']) {
|
||||||
|
add_menu_page($menu_page_title, $menu_title, $menu_capability, $menu_slug, $menu_callback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* add link under the plugin in the plugins admin page
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function add_link_to_custer_plugin($links) {
|
||||||
|
$slug_toggle = Custer::SLUG_TOOGLE_ADMIN_MENU;
|
||||||
|
$toggle_menu = Custer::OPTION_TOGGLE_MENU;
|
||||||
|
|
||||||
|
$toggle = get_option($toggle_menu['_name']);
|
||||||
|
|
||||||
|
if ($toggle === $toggle_menu['hide']) {
|
||||||
|
$links[] = '<a href="/'.$slug_toggle['_name'].'?'.$slug_toggle['toggle'].'='.$slug_toggle['show'].'">show menu</a>';
|
||||||
|
}
|
||||||
|
else if ($toggle === $toggle_menu['show']) {
|
||||||
|
$links[] = '<a href="/'.$slug_toggle['_name'].'?'.$slug_toggle['toggle'].'='.$slug_toggle['hide'].'">hide menu</a>';
|
||||||
|
}
|
||||||
|
return $links;
|
||||||
|
}
|
||||||
|
add_filter('plugin_action_links_custer/custer.php', __NAMESPACE__.'\add_link_to_custer_plugin');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* handle the toggle menu when url is reached
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function toggle_custer_plugin_menu() {
|
||||||
|
$slug_toggle = Custer::SLUG_TOOGLE_ADMIN_MENU;
|
||||||
|
$toggle_menu = Custer::OPTION_TOGGLE_MENU;
|
||||||
|
|
||||||
|
global $wp;
|
||||||
|
$current_slug = $wp->request;
|
||||||
|
if ($current_slug !== $slug_toggle['_name']) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$show = null;
|
||||||
|
if (!isset($_GET)) {
|
||||||
|
$show = null;
|
||||||
|
}
|
||||||
|
else if (empty($_GET)) {
|
||||||
|
$show = null;
|
||||||
|
}
|
||||||
|
if (!isset($_GET[$slug_toggle['toggle']])) {
|
||||||
|
$show = null;
|
||||||
|
}
|
||||||
|
else if ($_GET[$slug_toggle['toggle']] === $slug_toggle['show']) {
|
||||||
|
$show = true;
|
||||||
|
}
|
||||||
|
else if ($_GET[$slug_toggle['toggle']] === $slug_toggle['hide']) {
|
||||||
|
$show = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($show === true) {
|
||||||
|
update_option($toggle_menu['_name'], $toggle_menu['show']);
|
||||||
|
}
|
||||||
|
else if ($show === false) {
|
||||||
|
update_option($toggle_menu['_name'], $toggle_menu['hide']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$plugins_menu_url = admin_url('plugins.php');
|
||||||
|
wp_redirect($plugins_menu_url, 301);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
add_action('template_redirect', __NAMESPACE__.'\toggle_custer_plugin_menu');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
147
plugins/custer/change_id.php
Normal file
147
plugins/custer/change_id.php
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
<?php
|
||||||
|
namespace CUSTER;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* change the current user to the author id of the current object
|
||||||
|
* the only option is to force the author
|
||||||
|
* -> there is no sens in forcing the logged_in, because it's already the default
|
||||||
|
*
|
||||||
|
* [custer_author_id] -> give current user the id of author
|
||||||
|
* [custer_author_id off] -> reset to logged_in
|
||||||
|
*
|
||||||
|
* ! anchors not workink for the moment
|
||||||
|
* //[custer_author_id set_anchor='anchor_name'] -> create anchor for author user
|
||||||
|
* //[custer_author_id anchor='anchor_name'] -> give current user the id stored in the anchor_name
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function shortcode_author_id($options) {
|
||||||
|
$anchor_name = '';
|
||||||
|
$option = '';
|
||||||
|
$is_set_anchor = false;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* set option value :
|
||||||
|
* 'off', 'author', 'set_anchor', or 'anchor'
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (empty($options)) {
|
||||||
|
$option = 'author';
|
||||||
|
}
|
||||||
|
if (isset($options['set_anchor'])) {
|
||||||
|
$option = 'author';
|
||||||
|
// $is_set_anchor = true;
|
||||||
|
// $anchor_name = $options['set_anchor'];
|
||||||
|
// if (empty($anchor_name)) {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
unset($options['set_anchor']);
|
||||||
|
}
|
||||||
|
if (isset($options['anchor'])) {
|
||||||
|
// if ($is_set_anchor) {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// $option = 'anchor';
|
||||||
|
// $anchor_name = $options['anchor'];
|
||||||
|
// if (empty($anchor_name)) {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
unset($options['anchor']);
|
||||||
|
}
|
||||||
|
if (is_array($options) && in_array('off', $options)) {
|
||||||
|
$option = 'off';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($option)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* find id according to option
|
||||||
|
* if option is set_anchor, it sets it and return 0
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$id = \CUSTER\find_id_wih_option($option, $anchor_name);
|
||||||
|
if ($id === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* set current user
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if ($is_set_anchor) {
|
||||||
|
\CUSTER\create_anchor($anchor_name, $id);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
wp_set_current_user($id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_shortcode('custer_author_id', __NAMESPACE__.'\shortcode_author_id');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function create_anchor($anchor_name, $id) {
|
||||||
|
$option_anchor = Custer::OPTION_ANCHOR;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if needed, create the option
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (false === get_option($option_anchor)) {
|
||||||
|
add_option($option_anchor, array());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* add or update the id for the anchor name
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$anchors = get_option($option_anchor);
|
||||||
|
$anchors[$anchor_name] = $id;
|
||||||
|
update_option($option_anchor, $anchors);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* find ids according to options :
|
||||||
|
* - author : change the current user to the author of the page or post
|
||||||
|
* - anchor : uses the id stored in options with anchor_name
|
||||||
|
* - off : reset current user to the id before the changes
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function find_id_wih_option($option, $anchor_name) {
|
||||||
|
if ($option === 'author') {
|
||||||
|
$id = \CUSTER\get_author_id();
|
||||||
|
Custer::set_current_user_backup();
|
||||||
|
}
|
||||||
|
else if ($option === 'anchor') {
|
||||||
|
$id = \CUSTER\get_anchor_id($anchor_name);
|
||||||
|
Custer::set_current_user_backup();
|
||||||
|
}
|
||||||
|
else if ($option === 'off') {
|
||||||
|
$id = Custer::reset_current_user_backup();
|
||||||
|
}
|
||||||
|
return $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
35
plugins/custer/custer.php
Normal file
35
plugins/custer/custer.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
Plugin Name: hggg_custer
|
||||||
|
Plugin URI:
|
||||||
|
Description: customize user : output infos on page, on email, and change current user id momentarly
|
||||||
|
Author: hugogogo
|
||||||
|
Version: 0.2.2
|
||||||
|
Author URI:
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
include_once(plugin_dir_path(__FILE__) . '/custer_class.php');
|
||||||
|
include_once(plugin_dir_path(__FILE__) . '/get_user_id.php');
|
||||||
|
include_once(plugin_dir_path(__FILE__) . '/change_id.php');
|
||||||
|
include_once(plugin_dir_path(__FILE__) . '/format_user_infos.php');
|
||||||
|
include_once(plugin_dir_path(__FILE__) . '/user_infos.php');
|
||||||
|
include_once(plugin_dir_path(__FILE__) . '/filter_mail.php');
|
||||||
|
include_once(plugin_dir_path(__FILE__) . '/queries.php');
|
||||||
|
|
||||||
|
include_once(plugin_dir_path(__FILE__) . '/admin_menu.php');
|
||||||
|
include_once(plugin_dir_path(__FILE__) . '/admin_menu_toggle.php');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
62
plugins/custer/custer_class.php
Normal file
62
plugins/custer/custer_class.php
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
namespace CUSTER;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class Custer {
|
||||||
|
|
||||||
|
const USER_INFO_DATE_FORMAT = 'd/m/Y'; // for user_infos.php (date format : https://www.php.net/manual/fr/datetime.format.php)
|
||||||
|
const SLUG_TOOGLE_ADMIN_MENU = ['_name'=>'toogle_admin_menu_url_custer', 'toggle'=>'toggle', 'show'=>'show', 'hide'=>'hide'];
|
||||||
|
const OPTION_TOGGLE_MENU = ['_name'=>'toggle_admin_menu_option_custer', 'show'=>'show', 'hide'=>'hide'];
|
||||||
|
const OPTION_ANCHOR = 'custer_anchor_ids';
|
||||||
|
const QUERIES = [
|
||||||
|
'__author_page_url__',
|
||||||
|
'__user_post_url__',
|
||||||
|
'__admin_email__',
|
||||||
|
'__base_url__',
|
||||||
|
];
|
||||||
|
|
||||||
|
private static $_backup_current_user = null;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* setter and getter for current user backup
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static function set_current_user_backup() {
|
||||||
|
if (self::$_backup_current_user !== null)
|
||||||
|
return;
|
||||||
|
self::$_backup_current_user = get_current_user_id();
|
||||||
|
}
|
||||||
|
public static function get_current_user_backup() {
|
||||||
|
return self::$_backup_current_user;
|
||||||
|
}
|
||||||
|
public static function reset_current_user_backup() {
|
||||||
|
$backup_user = self::$_backup_current_user;
|
||||||
|
if ($backup_user === null) {
|
||||||
|
$backup_user = get_current_user_id();
|
||||||
|
}
|
||||||
|
self::$_backup_current_user = null;
|
||||||
|
return $backup_user;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
140
plugins/custer/filter_mail.php
Normal file
140
plugins/custer/filter_mail.php
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
<?php
|
||||||
|
namespace CUSTER;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* callback to provide the user info corresponding to the $$key_word$$
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function replace_words($matches, $user_id = null) {
|
||||||
|
if ($user_id !== null) {
|
||||||
|
$current_user = get_user_by('id', $user_id);
|
||||||
|
}
|
||||||
|
else if (is_user_logged_in()) {
|
||||||
|
$current_user = wp_get_current_user();
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($current_user === false) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = $matches[1];
|
||||||
|
$result = \CUSTER\format_user_info($query, $user_id);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if result is array, take the first element (not ideal)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (is_array($result)) {
|
||||||
|
$result = reset($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if no match, return $$<query>$$
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (empty($result)) {
|
||||||
|
return $matches[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* filter emails in the form-builder hook, before the wp_mail hook
|
||||||
|
* it receives the id of the user, no need to have the user still logged-in
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
//function filter_email_fb_CIPF($reply_body, $post_array) {
|
||||||
|
// PLGNTLS_class::debug_infos();
|
||||||
|
// $id = $post_array['ID'];
|
||||||
|
// // pattern : anything surrounded by '$$', ex : $$value$$
|
||||||
|
// $pattern = '/\$\$(.*?)\$\$/';
|
||||||
|
//
|
||||||
|
// // inline callback, with 'use' to get the id
|
||||||
|
// $new_body = preg_replace_callback($pattern, function($matches) use ($id) {
|
||||||
|
// return replace_words_CIPF($matches, $id);
|
||||||
|
// }, $reply_body);
|
||||||
|
//
|
||||||
|
// return $new_body;
|
||||||
|
//}
|
||||||
|
//add_filter('df_confirmation_body', __NAMESPACE__.'\filter_email_fb_CIPF', 10, 2); // the receive an email
|
||||||
|
//add_filter('df_notification_body', __NAMESPACE__.'\filter_email_fb_CIPF', 10, 2); // the admin receive a notification
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* filter emails at the final point : the wp_mail hook
|
||||||
|
* it uses a callback that rely on the logged-in user
|
||||||
|
* it will works well most of the time, but it's possible
|
||||||
|
* that a user logged out before the email is sent
|
||||||
|
* or event that a different user has already logged in
|
||||||
|
*/
|
||||||
|
function filter_email_wp($args) {
|
||||||
|
// pattern : anything surrounded by '$$', ex : $$value$$
|
||||||
|
$pattern = '/\$\$(.*?)\$\$/';
|
||||||
|
error_log("email args: " . json_encode($args));
|
||||||
|
/*
|
||||||
|
email args: {
|
||||||
|
"to":"ruknafetri@gufum.com",
|
||||||
|
"subject":"My Custom Email Subject",
|
||||||
|
"message":"Hello, This is a test email sent from my WordPress plugin!",
|
||||||
|
"headers":["Content-Type: text\/html; charset=UTF-8"],
|
||||||
|
"attachments":[]
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
$old_to = $args['to'];
|
||||||
|
$new_to = preg_replace_callback($pattern, __NAMESPACE__.'\replace_words', $old_to);
|
||||||
|
$args['to'] = $new_to;
|
||||||
|
|
||||||
|
$old_subject = $args['subject'];
|
||||||
|
$new_subject = preg_replace_callback($pattern, __NAMESPACE__.'\replace_words', $old_subject);
|
||||||
|
$args['subject'] = $new_subject;
|
||||||
|
|
||||||
|
$old_message = $args['message'];
|
||||||
|
$new_message = preg_replace_callback($pattern, __NAMESPACE__.'\replace_words', $old_message);
|
||||||
|
$args['message'] = $new_message;
|
||||||
|
|
||||||
|
return $args;
|
||||||
|
}
|
||||||
|
add_filter('wp_mail', __NAMESPACE__.'\filter_email_wp', 10, 1);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* add this filter specifically for the new users, since otherwise we would not have their id
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function filter_regitration_email_CIPF($wp_new_user_notification_email, $user, $blogname) {
|
||||||
|
$user_id = $user->ID;
|
||||||
|
$pattern = '/\$\$(.*?)\$\$/';
|
||||||
|
|
||||||
|
$old_body = $wp_new_user_notification_email['message'];
|
||||||
|
$new_body = preg_replace_callback($pattern, function($matches) use ($user_id) {
|
||||||
|
return \CUSTER\replace_words($matches, $user_id);
|
||||||
|
}, $old_body);
|
||||||
|
$wp_new_user_notification_email['message'] = $new_body;
|
||||||
|
|
||||||
|
return $wp_new_user_notification_email;
|
||||||
|
}
|
||||||
|
add_filter('wp_new_user_notification_email', __NAMESPACE__.'\filter_regitration_email_CIPF', 22, 3);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
136
plugins/custer/format_user_infos.php
Normal file
136
plugins/custer/format_user_infos.php
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
<?php
|
||||||
|
namespace CUSTER;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* return the result
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function return_result($output, $if_empty = '') {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if empty, apply options, or default empty string ''
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (empty($output)) {
|
||||||
|
$output = $if_empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if number, output a string
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (is_numeric($output)) {
|
||||||
|
$output = (string)$output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if not scalar, stringify output
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (!is_scalar($output)) {
|
||||||
|
$output = json_encode($output, JSON_UNESCAPED_SLASHES);
|
||||||
|
}
|
||||||
|
|
||||||
|
return esc_html($output);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* format the output
|
||||||
|
* if is acf, use acf default format
|
||||||
|
*/
|
||||||
|
function format_user_info($query, $user_id, $if_empty = '') {
|
||||||
|
$output_date_format = Custer::USER_INFO_DATE_FORMAT;
|
||||||
|
$special_queries = Custer::QUERIES;
|
||||||
|
|
||||||
|
$current_user = get_user_by('id', $user_id);
|
||||||
|
$is_acf = false;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if is special query
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (in_array($query, $special_queries, true)) {
|
||||||
|
$trimmed_query = trim($query, '_');
|
||||||
|
$function_name = __NAMESPACE__.'\find_'.$trimmed_query;
|
||||||
|
$output = $function_name($user_id);
|
||||||
|
return \CUSTER\return_result($output, $if_empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check if it's an acf field
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$acf_id = 'user_'.$user_id;
|
||||||
|
$acf_object = get_field_object($query, $acf_id);
|
||||||
|
if ($acf_object !== false)
|
||||||
|
$is_acf = true;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if is acf, use the acf return format
|
||||||
|
* otherwise, use the default wordpress value
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if ($is_acf) {
|
||||||
|
$output = get_field($query, $acf_id);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$output = $current_user->$query;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* try to extract a single entity
|
||||||
|
* for example : ["string"] -> "string"
|
||||||
|
* or : ["", "string"] -> "string"
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$output = \CUSTER\extract_smallest_entity($output);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if is not acf
|
||||||
|
* check if is a date
|
||||||
|
* and format it
|
||||||
|
* to create a DateTime from a time stamp : https://stackoverflow.com/a/12039058/9497573
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (!$is_acf) {
|
||||||
|
$timestamp = false;
|
||||||
|
if (is_string($output)) {
|
||||||
|
$timestamp = strtotime($output);
|
||||||
|
}
|
||||||
|
if ($timestamp !== false) {
|
||||||
|
//$date = new \DateTime('@' . $timestamp);
|
||||||
|
$date = date_create('@' . $timestamp);
|
||||||
|
$output = $date->format($output_date_format);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check options to format the result
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
return \CUSTER\return_result($output, $if_empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
69
plugins/custer/get_user_id.php
Normal file
69
plugins/custer/get_user_id.php
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
namespace CUSTER;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* get the current author id
|
||||||
|
* return 0 if not found
|
||||||
|
* get id outside loop : https://wordpress.stackexchange.com/q/65548
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function get_author_id() {
|
||||||
|
if (is_author()) {
|
||||||
|
$user_id = get_queried_object_id();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$user_id = get_the_author_meta('ID');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $user_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* get the anker user id
|
||||||
|
* return 0 if not found
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
//function get_anchor_id($anchor_name) {
|
||||||
|
// $option_anchor = Custer::OPTION_ANCHOR;
|
||||||
|
//error_log("anchor_name:");
|
||||||
|
//error_log($anchor_name);
|
||||||
|
//
|
||||||
|
// $anchors = get_option($option_anchor);
|
||||||
|
//error_log("anchors:");
|
||||||
|
//error_log(json_encode($anchors));
|
||||||
|
// if ($anchors === false) {
|
||||||
|
//error_log("anchors === false");
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (isset($anchors[$anchor_name])) {
|
||||||
|
// $user_id = $anchors[$anchor_name];
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (empty($user_id)) {
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return $user_id;
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
85
plugins/custer/queries.php
Normal file
85
plugins/custer/queries.php
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
<?php
|
||||||
|
namespace CUSTER;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 get_queries($user_id, $if_empty) {
|
||||||
|
$special_queries = Custer::QUERIES;
|
||||||
|
|
||||||
|
$queries = array();
|
||||||
|
foreach($special_queries as $query) {
|
||||||
|
$queries[$query] = \CUSTER\format_user_info($query, $user_id, $if_empty);
|
||||||
|
}
|
||||||
|
return $queries;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function find_author_page_url($user_id) {
|
||||||
|
return get_author_posts_url($user_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* find the posts of the user and return the first one
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function find_user_post_url($user_id) {
|
||||||
|
$user_post_url = '';
|
||||||
|
|
||||||
|
$args = array(
|
||||||
|
'post_type' => 'post',
|
||||||
|
'author' => $user_id,
|
||||||
|
'posts_per_page' => 1,
|
||||||
|
);
|
||||||
|
$posts = get_posts($args);
|
||||||
|
|
||||||
|
if (empty($posts)) {
|
||||||
|
$user_post_url = '';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$query = reset($posts);
|
||||||
|
$user_post_url = get_permalink($query->ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $user_post_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function find_admin_email($user_id) {
|
||||||
|
$admin_email = get_option( 'admin_email' );
|
||||||
|
return $admin_email;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function find_base_url($user_id) {
|
||||||
|
$base_url = home_url();
|
||||||
|
return $base_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
195
plugins/custer/user_infos.php
Normal file
195
plugins/custer/user_infos.php
Normal file
@@ -0,0 +1,195 @@
|
|||||||
|
<?php
|
||||||
|
namespace CUSTER;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 extract_smallest_entity($value) {
|
||||||
|
$size = 1;
|
||||||
|
while (is_array($value) && $size === 1) {
|
||||||
|
// https://stackoverflow.com/questions/2216052/how-to-check-whether-an-array-is-empty-using-php#answer-20177855
|
||||||
|
$tmp_array = array_filter($value);
|
||||||
|
$size = count($tmp_array);
|
||||||
|
if ($size === 1) {
|
||||||
|
$value = reset($tmp_array);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
function merge_arrays(...$arrays) {
|
||||||
|
// extract first element
|
||||||
|
$new_array = array_shift($arrays);
|
||||||
|
// then loop through the next arrays
|
||||||
|
foreach ($arrays as $array) {
|
||||||
|
foreach ($array as $key => $value) {
|
||||||
|
$value = \CUSTER\extract_smallest_entity($value);
|
||||||
|
// if key does not already exist, simply add it and the value to new array
|
||||||
|
if (!isset($new_array[$key])) {
|
||||||
|
$new_array[$key] = $value;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// if key already exist, add a new key with a (number) suffix
|
||||||
|
$i = 1;
|
||||||
|
while (isset($new_array[$key.'('.$i.')'])) {
|
||||||
|
++$i;
|
||||||
|
}
|
||||||
|
$new_array[$key.'('.$i.')'] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
uksort($new_array, 'strnatcasecmp');
|
||||||
|
return $new_array;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function output_list_front($array, $user_id, $if_empty) {
|
||||||
|
$output = '<ul>';
|
||||||
|
foreach ($array as $key => $value) {
|
||||||
|
if (str_starts_with($key, '_')) {
|
||||||
|
if (!str_starts_with($key, '__')) {
|
||||||
|
continue ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$value = \CUSTER\format_user_info($key, $user_id, $if_empty);
|
||||||
|
$output .= '<li>';
|
||||||
|
$output .= '<span>';
|
||||||
|
$output .= $key;
|
||||||
|
$output .= ' : ';
|
||||||
|
$output .= $value;
|
||||||
|
$output .= '</span>';
|
||||||
|
$output .= '</li>';
|
||||||
|
}
|
||||||
|
$output .= '</ul>';
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* shortcode to write user info of post author
|
||||||
|
* 0 or 1 argument, usage :
|
||||||
|
* - [custer_user_info] -> list of all availables infos
|
||||||
|
* - [custer_user_info user_email] -> display the email
|
||||||
|
* - [custer_user_info user_email user_login] -> display the email
|
||||||
|
* - [custer_user_info user_email id='logged_in'] -> display the email of the connected user
|
||||||
|
* - [custer_user_info user_email id='author'] -> display the email of the creator of the page/post
|
||||||
|
* - [custer_user_info user_email id='logged_in' important] -> display the email of the connected user, even if surrounded by shortcode 'custer_change_id'
|
||||||
|
* important keyword has no effect if id='author'
|
||||||
|
* - [custer_user_info user_email if_empty="value"] -> display 'value' if the user_email is empty or does not exist
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function current_user_infos($atts) {
|
||||||
|
$is_important = false;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* choose the default id target :
|
||||||
|
* - logged_in
|
||||||
|
* - author
|
||||||
|
*
|
||||||
|
$id_is = 'logged_in';
|
||||||
|
*/
|
||||||
|
$id_is = 'author';
|
||||||
|
$if_empty = '';
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* has parameter 'id' ?
|
||||||
|
* has parameter important ?
|
||||||
|
* has parameter if_empty ?
|
||||||
|
* if yes, handle them and removes them from $atts
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (is_array($atts)) {
|
||||||
|
if (isset($atts['id'])) {
|
||||||
|
$id_is = $atts['id'];
|
||||||
|
unset($atts['id']);
|
||||||
|
}
|
||||||
|
if ($id_is === 'logged_in') {
|
||||||
|
if (in_array('important', $atts)) {
|
||||||
|
$is_important = true;
|
||||||
|
$key = array_search('important', $atts);
|
||||||
|
unset($atts[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isset($atts['if_empty'])) {
|
||||||
|
$if_empty = $atts['if_empty'];
|
||||||
|
unset($atts['if_empty']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* should output all or a specific parameter ?
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$output_all = false;
|
||||||
|
if (empty($atts))
|
||||||
|
$output_all = true;
|
||||||
|
else if (count($atts) === 0)
|
||||||
|
$output_all = true;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* get id according to attributes,
|
||||||
|
* and the atts of the other shortcode 'custer_change_id' if in use
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if ($id_is === 'logged_in') {
|
||||||
|
if ($is_important) {
|
||||||
|
$user_id = Custer::get_current_user_backup();
|
||||||
|
if ($user_id === null)
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ($id_is === 'author') {
|
||||||
|
$user_id = \CUSTER\get_author_id();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* output all the available parameters (for help)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if ($output_all) {
|
||||||
|
$user_properties = (array) get_userdata($user_id)->data;
|
||||||
|
$user_metas = get_user_meta($user_id);
|
||||||
|
$queries = \CUSTER\get_queries($user_id, $if_empty);
|
||||||
|
$user_infos = \CUSTER\merge_arrays($user_metas, $user_properties, $queries);
|
||||||
|
return \CUSTER\output_list_front($user_infos, $user_id, $if_empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* real purpose of this shortcode :
|
||||||
|
* only return the first argument
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (is_array($atts))
|
||||||
|
$query = $atts[0];
|
||||||
|
else if (is_string($atts))
|
||||||
|
$query = $atts;
|
||||||
|
else
|
||||||
|
return '';
|
||||||
|
return \CUSTER\format_user_info($query, $user_id, $if_empty);
|
||||||
|
}
|
||||||
|
add_shortcode('custer_user_info', __NAMESPACE__.'\current_user_infos');
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
0
plugins/fbpatch/css/menu.css
Normal file
0
plugins/fbpatch/css/menu.css
Normal file
31
plugins/fbpatch/fbpatch.php
Normal file
31
plugins/fbpatch/fbpatch.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
Plugin Name: hggg_fbpatch
|
||||||
|
Plugin URI:
|
||||||
|
Description: some patchs for the form_builder plugin's bugs
|
||||||
|
Author: hugogogo
|
||||||
|
Version: 0.2.0
|
||||||
|
Author URI:
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
include_once(plugin_dir_path(__FILE__) . '/php/fbpatch_class.php');
|
||||||
|
|
||||||
|
include_once(plugin_dir_path(__FILE__) . '/menu/admin_menu.php');
|
||||||
|
include_once(plugin_dir_path(__FILE__) . '/menu/admin_menu_toggle.php');
|
||||||
|
include_once(plugin_dir_path(__FILE__) . '/menu/menu_content.php');
|
||||||
|
|
||||||
|
|
||||||
|
\FBPATCH\Fbpatch::init_hook();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
24
plugins/fbpatch/html/menu.html
Normal file
24
plugins/fbpatch/html/menu.html
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<!--
|
||||||
|
|
||||||
|
{"calculations":false,"hide_show":false}
|
||||||
|
|
||||||
|
-->
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.patches_wrapper {
|
||||||
|
margin: 20px 5px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<!-- https://developer.wordpress.org/reference/hooks/admin_post_action/ -->
|
||||||
|
<form method="POST" action="<?php echo admin_url( 'admin-post.php' ); ?>">
|
||||||
|
<input type="hidden" name="action" value="<?php echo $admin_post_patches; ?>">
|
||||||
|
<?php wp_nonce_field($nonce['_action'], $nonce['_name']); ?>
|
||||||
|
<?php foreach($patches as $patch => $options) {?>
|
||||||
|
<div class="patches_wrapper">
|
||||||
|
<input type="checkbox" id="<?php echo $patch; ?>" name="<?php echo $patch; ?>" <?php echo $options['checked'] === true ? "checked" : "" ?> />
|
||||||
|
<label for="<?php echo $patch; ?>"><b><?php echo $options['title']; ?> : </b><?php echo $options['description']; ?></label>
|
||||||
|
</div>
|
||||||
|
<?php } ?>
|
||||||
|
<input type="submit" value="send"/>
|
||||||
|
</form>
|
||||||
@@ -68,4 +68,3 @@ function patch_form_calculation_CIPF() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
patch_form_calculation_CIPF();
|
patch_form_calculation_CIPF();
|
||||||
|
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
let modal_wrapper_CIPF = document.querySelector('#de-fb-modal-wrapper-');
|
let modal_wrapper_CIPF = document.querySelector('#de-fb-modal-wrapper-');
|
||||||
|
|
||||||
// create an observer on first #de-fb-modal-wrapper- to check if child nodes are added
|
// create an observer on first #de-fb-modal-wrapper- to check if child nodes are added
|
||||||
@@ -6,3 +6,4 @@ jQuery.validator.addMethod( 'url', function(value, element) {
|
|||||||
return url(value, element) || url('http://' + value, element);
|
return url(value, element) || url('http://' + value, element);
|
||||||
}, 'Please enter a valid URL'
|
}, 'Please enter a valid URL'
|
||||||
);
|
);
|
||||||
|
|
||||||
38
plugins/fbpatch/menu/admin_menu.php
Normal file
38
plugins/fbpatch/menu/admin_menu.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
namespace FBPATCH;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* creates the plugin menu
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function plugin_menu() {
|
||||||
|
$menu_page_title = 'fbpatch';
|
||||||
|
$menu_title = 'fbpatch';
|
||||||
|
$menu_capability = 'manage_options';
|
||||||
|
$menu_slug = 'fbpatch-plugin';
|
||||||
|
$menu_callback = __NAMESPACE__.'\plugin_content';
|
||||||
|
|
||||||
|
\FBPATCH\toggle_menu($menu_page_title, $menu_title, $menu_capability, $menu_slug, $menu_callback);
|
||||||
|
}
|
||||||
|
add_action('admin_menu', __NAMESPACE__.'\plugin_menu');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
108
plugins/fbpatch/menu/admin_menu_toggle.php
Normal file
108
plugins/fbpatch/menu/admin_menu_toggle.php
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
<?php
|
||||||
|
namespace FBPATCH;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 toggle_menu($menu_page_title, $menu_title, $menu_capability, $menu_slug, $menu_callback) {
|
||||||
|
$toggle_menu = Fbpatch::OPTION_TOGGLE_MENU;
|
||||||
|
|
||||||
|
if (false === get_option($toggle_menu['_name'])) {
|
||||||
|
add_option($toggle_menu['_name'], $toggle_menu['hide'], '', 'no');
|
||||||
|
}
|
||||||
|
|
||||||
|
$toggle = get_option($toggle_menu['_name']);
|
||||||
|
|
||||||
|
if ($toggle === $toggle_menu['hide']) {
|
||||||
|
remove_menu_page($menu_slug);
|
||||||
|
}
|
||||||
|
else if ($toggle === $toggle_menu['show']) {
|
||||||
|
add_menu_page($menu_page_title, $menu_title, $menu_capability, $menu_slug, $menu_callback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* add link under the plugin in the plugins admin page
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function add_link_to_plugin($links) {
|
||||||
|
$slug_toggle = Fbpatch::SLUG_TOOGLE_ADMIN_MENU;
|
||||||
|
$toggle_menu = Fbpatch::OPTION_TOGGLE_MENU;
|
||||||
|
|
||||||
|
$toggle = get_option($toggle_menu['_name']);
|
||||||
|
|
||||||
|
if ($toggle === $toggle_menu['hide']) {
|
||||||
|
$links[] = '<a href="/'.$slug_toggle['_name'].'?'.$slug_toggle['toggle'].'='.$slug_toggle['show'].'">show menu</a>';
|
||||||
|
}
|
||||||
|
else if ($toggle === $toggle_menu['show']) {
|
||||||
|
$links[] = '<a href="/'.$slug_toggle['_name'].'?'.$slug_toggle['toggle'].'='.$slug_toggle['hide'].'">hide menu</a>';
|
||||||
|
}
|
||||||
|
return $links;
|
||||||
|
}
|
||||||
|
add_filter('plugin_action_links_fbpatch/fbpatch.php', __NAMESPACE__.'\add_link_to_plugin');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* handle the toggle menu when url is reached
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function toggle_plugin_menu() {
|
||||||
|
$slug_toggle = Fbpatch::SLUG_TOOGLE_ADMIN_MENU;
|
||||||
|
$toggle_menu = Fbpatch::OPTION_TOGGLE_MENU;
|
||||||
|
|
||||||
|
global $wp;
|
||||||
|
$current_slug = $wp->request;
|
||||||
|
if ($current_slug !== $slug_toggle['_name']) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$show = null;
|
||||||
|
if (!isset($_GET)) {
|
||||||
|
$show = null;
|
||||||
|
}
|
||||||
|
else if (empty($_GET)) {
|
||||||
|
$show = null;
|
||||||
|
}
|
||||||
|
if (!isset($_GET[$slug_toggle['toggle']])) {
|
||||||
|
$show = null;
|
||||||
|
}
|
||||||
|
else if ($_GET[$slug_toggle['toggle']] === $slug_toggle['show']) {
|
||||||
|
$show = true;
|
||||||
|
}
|
||||||
|
else if ($_GET[$slug_toggle['toggle']] === $slug_toggle['hide']) {
|
||||||
|
$show = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($show === true) {
|
||||||
|
update_option($toggle_menu['_name'], $toggle_menu['show']);
|
||||||
|
}
|
||||||
|
else if ($show === false) {
|
||||||
|
update_option($toggle_menu['_name'], $toggle_menu['hide']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$plugins_menu_url = admin_url('plugins.php');
|
||||||
|
wp_redirect($plugins_menu_url, 301);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
add_action('template_redirect', __NAMESPACE__.'\toggle_plugin_menu');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
104
plugins/fbpatch/menu/menu_content.php
Normal file
104
plugins/fbpatch/menu/menu_content.php
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
<?php
|
||||||
|
namespace FBPATCH;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* the construction of the admin menu page
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function plugin_content() {
|
||||||
|
$patches = Fbpatch::get_patches();
|
||||||
|
$nonce = Fbpatch::NONCE;
|
||||||
|
$admin_post_patches = Fbpatch::ADMIN_POST_PATCH_CHOICE;
|
||||||
|
ob_start();
|
||||||
|
include(Fbpatch::root_path() . '/html/menu.html');
|
||||||
|
$html = ob_get_clean();
|
||||||
|
|
||||||
|
echo $html;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* use this hook 'admin_post_{$action}' to receive a form post
|
||||||
|
* https://developer.wordpress.org/reference/hooks/admin_post_action/
|
||||||
|
*
|
||||||
|
* add the url to the action atrtibute of form, and the value of the action in an hidden input
|
||||||
|
* <form method="POST" action="<?php echo admin_url( 'admin-post.php' ); ?>">
|
||||||
|
* <input type="hidden" name="action" value="<?php echo $admin_post_patches; ?>">
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function patches_choice() {
|
||||||
|
$nonce = Fbpatch::NONCE;
|
||||||
|
if (!isset($_POST[$nonce['_name']])) {
|
||||||
|
\FBPATCH\redirect_menu_referer($_POST);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
if (!wp_verify_nonce($_POST[$nonce['_name']], $nonce['_action'])) {
|
||||||
|
\FBPATCH\redirect_menu_referer($_POST);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
[24-Mar-2024 12:24:08 UTC] -> _POST {
|
||||||
|
"action":"add_patches",
|
||||||
|
"nonce_name":"7eeb560dc0",
|
||||||
|
"_wp_http_referer":"\/wp-admin\/admin.php?page=fbpatch-plugin",
|
||||||
|
"hide_show":"on"
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
$pathes_on = array();
|
||||||
|
foreach($_POST as $key => $value) {
|
||||||
|
if ($value !== 'on') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$pathes_on[] = $key;
|
||||||
|
}
|
||||||
|
Fbpatch::set_patches($pathes_on);
|
||||||
|
|
||||||
|
\FBPATCH\redirect_menu_referer($_POST);
|
||||||
|
}
|
||||||
|
add_action('admin_post_'.Fbpatch::ADMIN_POST_PATCH_CHOICE, __NAMESPACE__.'\patches_choice');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function redirect_menu_referer($post) {
|
||||||
|
if (!isset($post)) {
|
||||||
|
wp_redirect(admin_url(), 301);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
if (is_null($post)) {
|
||||||
|
wp_redirect(admin_url(), 301);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
if (empty($post)) {
|
||||||
|
wp_redirect(admin_url(), 301);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($post['_wp_http_referer'])) {
|
||||||
|
wp_redirect(admin_url(), 301);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
wp_redirect(home_url($post['_wp_http_referer']), 301);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
216
plugins/fbpatch/php/fbpatch_class.php
Normal file
216
plugins/fbpatch/php/fbpatch_class.php
Normal file
@@ -0,0 +1,216 @@
|
|||||||
|
<?php
|
||||||
|
namespace FBPATCH;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class Fbpatch {
|
||||||
|
const SLUG_TOOGLE_ADMIN_MENU = ['_name'=>'toogle_admin_menu_url_fbpatch', 'toggle'=>'toggle', 'show'=>'show', 'hide'=>'hide'];
|
||||||
|
const OPTION_TOGGLE_MENU = ['_name'=>'toggle_admin_menu_option_fbpatch', 'show'=>'show', 'hide'=>'hide'];
|
||||||
|
const NONCE = ['_name'=>'nonce_name', '_action'=>'action_name'];
|
||||||
|
const ADMIN_POST_PATCH_CHOICE = 'add_patches';
|
||||||
|
|
||||||
|
/*
|
||||||
|
* get path an url from plugin root
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static function root_path() {
|
||||||
|
return plugin_dir_path(__DIR__);
|
||||||
|
}
|
||||||
|
public static function root_url() {
|
||||||
|
return plugin_dir_url(__DIR__);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ---------------------------------------------------------------------------
|
||||||
|
* OPTIONS
|
||||||
|
* these functions are used to select which patch is applied
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
private static $_patches = [
|
||||||
|
'_name'=>'fbpatch_list_of_patches',
|
||||||
|
'calculations'=>['checked'=>true, 'title'=>'calculations', 'description'=>"afficher le total des calculs dès l'ouverture des formulaires"],
|
||||||
|
'hide_show' =>['checked'=>true, 'title'=>'masquer les offres', 'description'=>"permettre de masquer les offres en editant un formulaire, sans les supprimer"],
|
||||||
|
'modals' =>['checked'=>false, 'title'=>'modals', 'description'=>"permettre plusieurs modals sur une meme page"],
|
||||||
|
'urls' =>['checked'=>false, 'title'=>'urls', 'description'=>"permettre de rentrer des urls sans 'http://'"],
|
||||||
|
];
|
||||||
|
|
||||||
|
private static function set_option_patches() {
|
||||||
|
/*
|
||||||
|
* get the list of patches in option
|
||||||
|
* create option if needed
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$raw_patches_option = get_option(self::$_patches['_name']);
|
||||||
|
if (false === $raw_patches_option) {
|
||||||
|
add_option(self::$_patches['_name'], '', '', 'no');
|
||||||
|
}
|
||||||
|
$patches_option = unserialize($raw_patches_option);
|
||||||
|
if (empty($patches_option)) {
|
||||||
|
$patches_option = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if the option miss patches, add them
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
foreach (self::$_patches as $patch => $data) {
|
||||||
|
if ($patch === '_name') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (isset($patches_option[$patch])) {
|
||||||
|
// updates the title and the description
|
||||||
|
$patches_option[$patch]['title'] = $data['title'];
|
||||||
|
$patches_option[$patch]['description'] = $data['description'];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// add the option
|
||||||
|
$patches_option[$patch] = $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if the option has additional patches, delete them
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
foreach ($patches_option as $patch => $data) {
|
||||||
|
if (isset(self::$_patches[$patch])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
unset($patches_option[$patch]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* change the option list with the update patches
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
ksort($patches_option);
|
||||||
|
$serialize_patches_option = serialize($patches_option);
|
||||||
|
update_option(self::$_patches['_name'], $serialize_patches_option);
|
||||||
|
}
|
||||||
|
public static function get_patches() {
|
||||||
|
self::set_option_patches();
|
||||||
|
$patches = get_option(self::$_patches['_name']);
|
||||||
|
return unserialize($patches);
|
||||||
|
}
|
||||||
|
public static function set_patches($patches_on) {
|
||||||
|
/*
|
||||||
|
* loop through the option list and update occording to the received list
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$raw_patches = get_option(self::$_patches['_name']);
|
||||||
|
$patches_option = unserialize($raw_patches);
|
||||||
|
foreach($patches_option as $patch => $data) {
|
||||||
|
if (in_array($patch, $patches_on)) {
|
||||||
|
$patches_option[$patch]['checked'] = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$patches_option[$patch]['checked'] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* change the option list with the update patches
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
ksort($patches_option);
|
||||||
|
$serialize_patches_option = serialize($patches_option);
|
||||||
|
update_option(self::$_patches['_name'], $serialize_patches_option);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* this function will include the files of the different patches if they are set in the options
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static function init_hook() {
|
||||||
|
$patches = Fbpatch::get_patches();
|
||||||
|
foreach($patches as $patch => $data) {
|
||||||
|
if ($data['checked'] === true) {
|
||||||
|
include_once(self::root_path() . '/php/patches/'.$patch.'.php');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ---------------------------------------------------------------------------
|
||||||
|
* HIDE SHOW
|
||||||
|
* to hide the chosen elements of the form without deleting the data in acf fields
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
private static $_post_id = 0;
|
||||||
|
private static $_has_elements_to_skip = false;
|
||||||
|
private static $_skip_elements = array();
|
||||||
|
|
||||||
|
public static function is_post_id($id) {
|
||||||
|
return self::$_post_id == $id;
|
||||||
|
}
|
||||||
|
public static function is_to_skip($key) {
|
||||||
|
return in_array($key, self::$_skip_elements);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* create an array of the elements to forget
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static function set_post_elements_to_forget($id, $is_to_skip, $skip_array) {
|
||||||
|
self::$_post_id = $id;
|
||||||
|
self::$_has_elements_to_skip = $is_to_skip;
|
||||||
|
self::$_skip_elements = $skip_array;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if there is elements to skip, add the filter
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static function init_skip_hook() {
|
||||||
|
if (true === self::$_has_elements_to_skip) {
|
||||||
|
add_filter("update_post_metadata", __NAMESPACE__.'\filter_elements_to_skip', 10, 5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* after insertion finished, removes filter and reset variables
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static function end_skip_hook() {
|
||||||
|
if (true === self::$_has_elements_to_skip) {
|
||||||
|
remove_filter("update_post_metadata", __NAMESPACE__.'\filter_elements_to_skip');
|
||||||
|
}
|
||||||
|
self::$_post_id = 0;
|
||||||
|
self::$_has_elements_to_skip = false;
|
||||||
|
self::$_skip_elements = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
27
plugins/fbpatch/php/patches/calculations.php
Normal file
27
plugins/fbpatch/php/patches/calculations.php
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
namespace FBPATCH;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 add_form_builder_calculations_patch() {
|
||||||
|
$handle = 'form_builder_calculations_patch';
|
||||||
|
$url = Fbpatch::root_url() . '/js/calculations.js';
|
||||||
|
$dependencies = array('de_fb_calc');
|
||||||
|
$version = null;
|
||||||
|
$defer = true;
|
||||||
|
wp_enqueue_script($handle, $url, $dependencies, $version, $defer);
|
||||||
|
}
|
||||||
|
add_action('wp_enqueue_scripts', __NAMESPACE__.'\add_form_builder_calculations_patch', 22);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
120
plugins/fbpatch/php/patches/hide_show.php
Normal file
120
plugins/fbpatch/php/patches/hide_show.php
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
<?php
|
||||||
|
namespace FBPATCH;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* prevents the meta data to be updated directly in the meta_post_update filter
|
||||||
|
* because nor form_builder nor wp provides filters to modify post_array
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 305 : ../../../../wordpress_docker/volumes/wp_volume/wp-content/plugins/divi-form-builder/includes/DiviFormBuilder.php
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function form_partner_before_process($form_id, $post_array, $form_type) {
|
||||||
|
//error_log("post_array: " . json_encode($post_array));
|
||||||
|
|
||||||
|
if (is_null($post_array) || empty($post_array)) {
|
||||||
|
//nothing to overwrite
|
||||||
|
return Fbpatch::set_post_elements_to_forget(0, false, array());
|
||||||
|
}
|
||||||
|
if (!isset($post_array['meta_input']) || empty($post_array['meta_input'])) {
|
||||||
|
//nothing to overwrite
|
||||||
|
return Fbpatch::set_post_elements_to_forget(0, false, array());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* creating a meta_input list without the prefix
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$raw_meta_input = $post_array['meta_input'];
|
||||||
|
$meta_input = array();
|
||||||
|
$prefix = 'de_fb_';
|
||||||
|
foreach($raw_meta_input as $meta) {
|
||||||
|
if (substr($meta, 0, strlen($prefix)) === $prefix) {
|
||||||
|
$meta_input[] = substr($meta, strlen($prefix));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if there is meta to skip, init the variables
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$to_skip = array();
|
||||||
|
foreach($meta_input as $meta) {
|
||||||
|
if (!isset($post_array[$meta])) {
|
||||||
|
$to_skip[] = $meta;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (empty($to_skip)) {
|
||||||
|
//nothing to overwrite
|
||||||
|
return Fbpatch::set_post_elements_to_forget(0, false, array());
|
||||||
|
}
|
||||||
|
return Fbpatch::set_post_elements_to_forget($post_array["ID"], true, $to_skip);
|
||||||
|
|
||||||
|
}
|
||||||
|
add_action('df_before_process', __NAMESPACE__.'\form_partner_before_process', 10, 3);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 506 : ../../../../wordpress_docker/volumes/wp_volume/wp-content/plugins/divi-form-builder/includes/DiviFormBuilder.php
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function form_partner_before_insert($form_id, $post_array) {
|
||||||
|
//error_log("--form_id : " . json_encode($form_id));
|
||||||
|
//error_log("post_array : " . json_encode($post_array));
|
||||||
|
|
||||||
|
Fbpatch::init_skip_hook();
|
||||||
|
}
|
||||||
|
add_action('df_before_insert_post', __NAMESPACE__.'\form_partner_before_insert', 10, 2);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 235 : ../../../../wordpress_docker/volumes/wp_volume/wp-includes/meta.php
|
||||||
|
* $check = apply_filters( "update_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $prev_value );
|
||||||
|
* "Returning a non-null value will effectively short-circuit the function."
|
||||||
|
* filter is added in Fbpatch class
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function filter_elements_to_skip($null, $object_id, $meta_key, $meta_value, $prev_value) {
|
||||||
|
if (false === Fbpatch::is_post_id($object_id)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (false === Fbpatch::is_to_skip($meta_key)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 558 : ../../../../wordpress_docker/volumes/wp_volume/wp-content/plugins/divi-form-builder/includes/DiviFormBuilder.php
|
||||||
|
* do_action( 'df_after_insert_post', $form_id, $post_id, $post_array );
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function after_form_inserted($form_id, $post_id, $post_array) {
|
||||||
|
//error_log("--form_id : " . json_encode($form_id));
|
||||||
|
//error_log("post_id: " . json_encode($post_id));
|
||||||
|
//error_log("post_array: " . json_encode($post_array));
|
||||||
|
Fbpatch::end_skip_hook();
|
||||||
|
}
|
||||||
|
add_action('df_after_insert_post', __NAMESPACE__.'\after_form_inserted', 10, 3);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
25
plugins/fbpatch/php/patches/modals.php
Normal file
25
plugins/fbpatch/php/patches/modals.php
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
namespace FBPATCH;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 test_modal() {
|
||||||
|
$handle = 'form_builder_modals_patch';
|
||||||
|
$url = Fbpatch::root_url() . '/js/modals.js';
|
||||||
|
$dependencies = array();
|
||||||
|
$version = null;
|
||||||
|
$defer = true;
|
||||||
|
wp_enqueue_script($handle, $url, $dependencies, $version, $defer);
|
||||||
|
}
|
||||||
|
add_shortcode('test_modal', __NAMESPACE__.'\test_modal');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user