199 Commits

Author SHA1 Message Date
asus
15b315b4f3 emails ok, except for shcedule deletion, not yet 2024-04-03 14:53:34 +02:00
asus
d2b2967218 fixed error with automatically adding _name to option 2024-04-03 14:21:33 +02:00
asus
8ac16dc1f4 fixed error in loop option email with _name 2024-04-03 14:07:25 +02:00
asus
913165a056 completed email default messages 2024-04-03 13:58:03 +02:00
asus
a34b9173cf added special query base_url 2024-04-03 13:36:28 +02:00
asus
ffc47a0295 emails in admin menu and updating options seems to work 2024-04-03 13:19:12 +02:00
asus
59b9acc55e fixed small errors in plugin tools for options and menu 2024-04-03 12:37:04 +02:00
asus
1553490444 html presentation of admin menu for emails 2024-04-03 10:31:27 +02:00
asus
1d36093d9f wip emails front admin menu 2024-04-03 00:13:39 +02:00
asus
9abe24b3bb added another state of error in payment if the payment is a success but the treatment has an error 2024-04-02 23:39:27 +02:00
asus
9e903a2ecf defined the emails 2024-04-02 19:31:00 +02:00
asus
2329482aa1 wip filter email subject and sender, in addition to message 2024-04-02 19:12:16 +02:00
asus
7a5b1f63d3 Merge branch 'master' into emails 2024-04-02 18:58:49 +02:00
asus
67bebe4cfc custer query to find admin email 2024-04-02 18:55:59 +02:00
asus
ccb800c203 custer v0.2.2 includes queries in all output 2024-04-02 18:50:56 +02:00
asus
47360119e8 wip creating emails 2024-04-02 17:01:25 +02:00
asus
1f5fff26d6 - updated all occurences of Plgntls:: constantes for Cipf:: const
- update menu to use the new methods
2024-04-02 15:45:54 +02:00
asus
64dc0ffbc5 plgntls :
- added it to cipf plugin
- fixed an error in using _prefix not as static value
2024-04-02 15:44:33 +02:00
asus
bc06828093 wip event schedule 2024-04-02 13:24:22 +02:00
asus
86539d5c14 cipf v0.5.1 2024-04-01 23:33:49 +02:00
asus
b24f0f4210 updated notes 2024-04-01 23:14:42 +02:00
asus
fb146ecda4 - updated states to work for user_id and post_id
- added states for partner page state publish-draft
2024-04-01 23:09:22 +02:00
asus
4d7906be40 prof more checks at profil and when fipf validate transfert 2024-04-01 01:39:38 +02:00
asus
75205571fe cipf added css to hide parts of user profil when fipf see them 2024-03-31 23:38:04 +02:00
asus
0a30bca907 moved css from site to plugin 2024-03-31 20:53:26 +02:00
asus
5d4be76102 xtxpatch v 0.1.1 it works fine 2024-03-31 19:59:20 +02:00
asus
995e230e32 xtxpatch saves the email settings, still need to handle them 2024-03-31 19:25:39 +02:00
asus
b4745ff672 fixed error with option update 2024-03-31 19:09:22 +02:00
asus
3e2174a23f fixed error with unserialization of option 2024-03-31 17:59:17 +02:00
asus
7ad01a51ba more improves in optin gestion in class, automatic handling for basic cases 2024-03-31 17:34:10 +02:00
asus
ca13c5dccb menu and options tools added to plgntls class in plugin xtxpatch 2024-03-31 15:17:53 +02:00
asus
0f554444dd wip trying to get the options working in class 2024-03-31 01:45:25 +01:00
asus
1268dc56e3 wip creating options and menu in plgntls 2024-03-30 21:03:21 +01:00
asus
95c292c626 - added new plugin
- improved the plgntls class for this plugin
2024-03-30 14:57:40 +01:00
asus
2682f3bcd4 more improved in plgntls class to let add_to_front be added multiple times 2024-03-30 11:15:22 +01:00
asus
ade0be87ce updated plgntls :
- renamed PLGNTLS_class -> Plgntls
- changed method 'add_to_front()' to static method
- moved fetch script as inline script, so the plgntls file is single
- improved the way inline script and styles are added
2024-03-29 21:56:12 +01:00
asus
42e8cbc4e9 cipf v 0.4.4 added randomization for posts if < -1 2024-03-27 18:54:57 +01:00
asus
50c05df2b6 small fixes in html and css for admin menu cipf 2024-03-27 17:23:22 +01:00
asus
dd0d4dfbeb added message payments in admin menu 2024-03-27 17:18:14 +01:00
asus
a0018c903b fixed default email options 2024-03-27 14:47:58 +01:00
asus
8b70bea62a fixed error new prof choosing transfert can now access profil 2024-03-27 14:10:10 +01:00
asus
ab6d825724 can choose the email for registration, and wether to send one or not 2024-03-27 13:06:48 +01:00
asus
0808c83589 cipf v 0.4.1 wip trying to filter registration email 2024-03-27 09:38:19 +01:00
asus
0136be4316 wip filter email registration 2024-03-26 22:33:41 +01:00
asus
dbb6dc0d19 edited infos for todo and fabien 2024-03-25 22:14:59 +01:00
asus
27e1e69dfb partner edit button not visible by someone else 2024-03-25 22:11:46 +01:00
asus
90fb5bc0b6 custer v 0.1.6 added special request for post url 2024-03-25 21:42:33 +01:00
asus
44a5d93f77 cipf v0.3.13 paypal credentials now from admin menu 2024-03-25 18:32:03 +01:00
asus
c9f0522ecc wip paypal credentials output in menu, but they dont update yet 2024-03-25 16:21:33 +01:00
asus
4036f4300d updated options to make them not automatically loaded when added 2024-03-25 15:16:19 +01:00
asus
6ec621a20b fbpatch small fixes in options and hide-show 2024-03-25 13:07:12 +01:00
asus
8ebbb8bff2 fbpatch v 0.1.3 2024-03-25 11:17:16 +01:00
asus
f055a10d1c hide show post elements works 2024-03-25 11:13:16 +01:00
asus
85e5a34e42 wip first strategy to overwrite the formbuilder post update is a dead end 2024-03-24 23:43:06 +01:00
asus
569f4524d3 moved all aptches from cipf plugin to fbpatch 2024-03-24 17:06:10 +01:00
asus
1745d8754d adding patchs files according to form in menu 2024-03-24 16:16:55 +01:00
asus
28a1f7922d fixed error in fetch 2024-03-24 16:06:47 +01:00
asus
1856943bc9 wip adding patchs conditionnaly 2024-03-24 15:14:53 +01:00
asus
f882caf850 option list update with form 2024-03-24 15:05:00 +01:00
asus
1415fc14a2 wip patchs appears with informations, but are not yet updated 2024-03-24 13:23:00 +01:00
asus
94dbe05f87 wip patches added to options 2024-03-24 12:37:38 +01:00
asus
5c93938b53 wip nonce works now 2024-03-24 11:12:11 +01:00
asus
b05b5f375e wip nonce actually dont work 2024-03-23 23:51:35 +01:00
asus
46885fe10e wip the nonce for the menu works 2024-03-23 22:14:16 +01:00
asus
aae40be620 wip menu can now receive form with rest api, but no nonce 2024-03-23 18:25:43 +01:00
asus
b6d1d63b93 wip adding fbpatch plugin 2024-03-23 15:24:14 +01:00
asus
1fe5379845 v 0.3.12
- update date when transfert success
- role partner at creation ok
2024-03-22 19:10:35 +01:00
asus
cb9042a746 updated notes 2024-03-21 19:27:45 +01:00
asus
ab9afab160 wip partner register role : found how to add hidden fields 2024-03-21 19:26:32 +01:00
asus
66fbbfd586 small improvements in handling prof states :
- card date validation now uses direct card duration, not a parameter
- checker for both types of transfert valid and invalid
- mv checks for transfert and date expiration in specific functions
2024-03-21 16:10:07 +01:00
asus
782ae1b1d8 added paypal diego live credentials 2024-03-21 16:09:44 +01:00
asus
fcd7aae681 better handle transfert validation 2024-03-20 21:10:56 +01:00
asus
dc77784fef changed all optionnal user_id in first parameters to last parameters 2024-03-20 20:02:03 +01:00
asus
68905de5d5 fixed error when fipf see account it changes status accordgin to its own values 2024-03-20 19:31:54 +01:00
asus
c973af3131 v 0.3.11 :
- fixed error in creating card number
- fixed error in creating first date limit
- fixed error dont put card in valid after success payment
2024-03-20 18:58:46 +01:00
asus
b57fb6156c added important to css for display state, i am going to hell 2024-03-20 17:44:42 +01:00
asus
c69df03c75 update making card renew after paiement only if it was new 2024-03-20 17:07:41 +01:00
asus
8933b3d321 debug mode false 2024-03-20 17:06:44 +01:00
asus
abd9717fe0 fixed error in creating card number 2024-03-20 17:04:21 +01:00
asus
578502838e rollback to not calculating price 2024-03-20 15:29:34 +01:00
asus
b93a3298d2 new profs redirects to command 2024-03-20 14:44:19 +01:00
asus
0717a7d9e4 v 0.3.10 admin can validate payment from front 2024-03-20 11:42:22 +01:00
asus
58f287f00f fixed redirection preventing to edit in divi builder mode 2024-03-20 11:24:40 +01:00
asus
4eee697078 first step in making api keys modifiable in admin : using getter and setter instead of const 2024-03-20 10:10:48 +01:00
asus
f9788fa96e v 0.3.9 profs are mostly ok i suppose, didn't checked all situations 2024-03-20 01:58:37 +01:00
asus
0ab26c0b31 - hide admin bar for front user
- admin page redirects non admin users
2024-03-20 01:54:49 +01:00
asus
227d07fe46 fixed pbm find author id ouside loop 2024-03-20 01:54:22 +01:00
asus
33adb095e5 - creates redirect-home function
- restrict prof form to profs
- restrict paypal page for prof only
2024-03-20 01:02:46 +01:00
asus
0127d8db4c - most prof states shoud be ok
- redirection partner page creation
- user ids on checks states
- reset cgv
- restrict prof profil page
2024-03-20 00:26:39 +01:00
asus
61063cabd9 partner redirection to page creation 2024-03-19 23:48:40 +01:00
asus
1248c2339d fixed error in prof state for renew card 2024-03-19 22:47:00 +01:00
asus
d264e6c321 wip cahngin states 2024-03-19 22:06:17 +01:00
asus
4de26b79fc updated infos about states 2024-03-19 20:50:35 +01:00
asus
58d02708b9 updated acf find non init field value with new technique to init with temp value first 2024-03-19 20:15:26 +01:00
asus
cbfbfabd18 made the plugin dont redeclare font variable if used two times 2024-03-19 18:44:53 +01:00
asus
f7c805f22b v 0.3.4 states are now handled with specific functions for setting, getting, and adding css 2024-03-19 16:28:15 +01:00
asus
db1d16bd91 created css files for states displays 2024-03-19 15:59:16 +01:00
asus
2f0b15dd6f changed acf field access from _name to _key 2024-03-19 15:05:33 +01:00
asus
aad98c5188 most account states updating are working 2024-03-19 13:06:16 +01:00
asus
5010b70d79 created functions to handle all state changes 2024-03-19 12:37:16 +01:00
asus
f221e43807 added dates functions for prof card 2024-03-19 08:58:59 +01:00
asus
5e7ca4f0f1 update notes 2024-03-19 07:30:59 +01:00
asus
0b8b479584 wip account states 2024-03-19 07:28:17 +01:00
asus
e1f4799150 abandonned price calculation at payment time because of pbm with formbuilder 2024-03-19 07:27:37 +01:00
asus
9cda6f13bd wip registration partner role with xootix hook and hiden fields 2024-03-19 07:24:53 +01:00
asus
cabee4db30 v 0.1.4.2 temporary deactivate anchors 2024-03-19 07:11:45 +01:00
asus
ba1d3e3707 v 0.1.4.1 correction new DateTime in shortcode, conflict with namespace 2024-03-19 07:11:04 +01:00
asus
c1b687064f updated notes 2024-03-18 13:30:17 +01:00
asus
5be80d1566 v 0.3.3 partner registration detected with slug using options and without referer 2024-03-18 13:28:48 +01:00
asus
98dfb17bf4 change author id works for prof profil and prof form 2024-03-18 12:23:27 +01:00
asus
82b6593dd9 - v 0.3.2 : can hide or show admin menu 2024-03-17 23:00:39 +01:00
asus
fcb15c97d1 v 0.3.1
- reset cgv
- price works with all acf returns for radio buttons
- redirection works
2024-03-17 18:16:28 +01:00
asus
874736fd8a redirections whould work now 2024-03-17 17:59:48 +01:00
asus
c39a656ab1 price calculation now works whatever acf return is set 2024-03-17 17:59:27 +01:00
asus
a245bd4350 - removed custom user function and put it in custer
- changed main file for cipf instead of fipfcard
- reset some fields after prof form validation
2024-03-17 15:28:08 +01:00
asus
eaa45c4ed1 custer format output works with numbers 2024-03-17 14:52:42 +01:00
asus
70d8998a3f custer : changed namespace, now all function use it 2024-03-17 14:06:25 +01:00
asus
fc41f7d36b cipf v 0.2.9 : moved shortcodes change_id and user_info to another plugin, custer 2024-03-17 02:29:31 +01:00
asus
f9b245c39c custer v 0.1.1 : now fully working 2024-03-17 02:28:27 +01:00
asus
6ad1fb5137 created plugin custer, and removed shortcodes change_id and user_infos from cipf plugin 2024-03-17 02:27:28 +01:00
asus
494943e4f7 v0.2.8 wip can force the id of a user for a portion of page with shortcode 2024-03-15 13:50:27 +01:00
asus
6c7b269052 tried a fix on redirection without real page, by using template-redirection hook instead of init 2024-03-15 09:18:39 +01:00
asus
9ebce56025 wip trying to force the acf id that formbuilder will use 2024-03-14 23:28:37 +01:00
asus
70888d384c fixed dates format error 2024-03-14 18:35:21 +01:00
asus
0d6d475ce0 v 0.2.6 2024-03-14 15:27:52 +01:00
asus
4c81476336 changed profil redirection so it does not need a real page anymore 2024-03-14 15:07:50 +01:00
asus
30c84135ef Merge branch 'debug_routes' 2024-03-14 13:48:37 +01:00
asus
d0bfe90715 nop it wasn't my plugin's fault 2024-03-14 13:48:19 +01:00
asus
e14acfb739 wip i broke everyhting :p 2024-03-14 13:10:05 +01:00
asus
4220c34c7f updated notes 2024-03-14 12:32:35 +01:00
asus
76f2e8ba00 wip debug redirections 2024-03-14 12:31:31 +01:00
asus
ecc072e25b added redirection without need of a page, use it for paypal success or failure message already 2024-03-14 10:29:02 +01:00
asus
2f4a5bb9ef wip handle custom form submit 2024-03-14 01:18:31 +01:00
asus
12de8ee12f some improvments on shortcode user_info, to output the right secure string in most cases 2024-03-13 14:57:01 +01:00
asus
10ca070d81 - wip create role at registration
- upgraded shortcode user_infos to output acf format
2024-03-13 13:28:14 +01:00
asus
f6e092f67d - moved reset field function outside renew_card file
- created a patch for formbuilder calculation pbm
2024-03-12 21:53:32 +01:00
asus
38f9b0ba72 - in plgntls transformed process to add fetch script even if list of srcs is empty
- created a patch for form builder calculation
2024-03-12 19:54:18 +01:00
asus
591add448f wip check offres for newsletter 2024-03-11 23:20:38 +01:00
asus
046b31579c changed all role occurences by a const 2024-03-11 00:02:55 +01:00
asus
4f4bfd1c88 card number id created 2024-03-10 23:12:20 +01:00
asus
c1944dbc39 added info in class about path construction 2024-03-10 22:53:15 +01:00
asus
1021d9bf71 - added a default css file to include to have a first handle
- cahnged get_path/url to root_path/url
- changed path setup -> now automatic from inside plugin
2024-03-10 22:37:38 +01:00
asus
9ee35b23bc - renew state : removed
- payment state : in acf
2024-03-10 14:51:47 +01:00
asus
b457ed119e changed meta field payment_status for acf field 2024-03-10 14:12:24 +01:00
asus
faefa98114 - added debug function
- fixed issues in acf fields use
2024-03-10 11:13:44 +01:00
asus
f3a9be5a89 wip upgrade and clean payment process 2024-03-09 22:03:22 +01:00
asus
fc3a205359 updates acf fields const values in class to avoid errors 2024-03-08 17:57:04 +01:00
asus
789a361871 moved all const in class 2024-03-08 09:23:51 +01:00
asus
022468c096 moved and updated reset fields into rebew file 2024-03-07 23:48:01 +01:00
asus
909a34cd37 renew page message are working 2024-03-07 23:27:20 +01:00
asus
9b5e44dfd3 changed plugin name to cipf 2024-03-07 22:35:39 +01:00
asus
be79310404 changed all instances of fipf to cipf 2024-03-07 22:32:50 +01:00
asus
f870f77a2c wip prof check page now handle the success message on paiement 2024-03-07 21:34:48 +01:00
asus
5e28bf3059 update payment validation by changing prof to active 2024-03-07 19:21:11 +01:00
asus
afd34e5296 updated som error in filter email for special query author page 2024-03-07 19:08:03 +01:00
asus
4916defcaa updated filter email to filter the author page special keyword 2024-03-07 19:03:42 +01:00
asus
31c3ed55f4 wip author page checks, waiting page redirection working 2024-03-07 17:50:45 +01:00
asus
d65af4cd43 - wip filter page prof
- upgraded user info shortcode to default behavior on author page
2024-03-07 17:05:55 +01:00
asus
b244b59deb small correction in user info 2024-03-07 15:13:16 +01:00
asus
60f46265c2 updated user info shortcode to output author page and format date 2024-03-07 14:51:10 +01:00
asus
b8fbd84d53 - payment : first date error corrected
- payment : added httpErrorException
- payment : error handling wip
- profil page restriction gives access to admin and editor
2024-03-07 10:26:11 +01:00
asus
2fb1ec35aa - improved payement paypal for date and other things 2024-03-06 23:44:46 +01:00
asus
1661f16aff wip payment kind of works with bugs 2024-03-06 13:53:47 +01:00
asus
917d51a097 - wip payment
- already solved success and failure messages and redirection
  - solved increase date multiple times
- users redirection works if error AND partner to posts instead of project
2024-03-05 17:22:11 +01:00
asus
620aa9329b added check for logged in user in filter email 2024-03-05 10:44:36 +01:00
asus
39c9f492dc upgraded email filter to filter also wp hook 2024-03-05 09:55:54 +01:00
asus
63cc1f28c0 created a new function to filter emails 2024-03-05 00:10:53 +01:00
asus
44e122d415 renamed formbuilder patch files 2024-03-04 08:52:18 +01:00
asus
cf9a020162 - added a reinit function for acf fields after form validation
- added a plugin version of the modal patch for form builder
2024-03-03 21:48:39 +01:00
asus
483c02a4c6 small improvement in print user infos list 2024-03-03 10:39:34 +01:00
asus
cae80d7d24 shortcode to get user infos 2024-03-03 01:37:10 +01:00
asus
8862bab1bd some more little codes for restrictions and registrations 2024-03-02 21:43:43 +01:00
asus
7738ad1863 - added role at registration with xootix
- cleaned folder
2024-03-02 16:14:36 +01:00
asus
8aeef1dca8 added inline code to plugin tools 2024-03-01 17:21:03 +01:00
asus
bd30c97194 - tests on editing author page with acf fields
- some reflexions on registrations
2024-02-29 23:45:02 +01:00
asus
6e88bba879 wip trying to modify html before it is rendered 2024-02-29 01:04:41 +01:00
asus
2ce603e644 now we can add attributes to js files using the tools class 2024-02-27 15:23:07 +01:00
asus
7a8c0750c5 wip adding attributes, works with filter wp-script-attributes 2024-02-27 11:51:46 +01:00
asus
81f3f8a7e7 wip trying to create better options to include scripts with attributes 2024-02-27 01:54:46 +01:00
asus
0177531924 - forget old ajax wp, now use fetch wp
- trying js files without imports
2024-02-26 13:18:19 +01:00
asus
5794e4cafe update private notes 2024-02-25 21:03:58 +01:00
asus
b839bf7f66 payment update acf fields allright 2024-02-25 18:11:33 +01:00
asus
ec18dc60b4 prefixed all paypal related fonctions with fipf 2024-02-25 15:00:21 +01:00
asus
4e094889c7 wip cron job to delete order id, but will deal with that later 2024-02-25 14:43:53 +01:00
asus
3d9b9bac9e wip track payment to user 2024-02-25 11:02:47 +01:00
asus
01187a8450 wip connecting user with payment 2024-02-25 01:46:33 +01:00
asus
1464562379 retrieving user that makes the purchase with nonce ok 2024-02-24 17:40:33 +01:00
asus
61b3f9f2f5 PAYPAL WORKING 2024-02-24 16:57:31 +01:00
asus
745f5ebf91 created routes, but json parse error ate the end of transaction 2024-02-24 01:19:39 +01:00
asus
38260912cd try wordpress rest api instead of ajax 2024-02-23 23:43:23 +01:00
asus
0f15b67e8b wip route api_order 2024-02-23 21:03:34 +01:00
asus
bebb346ff9 better file organisation 2024-02-23 19:49:56 +01:00
asus
b7685cbbc1 - struggled to make ajax works, but now is ok
- starting to make serverside works
2024-02-23 19:36:03 +01:00
asus
7cfa2e6351 - added capacity in plugin tool to take urls
- test front end integration ok
2024-02-23 10:52:02 +01:00
asus
fea195638b sdk call works now, just the begining 2024-02-22 23:44:22 +01:00
asus
45532c497d wip paypal with sdk not working 2024-02-22 20:30:01 +01:00
asus
1046390f59 small improvement in modals with diviengine-form-builder 2024-02-22 11:50:01 +01:00
asus
1262aeb706 wip paypal tests 2024-02-21 23:58:53 +01:00
asus
6158f738a2 submodules ipdates 2024-02-20 23:44:10 +01:00
115 changed files with 9287 additions and 4194 deletions

View File

@@ -1,4 +1,4 @@
# fipf 2024 # cipf 2024
- this project uses submodules recursively, so after cloning you need to do : - this project uses submodules recursively, so after cloning you need to do :
`git submodule update --init --recursive` `git submodule update --init --recursive`

View 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';
}
?>

View File

@@ -0,0 +1,3 @@
[class*='cipf_display_'] {
display: none !important;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View 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; }

View 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; }

View File

@@ -0,0 +1,34 @@
/*
* [/] Options personnelles,
* [/] À propos du compte,
* [/] Mots de passe dapplication,
* [/] 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;
}

View File

@@ -0,0 +1,6 @@
#mytext {
border: 1px solid blue;
}
#mytext_2 {
border: 1px solid green;
}

View File

@@ -0,0 +1,3 @@
.partenaire_propre_page_cipf {
display: none;
}

View File

@@ -0,0 +1,3 @@
div.partenaire_propre_page_cipf {
display: block;
}

View 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>

View File

@@ -0,0 +1,2 @@
<div id="paypal-button-container"></div>
<p id="result-message"></p>

View File

@@ -0,0 +1,61 @@
import { resultMessage } from './result_message.js';
/*
* @see https://developer.paypal.com/docs/checkout/standard/integrate/#link-integratebackend
*
*/
export async function createOrder() {
try {
const response = await PLGNTLS_fetch('/cipf_plugin/api/v1/orders', {
method: "POST",
headers: {
"Content-Type": "application/json",
},
});
const orderData = await response.json();
/*
* is it necessary since the error is catched according to the presence of id ?
* -> i think yes, because we want to know the type of http error, right ?
* -> actually the http error code will be shown in the console anyway, so...
*
if (!response.ok) {
throw new Error('Network response was not ok : ' + orderData.data.status + ' message : ' + orderData.message);
}
*/
if (orderData.id) {
return orderData.id;
}
else { // throw an error
const errorDetail = orderData?.details?.[0];
const errorMessage = errorDetail
? `${errorDetail.issue} ${errorDetail.description} (${orderData.debug_id})`
: JSON.stringify(orderData);
throw new Error(errorMessage);
}
} catch (error) {
console.error(error);
resultMessage(`Could not initiate PayPal Checkout...<br><br>${error}`);
}
}
/**
* @see https://developer.paypal.com/demo/checkout/#/pattern/server
*
// Call your server to set up the transaction
function createOrder(data, actions) {
const fetch_create_url = PLGNTLS_data.fetch_url + "/cipf_plugin/api/v1/orders";
console.log("fetch_create_url:", fetch_create_url);
return fetch(fetch_create_url, {
method: 'post'
}).then(function(res) {
return res.json();
}).then(function(orderData) {
return orderData.id;
});
},
*/

View File

@@ -0,0 +1,62 @@
import { resultMessage } from './result_message.js';
/*
* @see https://developer.paypal.com/docs/checkout/standard/integrate/#link-integratebackend
*
*/
export async function onApprove(data, actions) {
try {
const fetch_approve_url = PLGNTLS_data.fetch_url + "/cipf_plugin/api/v1/orders/" + data.orderID + "/capture";
const response = await PLGNTLS_fetch('/cipf_plugin/api/v1/orders/' + data.orderID + '/capture', {
method: "POST",
headers: {
"Content-Type": "application/json",
},
});
const orderData = await response.json();
// Three cases to handle:
// (1) Recoverable INSTRUMENT_DECLINED -> call actions.restart()
// (2) Other non-recoverable errors -> Show a failure message
// (3) Successful transaction -> Show confirmation or thank you message
// + hugogogo treatment error but success order
const errorDetail = orderData?.details?.[0];
if (errorDetail?.issue === "INSTRUMENT_DECLINED") {
// (1) Recoverable INSTRUMENT_DECLINED -> call actions.restart()
// recoverable state, per https://developer.paypal.com/docs/checkout/standard/customize/handle-funding-failures/
return actions.restart();
}
else if (errorDetail) {
// (2) Other non-recoverable errors -> Show a failure message
throw new Error(`${errorDetail.description} (${orderData.debug_id})`);
}
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));
}
}
else {
// (3) Successful transaction -> Show confirmation or thank you message
// Or go to another URL: actions.redirect('thank_you.html');
const transaction =
orderData?.purchase_units?.[0]?.payments?.captures?.[0] ||
orderData?.purchase_units?.[0]?.payments?.authorizations?.[0];
console.log("Capture result",orderData);
resultMessage(PLGNTLS_data.paypal_message_success);
actions.redirect(PLGNTLS_data.paypal_redirection_success);
}
}
catch (error) {
console.error(error);
resultMessage(PLGNTLS_data.paypal_message_failure);
actions.redirect(PLGNTLS_data.paypal_redirection_failure);
}
}

View File

@@ -0,0 +1,56 @@
import { createOrder } from './create_order.js';
import { onApprove } from './on_approve.js';
window.paypal.Buttons({
/*
style: {
layout: 'vertical',
color: 'blue',
shape: 'rect',
label: 'paypal',
},
*/
createOrder: createOrder,
onApprove: onApprove,
})
.render("#paypal-button-container");
/**
* customize card fields
* from : https://developer.paypal.com/docs/checkout/advanced/integrate#link-addpaypalbuttonsandcardfields
*
// Create the Card Fields Component and define callbacks
const cardField = paypal.CardFields({
createOrder: createOrder,
onApprove: onApprove,
});
// Render each field after checking for eligibility
if (cardField.isEligible()) {
const nameField = cardField.NameField();
nameField.render("#card-name-field-container");
const numberField = cardField.NumberField();
numberField.render("#card-number-field-container");
const cvvField = cardField.CVVField();
cvvField.render("#card-cvv-field-container");
const expiryField = cardField.ExpiryField();
expiryField.render("#card-expiry-field-container");
// Add click listener to submit button and call the submit function on the CardField component
document
.getElementById("card-field-submit-button")
.addEventListener("click", () => {
cardField.submit().then(() => {
// submit successful
});
});
}
*/

View File

@@ -0,0 +1,9 @@
// Example function to show a result to the user. Your site's UI library can be used instead.
//function resultMessage(message) {
export function resultMessage(message) {
const buttons = document.querySelector("#paypal-button-container");
const container = document.querySelector("#result-message");
buttons.style.display = 'none';
container.innerHTML = message;
}

View 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);
?>

View 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;
}
?>

View 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');
?>

View 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);
}
?>

View 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'=>"",
],
*/
?>

View File

@@ -0,0 +1,44 @@
<?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 deconnexion
* 1. il faut creer un menu personalisé dans Apparence > Menus
* 2. dans le code ci-dessous, changer la valeur de $menu_title pour correspondre au titre du menu
* 3. et si besoin changer la valeur de $menu_redirect pour choisir la page de redirection :
* - si laissée vide, la redirection se fera sur la page de connexion de wordpress
* - avec $current_url la redirection se fera sur la page actuelle
* - avec $base_url on redirige vers la page d'accueil du site (l'url sans chemin supplementaire)
* cette variable $base_url peut etre utilisee pour construire une autre url :
* - $menu_redirect = $base_url -> https://le_site_actuel.com/
* - $menu_redirect = $base_url . 'contact' -> https://le_site_actuel.com/contact
* - $menu_redirect = $current_url -> https://le_site_actuel.com/la_meme_page
* - $menu_redirect = 'www.un_autre_site.net/contact' -> https://www.un_autre_site.net/contact
*/
function change_menu_logout($items){
Plgntls::debug_infos();
$menu_title = 'special logout';
// quelques urls utiles :
$base_url = home_url();
$current_url = home_url( $_SERVER['REQUEST_URI'] );
$menu_redirect = '';
foreach($items as $item){
if( $item->title === $menu_title){
$item->url = wp_nonce_url( wp_logout_url( $menu_redirect ), 'log-out' );
}
}
return $items;
}
add_filter('wp_nav_menu_objects', 'change_menu_logout');
?>

View 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');
?>

View 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);
?>

View 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);
?>

View 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'];
}
?>

View 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');
?>

View File

@@ -0,0 +1,27 @@
<?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::root_path() . '/php/utils/http_errors.php');
include_once(Plgntls::root_path() . '/php/paypal/route_api_utils.php');
include_once(Plgntls::root_path() . '/php/paypal/user_can_pay.php');
include_once(Plgntls::root_path() . '/php/paypal/update_user_payment.php');
include_once(Plgntls::root_path() . '/php/paypal/shortcode.php');
include_once(Plgntls::root_path() . '/php/paypal/route_api_orders.php');
include_once(Plgntls::root_path() . '/php/paypal/route_api_orders_capture.php');
include_once(Plgntls::root_path() . '/php/paypal/routes.php');
include_once(Plgntls::root_path() . '/php/paypal/payment_page.php');
?>

View File

@@ -0,0 +1,149 @@
<?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!');
}
/*
* this function runs before the paiement, it initiate the order
* @see https://developer.paypal.com/docs/checkout/standard/integrate/#link-integratebackend
*
* in this function and the insides functions,
* explicit errors are thrown with HttpException,
* otherwise it's an unexpected error to catch with Exception
*
*/
function handle_orders_request_CIPF($request_data) {
Plgntls::debug_infos();
// declaring outside the try..catch scope
$order_response = array();
/*
* - check if user can pay, according to conditions
* - process the order and get the response
* if it fails here : the order was not created
*
*/
try {
$can_pay = check_can_pay_CIPF();
if (is_wp_error($can_pay))
throw new HttpException('not allowed to pay : ' . $can_pay->get_error_message(), 403);
$order_response = create_order_CIPF();
$json_response = $order_response['json_response'];
$http_status_code = $order_response['http_status_code'];
}
catch (HttpException $error) {
$status_code = $error->getStatusCode();
$message = 'Failed to create order in server :' . $error->getMessage();
return new WP_REST_Response($message, $status_code);
}
catch (Exception $error) {
$message = 'Failed to create order in server :' . $error->getMessage();
return new WP_REST_Response($message, 500);
}
/*
* - add infos of the initiated order into user profil
* - return the created order to the front
* if it fails here : the order was created in paypal
* but a pbm occured in treating it with the user
*
*/
try {
update_user_pre_order_CIPF($json_response, 'start');
/*
* https://developer.wordpress.org/reference/classes/wp_rest_response/
* extends from https://developer.wordpress.org/reference/classes/wp_http_response/
* __construct( $data = null, $status = 200, $headers = array() )
*
*/
return new WP_REST_Response($json_response, $http_status_code);
}
catch (HttpException $error) {
$status_code = $error->getStatusCode();
$message = 'Order created, but failed in treatment :' . $error->getMessage();
return new WP_REST_Response($message, $status_code);
}
catch (Exception $error) {
$message = 'Order created, but failed in treatment :' . $error->getMessage();
return new WP_REST_Response($message, 500);
}
}
/*
* Create an order to start the transaction.
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_create
*
*/
function create_order_CIPF() {
Plgntls::debug_infos();
$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();
$user_id = get_current_user_id();
$acf_id = 'user_' . $user_id;
$price = get_field($acf_card_price_total['_name'], $acf_id);
// $price = 0.01;
$url = $paypal_api_base_url . '/v2/checkout/orders';
$payload = array(
'intent' => "CAPTURE",
'purchase_units' => array(
array(
'amount' => array(
'currency_code' => "EUR",
'value' => $price,
),
),
),
);
$headers = array(
"Content-Type: application/json",
"Authorization: Bearer " . $access_token
// Uncomment one of these to force an error for negative testing (in sandbox mode only). Documentation:
// https://developer.paypal.com/tools/sandbox/negative-testing/request-headers/
// "PayPal-Mock-Response": '{"mock_application_codes": "MISSING_REQUIRED_PARAMETER"}'
// "PayPal-Mock-Response": '{"mock_application_codes": "PERMISSION_DENIED"}'
// "PayPal-Mock-Response": '{"mock_application_codes": "INTERNAL_SERVER_ERROR"}'
);
// Initialize cURL session
$ch = curl_init();
// Set cURL options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// Execute cURL session and get the response
$response_json = curl_exec($ch);
// in utils
$response = handle_json_response_CIPF($response_json, $ch);
// Close cURL session
curl_close($ch);
return $response;
};
?>

View File

@@ -0,0 +1,114 @@
<?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_orders_capture_request_CIPF($request) {
Plgntls::debug_infos();
$order_id = $request['orderID'];
// declaring outside the try..catch scope
$response_json = array();
/*
* ask paypal about the finished order
*
*/
try {
$response_json = capture_order_cipf($order_id);
$http_status_code = $response_json['http_status_code'];
$json_response = $response_json['json_response'];
}
catch (HttpException $error) {
$status_code = $error->getStatusCode();
$message = 'Failed to capture order in server :' . $error->getMessage();
return new WP_REST_Response($message, $status_code);
}
catch (Exception $error) {
$message = 'Failed to capture order in server : ' . $error->getMessage();
return new WP_REST_Response($message, 500);
}
/*
* update the client situation
* and return the response of paypal
*
* capture status : https://developer.paypal.com/docs/api/orders/v2/#definition-order_status
* - COMPLETED
* - DECLINED
* - PARTIALLY_REFUNDED
* - PENDING
* - REFUNDED
* - FAILED
*
*/
try {
update_user_post_capture_CIPF($json_response, 'end');
return new WP_REST_Response($json_response, $http_status_code);
}
catch (HttpException $error) {
$status_code = $error->getStatusCode();
$message = array('ERROR_TREATMENT'=>true, 'message'=>'Failed to handle order after capture in server: ' . $error->getMessage());
return new WP_REST_Response($message, $status_code);
}
catch (Exception $error) {
$message = array('ERROR_TREATMENT'=>true, 'message'=>'Failed to handle order after capture in server: ' . $error->getMessage());
return new WP_REST_Response($message, 500);
}
}
/**
* Capture payment for the created order to complete the transaction.
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_capture
*/
function capture_order_CIPF($order_id) {
Plgntls::debug_infos();
$paypal_api_base_url = get_paypal_api_base_url_CIPF();
$access_token = generate_access_token_CIPF();
$url = $paypal_api_base_url . '/v2/checkout/orders/' . $order_id . '/capture';
$headers = array(
"Content-Type: application/json",
"Authorization: Bearer " . $access_token
// Uncomment one of these to force an error for negative testing (in sandbox mode only). Documentation:
// https://developer.paypal.com/tools/sandbox/negative-testing/request-headers/
// 'PayPal-Mock-Response: {"mock_application_codes": "INSTRUMENT_DECLINED"}',
// 'PayPal-Mock-Response: {"mock_application_codes": "TRANSACTION_REFUSED"}',
// 'PayPal-Mock-Response: {"mock_application_codes": "INTERNAL_SERVER_ERROR"}'
);
// Initialize cURL session
$ch = curl_init();
// Set cURL options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute cURL session and get the response
$response_json = curl_exec($ch);
// in utils
$response = handle_json_response_CIPF($response_json, $ch);
// Close cURL session
curl_close($ch);
return $response;
};
?>

View File

@@ -0,0 +1,129 @@
<?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!');
}
/*
* @see https://developer.paypal.com/docs/checkout/standard/integrate/#link-integratebackend
*
*/
function handle_json_response_CIPF($response, $ch) {
Plgntls::debug_infos();
if ($response === false)
throw new HttpException('cURL error: ' . curl_error($ch), 502);
// Decode JSON response
$json_response = json_decode($response);
// https://stackoverflow.com/questions/2348152/detect-bad-json-data-in-php-json-decode
if ($json_response === null && json_last_error() !== JSON_ERROR_NONE) {
throw new HttpException('JSON decoding error: ' . json_last_error_msg(), 502);
}
// Return response data along with HTTP status code
return array(
'json_response' => $json_response,
'http_status_code' => curl_getinfo($ch, CURLINFO_HTTP_CODE),
);
}
function handle_response_CIPF($response) {
Plgntls::debug_infos();
try
{
// Decode JSON response
$json_response = json_decode($response);
return array(
'json_response' => $json_response,
'http_status_code' => http_response_code()
);
}
catch (Exception $err)
{
// Get error message from response
$error_message = $response->text();
throw new Exception($error_message);
}
}
/**
* Generate an OAuth 2.0 access token for authenticating with PayPal REST APIs.
* @see https://developer.paypal.com/docs/checkout/standard/integrate/#link-integratebackend
* @see https://developer.paypal.com/api/rest/authentication/
*/
function generate_access_token_CIPF() {
Plgntls::debug_infos();
$paypal_client_id = get_paypal_client_id_CIPF();
$paypal_client_secret = get_paypal_client_secret_CIPF();
$paypal_api_base_url = get_paypal_api_base_url_CIPF();
/*
try
{
*/
if ( !$paypal_client_id || !$paypal_client_secret ) {
throw new HttpException("MISSING_API_CREDENTIALS", 403);
}
$credentials = $paypal_client_id . ":" . $paypal_client_secret;
$auth = base64_encode($credentials);
$url = $paypal_api_base_url . '/v1/oauth2/token';
$body = http_build_query(array('grant_type' => 'client_credentials'));
// Initialize curl
$ch = curl_init();
// Set curl options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Basic ' . $auth,
));
/********************/
// Execute cURL session and get the response
$data_json = curl_exec($ch);
// in utils
$data = handle_json_response_CIPF($data_json, $ch);
// Close cURL session
curl_close($ch);
return $data['json_response']->access_token;
/********************/
/*
// Execute curl and get the response
$data_json = curl_exec($ch);
if ( $data_json === false)
throw new Exception('cURL error: ' . curl_error($ch));
// Close curl
curl_close($ch);
$data = json_decode($data_json);
return $data->access_token;
}
catch (Exception $error)
{
error_log("Failed to generate Access Token:");
error_log($error->getMessage());
}
*/
};
?>

View File

@@ -0,0 +1,34 @@
<?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!');
}
// handling routes and endpoints
// diff routes and endpoints : https://stackoverflow.com/q/56075017/9497573
function routes_endpoints_CIPF() {
Plgntls::debug_infos();
if (is_admin()) {
return;
}
$base_rest_route = Cipf::URL_BASE_REST_ROUTE;
register_rest_route($base_rest_route, '/orders', array(
'methods' => 'POST',
'callback' => 'handle_orders_request_CIPF',
));
register_rest_route($base_rest_route, '/orders/(?P<orderID>[a-zA-Z0-9]+)/capture', array(
'methods' => 'POST',
'callback' => 'handle_orders_capture_request_CIPF',
));
};
add_action('rest_api_init', 'routes_endpoints_CIPF');
?>

View File

@@ -0,0 +1,65 @@
<?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!');
}
/**
* call to paypal_shortcode_content()
*/
function paypal_shortcode_content_CIPF() {
Plgntls::debug_infos();
$slug_paypal_redirection_success = Cipf::SLUG_PAYPAL_REDIRECTION_SUCCESS;
$slug_paypal_redirection_failure = Cipf::SLUG_PAYPAL_REDIRECTION_FAILURE;
$paypal_client_id = get_paypal_client_id_CIPF();
$paypal_message_success = get_payment_message_success_CIPF();
$paypal_message_failure = get_payment_message_failure_CIPF();
$paypal_message_problem = get_payment_message_problem_CIPF();
// if (!can_pay_now_CIPF())
// return no_payment_CIPF();
$pp_client_id = $paypal_client_id;
$pp_sdk_currency = "EUR";
$pp_sdk_base_url = "https://www.paypal.com";
$pp_sdk_url = "{$pp_sdk_base_url}/sdk/js?client-id={$pp_client_id}&currency={$pp_sdk_currency}";
$paypal_redirection_success = home_url() . '/' . $slug_paypal_redirection_success;
$paypal_redirection_failure = home_url() . '/' . $slug_paypal_redirection_failure;
$added_to_front = Plgntls::add_to_front(
array(
$pp_sdk_url,
array("js/paypal/paypal.js", 'type'=>'module'),
"html/paypal/paypal.html",
),
compact (
'paypal_redirection_success',
'paypal_redirection_failure',
'paypal_message_success',
'paypal_message_failure',
'paypal_message_problem',
),
);
return $added_to_front;
}
add_shortcode('cipf_paypal_shortcode', 'paypal_shortcode_content_CIPF');
function no_payment_CIPF() {
Plgntls::debug_infos();
return;
}
?>

View File

@@ -0,0 +1,222 @@
<?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!');
}
/*
* see documentation in private 'paypal.md'
* basically it check if the user who initiate the transaction
* is the same that finish it
*
* add_user_meta('user_id', 'cipf_order_id', 'aaaaaa');
* ['aaaaaa']
* add_user_meta('user_id', 'cipf_order_id', 'bbbbbb');
* ['aaaaaa', 'bbbbbb']
* add_user_meta('user_id', 'cipf_order_id', 'bbbbbb');
* ['aaaaaa', 'bbbbbb', 'bbbbbb']
* get_user_meta('user_id', 'cipf_order_id');
* ['aaaaaa', 'bbbbbb', 'bbbbbb']
* $del_ret = delete_user_meta('user_id', 'cipf_order_id', 'bbbbbb');
* ['aaaaaa'] - $del_ret === true
* $del_ret = delete_user_meta('user_id', 'cipf_order_id', 'bbbbbb');
* ['aaaaaa'] - $del_ret === false
*
*/
/*
*
*
*/
function update_user_pre_order_CIPF($message) {
Plgntls::debug_infos();
$acf_payment_status = Cipf::ACF_CARD_PAYMENT_STATE;
$meta_order_id = Cipf::META_ORDER_ID;
$order_id = $message->id;
$user_id = get_current_user_id();
$acf_id = 'user_'.$user_id;
/*
* - delete previous order ids
* ->if we are here it's because a new order will try to be created
* - addind order_id to cipf_order_id meta field
*
*/
delete_user_meta($user_id, $meta_order_id);
add_user_meta($user_id, $meta_order_id, $order_id);
/*
* create a meta field to check states of payements on prof author page :
* - 'started' -> at order creation
* - 'success' -> at capture success (on author page, it means success, then make it empty)
* - 'failure' -> at capture failure (on author page, it means failure, then make it empty)
* - 'nothing' -> output nothing on author page
*
*/
set_payment_started_CIPF($user_id);
}
/*
*
*
*/
function update_user_post_capture_CIPF($message) {
Plgntls::debug_infos();
$order_id = $message->id;
$user_id = get_current_user_id();
$status = null;
if (is_object($message) && isset($message->status))
$status = $message->status;
/*
* capture status : https://developer.paypal.com/docs/api/orders/v2/#definition-order_status
* - COMPLETED
* - DECLINED
* - PARTIALLY_REFUNDED
* - PENDING
* - REFUNDED
* - FAILED
*/
/*
* delete order_id and update user
* -> is it necessary to delete order_id since we delete it when creating a new order ?
* -> it is at least necessary to find the user who did the purchase
*
*/
// find the user containing the order_id and delete this order_id
$user_id_to_update = find_user_with_order_id_CIPF($user_id, $order_id);
if ($user_id_to_update === false)
throw new HttpException('cannot find user with this order_id', 502);
if ($status === 'COMPLETED') {
// proceed to validate payment for user
success_payment_for_user_CIPF($user_id_to_update, $order_id);
}
else if ($status === 'PENDING') {
// i don't know what to do yet, maybe make more checks and output a message to contact diego ?
// https://developer.paypal.com/docs/api/orders/v2/#definition-capture_status_details
}
else {
failure_payment_for_user_CIPF($user_id_to_update, $order_id, $status);
}
}
/*
* things to do when a payment has failed
* failed payement means order status is not COMPLETED or PENDING
* it can be :
* - DECLINED
* - PARTIALLY_REFUNDED
* - REFUNDED
* - FAILED
* -> capture status : https://developer.paypal.com/docs/api/orders/v2/#definition-order_status
* in any cases, the price was not paid
*
*/
function failure_payment_for_user_CIPF($user_id, $order_id, $status) {
Plgntls::debug_infos();
$meta_order_id = Cipf::META_ORDER_ID;
$acf_id = 'user_'.$user_id;
/*
* remove the order_id from user meta
*
*/
delete_user_meta($user_id, $meta_order_id, $order_id);
set_payment_failure_CIPF($user_id);
set_account_to_pay_CIPF($user_id);
send_emails_CIPF('payment_echec', $user_id);
}
/*
* things to do when a payment is a success
*
*/
function success_payment_for_user_CIPF($user_id, $order_id) {
Plgntls::debug_infos();
$meta_order_id = Cipf::META_ORDER_ID;
$acf_id = 'user_'.$user_id;
/*
* remove the order_id from user meta
*
*/
delete_user_meta($user_id, $meta_order_id, $order_id);
update_card_expiration_CIPF($user_id);
if (is_card_new_CIPF()) {
set_card_number_CIPF($user_id);
set_card_renew_CIPF($user_id);
}
set_payment_success_CIPF($user_id);
set_account_valid_CIPF($user_id);
send_emails_CIPF('payment_success', $user_id);
}
/*
* @return mixed num - user_id
* bool false - if no match found
*
*/
function find_user_with_order_id_CIPF($current_user_id, $order_id) {
Plgntls::debug_infos();
$meta_order_id = Cipf::META_ORDER_ID;
$role_prof = Cipf::ROLE_PROF;
$user_metas = get_user_meta($current_user_id, $meta_order_id, false);
if (in_array($order_id, $user_metas)) {
return $current_user_id;
}
/*
* it means the current user didn't have this order_id
* so we look for another user
* https://developer.wordpress.org/reference/classes/WP_User_Query/prepare_query/
*
*/
$users = get_users(array(
'role' => $role_prof,
'meta_key' => $meta_order_id,
'meta_value' => $order_id,
'fields' => 'ID',
));
if (count($users) > 1)
throw new HttpException('multiple users with same order_id', 502);
else if (count($users) === 1)
return reset($users);
return false;
}
?>

View File

@@ -0,0 +1,138 @@
<?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!');
}
/*
* 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
* @return true / wp_error
*
*/
function check_can_pay_CIPF() {
Plgntls::debug_infos();
$acf_card_payment_method = Cipf::ACF_CARD_PAYMENT_METHOD;
$acf_card_price_choice = Cipf::ACF_CARD_PRICE_CHOICE;
$acf_card_price_delivery = Cipf::ACF_CARD_PRICE_DELIVERY;
$acf_card_price_total = Cipf::ACF_CARD_PRICE_TOTAL;
$acf_card_expiration = Cipf::ACF_CARD_EXPIRATION;
$card_renew_period = Cipf::CARD_RENEW_PERIOD;
$current_user = wp_get_current_user();
$user_id = get_current_user_id();
$acf_id = 'user_' . $user_id;
/*
* check if payment is virement or immediat
*
$payement = get_field($acf_card_payment_method['_name'], $acf_id);
if (strtolower($payement) === 'virement') {
return false;
}
*/
/*
* ABANDONNED : bug with formbuilder
* calculate price
* update the price even if form builder already did it
* in case it was changed from admin pannel
*
$tarif = get_acf_value_CIPF($acf_card_price_choice, $acf_id);
$livraison = get_acf_value_CIPF($acf_card_price_delivery, $acf_id);
if ($tarif !== null && $livraison !== null) {
$price = $tarif + $livraison;
}
else {
$price = 0;
}
update_field($acf_card_price_total['_name'], $price, $acf_id);
*/
/*
* price is not empty or 0
*
*/
$price = get_field($acf_card_price_total['_name'], $acf_id);
if (empty($price)) {
return new WP_Error('cannot_purchase', "no price selected");
}
if ($price === 0) {
return new WP_Error('cannot_purchase', "price is 0, nothing to purchase");
}
/*
* date validity is empty
* or is paste
* or is less than 1 month
*
$validity_field = get_field_object($acf_card_expiration, $acf_id);
if ($validity_field === false)
return true;
$validity = $validity_field['value'];
$format_field = $validity_field['return_format'];
if (empty($validity))
return true;
$date_validity = date_create_from_format($format_field, $validity);
$date_now = date_create('today');
$diff = date_diff($date_now, $date_validity)->format('%R%a');
if ((int)$diff <= 0) {
// date end of validity in the past
return true;
}
else if ((int)$diff <= $card_renew_period) {
// date expiration is in less that renew period time (ex: 30 days)
return true;
}
else {
// date end of validity is in more than renew perdio (ex: 3 month)
return new WP_Error('cannot_purchase', "it's too soon to renew your card");
}
*/
return true;
}
?>

View 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);
}
?>

View 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');
?>

View 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);
}
}
}
?>

View 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);
?>

View 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');
?>

View 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!');
}
/*
* 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
nocache_headers();
wp_redirect(home_url(), 301);
exit;
}
/*
* 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(){
Plgntls::debug_infos(2);
$slug_page_redirection = Cipf::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;
}
Plgntls::debug_infos();
redirection_profil_CIPF();
}
add_action('template_redirect', 'redirection_page_CIPF');
?>

View 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);
?>

View 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);
}
?>

View File

@@ -0,0 +1,27 @@
<?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!');
}
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
https://stackify.com/how-to-log-to-console-in-php/
*/
function console_log(...$outputs) {
Plgntls::debug_infos();
if (CIPF_CONSOLE_OFF)
return;
foreach($outputs as $output)
{
$json_output = json_encode($output, JSON_HEX_TAG);
$js_code = '<script>console.log(' . $json_output . ');</script>';
echo $js_code;
}
}
?>

View File

@@ -0,0 +1,68 @@
<?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!');
}
/*
* globals variables
* const vs define : https://stackoverflow.com/questions/2447791/php-define-vs-const
*/
/* switch console_log
const CONSOLE_OFF = true;
*/
const CIPF_CONSOLE_OFF = false;
/*
* paypal credentials
*
* LIVE :
*
* const PAYPAL_CLIENT_ID = "Aedn5e8z__hPBvKirqw5bwlhI9ChG8_N6c1xbgybYyBr4B4oP8uVzmVdH1QVKdPQKf6bWg7orPV4PDrO";
* const PAYPAL_CLIENT_SECRET = "EGeGwfHGxHxsjnC-tH8W0IL4nN3_xlc3sXFRPCQOw5uUoWae3eOgghuDKMnZc5DVGTbP6yIjVJ1BaAra";
*
* SANBOX :
*
* const PAYPAL_CLIENT_ID = "AfcmwxIXlG2ZxaMdjazX57I70BXz__aEqNWaTnqfSCI34a0V7nMbytswx7EViUjlpHs7opyrRwaH9YLl";
* const PAYPAL_CLIENT_SECRET = "EGunIhGRjPvn0Z8wXO0JsdhET30OStTAH_IyRsmhimEN23_qiRSFD-ql4tvnulKJw6TitZ-vU-ytc4A-";
*
const PAYPAL_CLIENT_ID = "AfcmwxIXlG2ZxaMdjazX57I70BXz__aEqNWaTnqfSCI34a0V7nMbytswx7EViUjlpHs7opyrRwaH9YLl";
const PAYPAL_CLIENT_SECRET = "EGunIhGRjPvn0Z8wXO0JsdhET30OStTAH_IyRsmhimEN23_qiRSFD-ql4tvnulKJw6TitZ-vU-ytc4A-";
*/
/*
* paypal api base url
const PAYPAL_API_BASE_URL = "https://api-m.sandbox.paypal.com";
*/
/*
* paypal messages
* put the message betweeen backticks `message` and then between single quotes '`message`'
* because it will be evaluated in front by js, so it need something to evaluate, in ``
* you can then use variables available in the context of execution : '`Transaction ${transaction.status}`'
* is it good strategy ? idk
const PAYPAL_MESSAGE_SUCCESS = '`Transaction ${transaction.status}: ${transaction.id}<br><br>See console for all available details`';
const PAYPAL_MESSAGE_FAILURE = '`Sorry, your transaction could not be processed...<br><br>${error}`';
const PAYPAL_MESSAGE_SUCCESS = '`paiement reussi`';
const PAYPAL_MESSAGE_FAILURE = '`paiement raté`';
*/
/*
* acf fields for card :
* - card_is_valid : has valid card
* - card_date_purchase : date of purchase
* - card_date_validity : date end of validity
const CARD_IS_VALID = 'carte_est_valide';
const CARD_DATE_PURCHASE = 'date_d_achat';
const CARD_DATE_VALIDITY = 'date_fin_validite';
*/
?>

View File

@@ -0,0 +1,30 @@
<?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!');
}
// Define a custom exception class for HTTP errors
class HttpException extends Exception {
// HTTP status code
private $statusCode;
public function __construct($message, $statusCode) {
parent::__construct($message);
$this->statusCode = $statusCode;
}
public function getStatusCode() {
return $this->statusCode;
}
}
?>

File diff suppressed because it is too large Load Diff

View 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');
?>

View 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');
?>

View 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
View 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');
?>

View 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;
}
}
?>

View 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);
?>

View 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);
}
?>

View 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;
//}
?>

View 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;
}
?>

View 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');
?>

View File

View 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();
?>

View 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>

View File

@@ -0,0 +1,70 @@
function patch_form_calculation_CIPF() {
let form_calculation = document.querySelector('form.fb_form.multistep');
if (form_calculation === null)
return;
/*
* finds the input:checked in the element .calculate_field
* and trigger the event 'change' on it
* - this event 'change' is added by form builder in divi-form-calc-min.js :
* $(document).on(
* 'change',
* '.calculate_field input:not([type="hidden"]), .calculate_field select',
* function () {
* ...
* }
* );
*
*/
function trigger_change(element) {
/*
* jquery version
*
let inputs = $(element).find('input:checked');
inputs.trigger('change');
*/
/*
* js version
*
*/
let inputs = element.querySelectorAll('input:checked');
// loop through inputs and trigger 'change' event on each
inputs.forEach(function(input) {
// Triggering 'change' event
let change_event = new Event('change', {
bubbles: true,
cancelable: true,
});
input.dispatchEvent(change_event);
});
}
// create an observer on form to check if child nodes are modified
const observer_form = new MutationObserver(wait_for_calculation_class);
observer_form.observe(form_calculation, {
subtree: true,
attributes: true,
});
// observe mutations to see if they include the addition of class .calculate_field
// if the class is added, call the function that might trigger the change event on it
function wait_for_calculation_class(mutationsList) {
mutationsList.forEach((mutation) => {
// check if class where added
if (mutation.type !== 'attributes')
return;
if (mutation.attributeName !== 'class')
return;
// check if added class is .calculate_field
let target = mutation.target;
if (target.classList.contains('calculate_field')) {
// If the class is added, trigger the 'change' event
trigger_change(target);
}
});
}
}
patch_form_calculation_CIPF();

View File

@@ -0,0 +1,29 @@
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
const observer_CIPF = new MutationObserver(wait_for_close_button_CIPF);
observer_CIPF.observe(modal_wrapper_CIPF, {
subtree: true,
childList: true,
});
// observe mutations to see if they include the creation of the button .modal-close
// if the button is created, add an eventListener to it
function wait_for_close_button_CIPF(mutationsList) {
mutationsList.forEach((mutation) => {
// check if nodes were added
if (mutation.type !== 'childList')
return;
// check if added nodes includes the button .modal-close
let modal_close = document.querySelector('#de-fb-modal-wrapper- .modal-close');
if (modal_close !== null) {
modal_close.addEventListener("click", delete_modal_CIPF);
}
});
}
// when triggered, the .modal-close button will remove all childs from #de-fb-modal-wrapper-
function delete_modal_CIPF() {
modal_wrapper_CIPF.innerHTML = '';
}

View File

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

View 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');
?>

View 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');
?>

View 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;
}
?>

View 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();
}
}
?>

View 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);
?>

View 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);
?>

View 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');
?>

View File

@@ -1,12 +1,14 @@
<?php <?php
/* namespace FBPATCH;
Plugin Name: formbuilder url patch
Plugin URI: /**
Description: * it means someone outside wp is accessing the file, in this case kill it.
Author: hugogogo */
Version: 1.1.0 if (!defined('ABSPATH')) {
Author URI: die('You can not access this file!');
*/ }
/** /**
* in `wp-content/plugins/divi-form-builder/includes/DiviFormBuilder.php` * in `wp-content/plugins/divi-form-builder/includes/DiviFormBuilder.php`
@@ -14,15 +16,15 @@ Author URI:
* - Undefined variable: min_length in /var/www/html/wp-content/plugins/divi-form-builder/includes/modules/FormField/FormField.php on line 5933 * - Undefined variable: min_length in /var/www/html/wp-content/plugins/divi-form-builder/includes/modules/FormField/FormField.php on line 5933
* - Undefined variable: use_icon in /var/www/html/wp-content/plugins/divi-form-builder/includes/modules/FormField/FormField.php on line 5984 * - Undefined variable: use_icon in /var/www/html/wp-content/plugins/divi-form-builder/includes/modules/FormField/FormField.php on line 5984
*/ */
function add_my_jquery_patch() function add_my_jquery_patch() {
{
$handle = 'jquery_validator_url_patch'; $handle = 'jquery_validator_url_patch';
$url = plugin_dir_url(__FILE__) . 'jquery_validator_url_patch.js'; $url = Fbpatch::root_url() . 'js/urls.js';
$dependencies = array('de_fb_validate'); $dependencies = array('de_fb_validate');
$version = ''; $version = null;
$defer = true; $defer = true;
wp_enqueue_script( $handle, $url, $dependencies, $version, $defer); wp_enqueue_script( $handle, $url, $dependencies, $version, $defer);
} }
add_action('wp_enqueue_scripts', 'add_my_jquery_patch'); add_action('wp_enqueue_scripts', __NAMESPACE__.'\add_my_jquery_patch');
?> ?>

View File

@@ -1,7 +0,0 @@
.first_el_to_change {
border: 1px solid red;
}
#model_plugin_shortcode {
border: 1px solid blue;
padding: 10px;
}

View File

@@ -1,391 +0,0 @@
<?php
/*
Plugin Name: fipfcard_plugin
Plugin URI:
Description:
Author: hugogogo
Version: 1.1.0
Author URI:
*/
/*
5.5 . 5.48
59 . 58.99
50.6 . 50.58
38.5 . 38.53
99.8 . 99.84
25.2 . 25.17
131.6 . 135
63.7 . 63.68
85 . 85.05
50.2 . 50.17
41.4 . 41.43
18.8 . 18.82
*/
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
plugin dir root
*/
include_once( plugin_dir_path(__FILE__) . '/utils/plugin_tools.php');
PLGNTLS_class::set_root_dir( plugin_dir_path(__FILE__), plugin_dir_url(__FILE__) );
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
inclusions
*/
include_once(PLGNTLS_class::get_path() . '/php/utils/globals.php');
include_once(PLGNTLS_class::get_path() . '/php/menu/example_menu.php');
//include_once(PLGNTLS_class::get_path() . '/php/images/image_edit_shortcode.php');
//include_once(PLGNTLS_class::get_path() . '/php/images/image-edit.php');
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
plugin shortcode
*/
function fipfcard_main_shortcode()
{
$fipfcard_tools = new PLGNTLS_class();
$myvar_1 = "I am one";
$myvar_2 = "I am two";
$names = ["hugo", "camille"];
$ages = ["13", "34", "56"];
$data = wp_get_current_user();
$data = $data->data;
$data = $data->user_email;
//error_log("data->data");
//error_log($data);
//delete_post_meta(get_the_ID(), "_data_user_email");
//delete_post_meta(get_the_ID(), "_data");
//add_post_meta(get_the_ID(), "data_user_email", $data);
$post_metadata = get_metadata( 'post', get_the_ID() );
$post_meta = get_post_meta( get_the_ID() );
$user_metadata = get_metadata( 'user', get_current_user_id() );
$user_meta = get_user_meta( get_current_user_id() );
$acf_get_fields = get_fields( get_the_ID() );
$user_data = get_userdata( get_current_user_id() );
$current_user = wp_get_current_user();
return $fipfcard_tools->add_to_front
(
array
(
"css/example_style.css",
"js/example_init.js",
"js/example_script2.js",
"js/example_script3.js",
"html/example_index.html",
"html/example_index2.html",
),
compact
(
"myvar_1",
"myvar_2",
"post_metadata",
"post_meta",
"user_metadata",
"user_meta",
"acf_get_fields",
"user_data",
"current_user",
"names",
"ages",
)
);
}
add_shortcode('fipfcard_plugin', 'fipfcard_main_shortcode');
function custom_frontend_posting_form() {
$my_image = the_field('image_ratio');
error_log("my_image");
error_log(json_encode($my_image));
return $my_image;
}
add_shortcode('custom_frontend_posting_form', 'custom_frontend_posting_form');
/*
add_action('init', 'custom_action_handler');
function custom_action_handler() {
error_log("inside init :)");
if ( isset( $_GET['custom_action'] ) && $_GET['custom_action'] === 'do_something' ) {
error_log("GET :)");
}
if ( isset( $_POST['custom_action'] ) && $_POST['custom_action'] === 'do_something' ) {
error_log("POST :)");
}
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
error_log("REQUEST_METHOD === GET");
error_log("_GET");
error_log(json_encode($_GET));
}
if ($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['submit'])) {
error_log("REQUEST_METHOD === GET && GET[SUBMIT]");
}
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER['QUERY_STRING'] === 'custom_action=do_something' ) {
error_log("_POST['de_fb_ville']");
error_log(json_encode($_POST['de_fb_ville']));
}
*/
// custom-form-handler.php
/*
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['submit'])) {
error_log("REQUEST_METHOD === POST && POST[SUBMIT]");
error_log("_POST");
error_log(json_encode($_POST));
// Form submitted, handle the submission
$name = sanitize_text_field($_POST['name']);
$email = sanitize_email($_POST['email']);
// Perform validation
$errors = array();
if (empty($name)) {
$errors['name'] = 'Name is required';
}
if (!is_email($email)) {
$errors['email'] = 'Invalid email address';
}
if (empty($errors)) {
// Form data is valid, process the submission
// For example, save data to the database or send an email
// Redirect the user or display a success message
} else {
// Form data is not valid, display errors
// You might re-render the form with error messages here
}
}
}
*/
/*
[17-Feb-2024 17:54:21 UTC]
{
"SERVER_SOFTWARE":"nginx\/1.20.2",
"REQUEST_URI":"\/?custom_action=do_something",
"USER":"www-data",
"HOME":"\/home\/www-data",
"HTTP_SEC_GPC":"1",
"HTTP_SEC_FETCH_USER":"?1",
"HTTP_SEC_FETCH_SITE":"same-origin",
"HTTP_SEC_FETCH_MODE":"navigate",
"HTTP_SEC_FETCH_DEST":"document",
"HTTP_UPGRADE_INSECURE_REQUESTS":"1",
"HTTP_COOKIE":"wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_f31a945e73c53ab9af191e34eb33fa88=hugo%7C1708332197%7CbJvy7kRZ3UWJ2C0ZOaSuhpLCz11vHL8CA68sQv9U1ne%7C927c46e3b46a2716df0fcce98d7ccda0e158be0aad0593b2dc233de4ccad9e27; wp-settings-time-11=1708187741; mjx.menu=renderer%3ANativeMML%26%3Bsemantics%3Atrue%26%3Bcontext%3ABrowser%26%3Bzoom%3ANone",
"HTTP_REFERER":"https:\/\/local_fipfcard_plugin.com\/modif_profile\/",
"HTTP_CONNECTION":"keep-alive",
"HTTP_DNT":"1",
"HTTP_ORIGIN":"https:\/\/local_fipfcard_plugin.com",
"HTTP_CONTENT_LENGTH":"2310",
"HTTP_CONTENT_TYPE":"multipart\/form-data; boundary=---------------------------92033335430820533424009149678",
"HTTP_ACCEPT_ENCODING":"gzip, deflate, br",
"HTTP_ACCEPT_LANGUAGE":"en-US,en;q=0.5",
"HTTP_ACCEPT":"text\/html,application\/xhtml+xml,application\/xml;q=0.9,image\/avif,image\/webp,*\/*;q=0.8",
"HTTP_USER_AGENT":"Mozilla\/5.0 (X11; Ubuntu; Linux x86_64; rv:122.0) Gecko\/20100101 Firefox\/122.0",
"HTTP_HOST":"local_fipfcard_plugin.com",
"REDIRECT_STATUS":"200",
"SERVER_NAME":"local_fipfcard_plugin.com",
"SERVER_PORT":"443",
"SERVER_ADDR":"172.18.0.4",
"REMOTE_PORT":"47220",
"REMOTE_ADDR":"172.18.0.1",
"GATEWAY_INTERFACE":"CGI\/1.1",
"HTTPS":"on",
"REQUEST_SCHEME":"https",
"SERVER_PROTOCOL":"HTTP\/1.1",
"DOCUMENT_ROOT":"\/var\/www\/html",
"DOCUMENT_URI":"\/index.php",
"SCRIPT_NAME":"\/index.php",
"CONTENT_LENGTH":"2310",
"CONTENT_TYPE":"multipart\/form-data; boundary=---------------------------92033335430820533424009149678",
"REQUEST_METHOD":"POST",
"QUERY_STRING":"custom_action=do_something",
"SCRIPT_FILENAME":"\/var\/www\/html\/index.php",
"FCGI_ROLE":"RESPONDER",
"PHP_SELF":"\/index.php",
"REQUEST_TIME_FLOAT":1708192460.934234,
"REQUEST_TIME":1708192460
}
$_POST
{
"field_title":["ville_title","nom","pedagogie"],
"field_name":["de_fb_ville","de_fb_nom","de_fb_pedagogie"],
"field_id":["de_fb_ville_id","de_fb_nom","de_fb_pedagogie"],
"de_fb_ville":"gut",
"de_fb_nom":"gut",
"de_fb_pedagogie":"gut",
"form_key":"33420-0",
"unique_id":"d2564b14-290e-4865-b740-7932ae770d43",
"form_type":"custom",
"divi-form-submit":"yes",
"form_id":"modif_profile",
"form_type_confirm":""
}
add_action('parse_request', 'my_custom_url_handler');
function my_custom_url_handler($query)
{
if ($_SERVER['REQUEST_METHOD'] !== 'POST' )
return ;
if ($_SERVER['QUERY_STRING'] !== 'update_profile_acf' )
return ;
// ! add verification that user can do this edit !
foreach($_POST['field_name'] as $field)
{
error_log("_POST[$field]");
error_log($_POST[$field]);
}
}
*/
/**
* do_action( 'df_before_process', string $form_id, Array $post_array, String $form_type )
* Description: Fires after form is submitted and captcha checking is ok.
* Parameters:
* - $form_id: (String) Form ID from Form setting.
* - $post_array: (Array) Submitted fields from the form. Keys are mapped field names or custom field names (in case of Field Mapping Type is Custom).
* - $form_type : (String) Form Type
*
* wordpress_docker/volumes/wp_volume/wp-content/plugins/divi-form-builder/includes/DiviFormBuilder.php|298 col 18-35| do_action( 'df_before_process', $form_id, $post_array, $form_type );
* wordpress_docker/volumes/wp_volume/wp-content/plugins/divi-form-builder/includes/ajaxcalls/post_ajax.php|254 col 16-33| do_action( 'df_before_process', $form_id, $post_array, $form_type );
*
* check user rights :
* - https://developer.wordpress.org/reference/functions/is_user_logged_in/
* - https://stackoverflow.com/questions/19802492/check-if-current-user-is-administrator-in-wordpress
* - https://developer.wordpress.org/reference/functions/current_user_can/
*/
add_action ('df_before_process', 'PLGNTLS_my_custom_df_form_handler', 10, 3);
function PLGNTLS_my_custom_df_form_handler($form_id, $post_array, $form_type)
{
error_log("in my_custom_df_form_handler");
error_log("form_id");
error_log($form_id);
error_log("post_array");
error_log(json_encode($post_array));
error_log("form_type");
error_log($form_type);
}
// Hook into the 'acf/save_post' action
/*
add_action('acf/save_post', 'handle_acf_form_submission', 5); // 20 is the priority, you can adjust it as needed
function handle_acf_form_submission($post_id)
{
error_log("in acf/save_post");
if ($_SERVER['REQUEST_METHOD'] === 'POST' )
{
error_log("_SERVER['REQUEST_URI']");
error_log(json_encode($_SERVER['REQUEST_URI']));
error_log("_SERVER['QUERY_STRING']");
error_log(json_encode($_SERVER['QUERY_STRING']));
error_log("_POST['de_fb_ville']");
error_log(json_encode($_POST['de_fb_ville']));
}
// Check if the request is coming from the specific URL
if ($_SERVER['QUERY_STRING'] !== '/') {
return; // Exit if the request is not from the specific URL
}
// Check if this is an autosave
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
// Check if this is a revision
if (wp_is_post_revision($post_id)) {
return;
}
// Check if the current user has permission to edit the post
if (!current_user_can('edit_post', $post_id)) {
return;
}
// Your ACF form submission handling logic goes here
// For example, you can retrieve form data using $_POST and update ACF fields accordingly
if (isset($_POST['your_acf_field_name'])) {
$field_value = sanitize_text_field($_POST['your_acf_field_name']);
update_field('your_acf_field_name', $field_value, $post_id);
}
}
*/
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
menu plugin
*/
function fipfcard_plugin_menu()
{
add_menu_page
(
'fipf_card', // webpage title
'fipf_card', // menu title
'manage_options', // capability
'fipfcard-plugin', // menu_slug
'fipfcard_plugin_content' // callback function to display page content
);
}
add_action('admin_menu', 'fipfcard_plugin_menu');
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
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 fipfcard_ajax_handler()
{
wp_send_json_success( array
(
'It works',
"data_received" => $_POST['postid'],
),
200
);
}
add_action( 'wp_ajax_get_data', 'fipfcard_ajax_handler' );
?>

View File

@@ -1,66 +0,0 @@
<div id="model_plugin_shortcode">
<ol>
<p>list get_metadata('post') :</p>
<?php
foreach($post_metadata as $meta_key => $meta_value) {
include($plgn_dir."html/templates/print_meta.html");
}
?>
</ol>
<ol>
<p>list get_post_meta() :</p>
<?php
foreach($post_meta as $meta_key => $meta_value) {
include($plgn_dir."html/templates/print_meta.html");
}
?>
</ol>
<ol>
<p>list get_metadata('user') :</p>
<?php
foreach($user_metadata as $meta_key => $meta_value) {
include($plgn_dir."html/templates/print_meta.html");
}
?>
</ol>
<ol>
<p>list get_user_meta() :</p>
<?php
foreach($user_meta as $meta_key => $meta_value) {
include($plgn_dir."html/templates/print_meta.html");
}
?>
</ol>
<ol>
<p>list get_userdata() :</p>
<?php
foreach($user_data as $meta_key => $meta_value) {
include($plgn_dir."html/templates/print_meta.html");
}
?>
</ol>
<ol>
<p>list wp_get_current_user() :</p>
<?php
foreach($current_user as $meta_key => $meta_value) {
include($plgn_dir."html/templates/print_meta.html");
}
?>
</ol>
<ol>
<p>list wp_get_current_user()->data :</p>
<?php
foreach($current_user->data as $meta_key => $meta_value) {
include($plgn_dir."html/templates/print_meta.html");
}
?>
</ol>
<p>i am a new p</p>
<p class="first_el_to_change">to change</p>
<button id='test_ajax_1' name="ajax_button_1" value="2024">2024</button>
<?php
foreach($names as $name) {
include($plgn_dir."html/templates/example_presentation.html");
}
?>

View File

@@ -1,22 +0,0 @@
<?php
foreach($ages as $age) {
?>
<p>age <?php echo esc_html($age); ?></p>
<?php
}
?>
<p class="third_el_to_change">to change</p>
<p>aaaaaand this is the end</p>
<form method="post" action="<?php echo esc_url( wp_registration_url() ); ?>">
<input type="text" name="user_login" placeholder="username">
<input type="email" name="user_email" placeholder="email">
<input type="password" name="user_pass" placeholder="password">
<button type="submit">register</button>
</form>
<form method="post" action="<?php echo esc_url( wp_lostpassword_url() ); ?>">
<input type="hidden" id="user_login" value="rexe">
<input type="text" name="pass1" data-reveal="1" data-pw="i0#chBo*S1Br5iDY" placeholder="new password">
<input type="hidden" name="rp_key" value="WO8qGALMbbKKsEEhXsOQ">
<button type="submit">generate</button>
</form>
</div>

View File

@@ -1,3 +0,0 @@
<input type='text' id='image_id' placeholder="image_id" value="33555">
<button id='edit_image'>edit image</button>
<div id="media_editor"></div>

View File

@@ -1,2 +0,0 @@
<input type='text' id='mytext'>
<button id='mybutton'>send</button>

View File

@@ -1,2 +0,0 @@
<p>hello <?php echo esc_html($name); ?></p>
<p class="second_el_to_change">to change</p>

View File

@@ -1,4 +0,0 @@
<li>
"<?php echo esc_html($meta_key); ?>" :
<?php echo esc_html(json_encode($meta_value)); ?>
</li>

View File

@@ -1,20 +0,0 @@
console.log("PLGNTLS_data:");
console.log(PLGNTLS_data);
const title = document.querySelector(".first_el_to_change");
title.innerHTML = "--- coucou ;) " + PLGNTLS_data.myvar_1;
const ajax_button_1 = document.querySelector("#test_ajax_1");
ajax_button_1.addEventListener('click', () => {
PLGNTLS_data.ajax(ajax_button_1, 'get_data')
.then((response) => response.json())
.then((data) => {
console.log("datou: ");
console.log(data);
})
.catch((error) => {
console.log("error: ");
console.log(error);
})
;
});

View File

@@ -1,3 +0,0 @@
const title2 = document.querySelector(".second_el_to_change");
title2.innerHTML = "--- ho boy !";

View File

@@ -1,3 +0,0 @@
const title3 = document.querySelector(".third_el_to_change");
title3.innerHTML = "--- bye bye, " + PLGNTLS_data.myvar_2;

File diff suppressed because it is too large Load Diff

View File

@@ -1,381 +0,0 @@
console.log("---------------inside image_editor.js--------------");
const edit_image_button = document.getElementById('edit_image');
const image_id_field = document.getElementById('image_id');
const media_editor = document.getElementById('media_editor');
edit_image_button.addEventListener('click', () => {
const image_id = image_id_field.value;
//PLGNTLS_ajax("postid", image_id, 'image-editor')
const data_obj = {
'postid': image_id,
};
PLGNTLS_ajax(data_obj, 'image_editor_PLGNTLS')
.then((response) => response.json())
.then((data) => {
console.log("data: ");
console.log(data);
media_editor.innerHTML = data.data.html;
})
.catch((error) => {
console.log("error: ");
console.log(error);
});
});
/*
open: function (e, t, i) { // t: nonce
this._view = i; // div: #media-editor-114
var a = c('#image-editor-' + e), // e: image id
o = c('#media-head-' + e),
r = c('#imgedit-open-btn-' + e),
s = r.siblings('.spinner');
if (!r.hasClass('button-activated')) return s.addClass('is-active'),
c.ajax({
url: ajaxurl,
type: 'post',
data: {
action: 'image-editor',
_ajax_nonce: t,
postid: e,
do : 'open'},
beforeSend: function () {
r.addClass('button-activated')
}
}).done(
function (t) {
var i;
'-1' === t &&
(
i = n('Could not load the preview image.'),
a.html(
'<div class="notice notice-error" tabindex="-1" role="alert"><p>' + i + '</p></div>'
)
),
t.data &&
t.data.html &&
a.html(t.data.html),
o.fadeOut(
'fast',
function () {
a.fadeIn(
'fast',
function () {
i &&
c(document).trigger('image-editor-ui-ready')
}
),
r.removeClass('button-activated'),
s.removeClass('is-active')
}
),
l.init(e)
}
) },
imgLoaded: function (t) {
var i = c('#image-preview-' + t),
e = c('#imgedit-crop-' + t);
void 0 === this.hold.sizer &&
this.init(t),
this.initCrop(t, i, e),
this.setCropSelection(
t,
{
x1: 0,
y1: 0,
x2: 0,
y2: 0,
width: i.innerWidth(),
height: i.innerHeight()
}
),
this.toggleEditor(t, 0, !0)
},
focusManager: function () {
setTimeout(
function () {
var t = c('.notice[role="alert"]');
(t = t.length ? t : c('.imgedit-wrap').find(':tabbable:first')).attr('tabindex', '-1').trigger('focus')
},
100
)
},
initCrop: function (a, t, i) {
var o = this,
r = c('#imgedit-sel-width-' + a),
s = c('#imgedit-sel-height-' + a),
n = c('#imgedit-start-x-' + a),
d = c('#imgedit-start-y-' + a),
t = c(t);
t.data('imgAreaSelect') ||
(
o.iasapi = t.imgAreaSelect({
parent: i,
instance: !0,
handles: !0,
keys: !0,
minWidth: 3,
minHeight: 3,
onInit: function (t) {
c(t).next().css('position', 'absolute').nextAll('.imgareaselect-outer').css('position', 'absolute'),
i.children().on(
'mousedown, touchstart',
function (t) {
var i,
e = !1;
t.shiftKey &&
(
t = o.iasapi.getSelection(),
i = o.getSelRatio(a),
e = t &&
t.width &&
t.height ? t.width + ':' + t.height : i
),
o.iasapi.setOptions({
aspectRatio: e
})
}
)
},
onSelectStart: function () {
l.setDisabled(c('#imgedit-crop-sel-' + a), 1),
l.setDisabled(c('.imgedit-crop-clear'), 1),
l.setDisabled(c('.imgedit-crop-apply'), 1)
},
onSelectEnd: function (t, i) {
l.setCropSelection(a, i),
c('#imgedit-crop > *').is(':visible') ||
l.toggleControls(c('.imgedit-crop.button'))
},
onSelectChange: function (t, i) {
var e = l.hold.sizer;
r.val(l.round(i.width / e)),
s.val(l.round(i.height / e)),
n.val(l.round(i.x1 / e)),
d.val(l.round(i.y1 / e))
}
})
)
},
setCropSelection: function (t, i) {
if (!(i = i || 0) || i.width < 3 && i.height < 3) return this.setDisabled(c('.imgedit-crop', '#imgedit-panel-' + t), 1),
this.setDisabled(c('#imgedit-crop-sel-' + t), 1),
c('#imgedit-sel-width-' + t).val(''),
c('#imgedit-sel-height-' + t).val(''),
c('#imgedit-start-x-' + t).val('0'),
c('#imgedit-start-y-' + t).val('0'),
c('#imgedit-selection-' + t).val(''),
!1;
i = {
x: i.x1,
y: i.y1,
w: i.width,
h: i.height
},
this.setDisabled(c('.imgedit-crop', '#imgedit-panel-' + t), 1),
c('#imgedit-selection-' + t).val(JSON.stringify(i))
},
close: function (t, i) {
if ((i = i || !1) && this.notsaved(t)) return !1;
this.iasapi = {},
this.hold = {},
this._view ? this._view.back() : c('#image-editor-' + t).fadeOut(
'fast',
function () {
c('#media-head-' + t).fadeIn(
'fast',
function () {
c('#imgedit-open-btn-' + t).trigger('focus')
}
),
c(this).empty()
}
)
},
notsaved: function (t) {
var i = c('#imgedit-history-' + t).val(),
i = '' !== i ? JSON.parse(i) : [];
return this.intval(c('#imgedit-undone-' + t).val()) < i.length &&
!confirm(c('#imgedit-leaving-' + t).text())
},
addStep: function (t, i, e) {
for (
var a = this,
o = c('#imgedit-history-' + i),
r = '' !== o.val() ? JSON.parse(o.val()) : [],
s = c('#imgedit-undone-' + i),
n = a.intval(s.val());
0 < n;
) r.pop(),
n--;
s.val(0),
r.push(t),
o.val(JSON.stringify(r)),
a.refreshEditor(
i,
e,
function () {
a.setDisabled(c('#image-undo-' + i), !0),
a.setDisabled(c('#image-redo-' + i), !1)
}
)
},
rotate: function (t, i, e, a) {
if (c(a).hasClass('disabled')) return !1;
this.closePopup(a),
this.addStep({
r: {
r: t,
fw: this.hold.h,
fh: this.hold.w
}
}, i, e)
},
flip: function (t, i, e, a) {
if (c(a).hasClass('disabled')) return !1;
this.closePopup(a),
this.addStep({
f: {
f: t,
fw: this.hold.w,
fh: this.hold.h
}
}, i, e)
},
crop: function (t, i, e) {
var a = c('#imgedit-selection-' + t).val(),
o = this.intval(c('#imgedit-sel-width-' + t).val()),
r = this.intval(c('#imgedit-sel-height-' + t).val());
if (c(e).hasClass('disabled') || '' === a) return !1;
0 < (a = JSON.parse(a)).w &&
0 < a.h &&
0 < o &&
0 < r &&
(a.fw = o, a.fh = r, this.addStep({
c: a
}, t, i)),
c('#imgedit-sel-width-' + t).val(''),
c('#imgedit-sel-height-' + t).val(''),
c('#imgedit-start-x-' + t).val('0'),
c('#imgedit-start-y-' + t).val('0')
},
undo: function (i, t) {
var e = this,
a = c('#image-undo-' + i),
o = c('#imgedit-undone-' + i),
r = e.intval(o.val()) + 1;
a.hasClass('disabled') ||
(
o.val(r),
e.refreshEditor(
i,
t,
function () {
var t = c('#imgedit-history-' + i),
t = '' !== t.val() ? JSON.parse(t.val()) : [];
e.setDisabled(c('#image-redo-' + i), !0),
e.setDisabled(a, r < t.length),
t.length === r &&
c('#image-redo-' + i).trigger('focus')
}
)
)
},
redo: function (t, i) {
var e = this,
a = c('#image-redo-' + t),
o = c('#imgedit-undone-' + t),
r = e.intval(o.val()) - 1;
a.hasClass('disabled') ||
(
o.val(r),
e.refreshEditor(
t,
i,
function () {
e.setDisabled(c('#image-undo-' + t), !0),
e.setDisabled(a, 0 < r),
0 == r &&
c('#image-undo-' + t).trigger('focus')
}
)
)
},
setNumSelection: function (t, i) {
var e = c('#imgedit-sel-width-' + t),
a = c('#imgedit-sel-height-' + t),
o = c('#imgedit-start-x-' + t),
r = c('#imgedit-start-y-' + t),
o = this.intval(o.val()),
r = this.intval(r.val()),
s = this.intval(e.val()),
n = this.intval(a.val()),
d = c('#image-preview-' + t),
l = d.height(),
d = d.width(),
h = this.hold.sizer,
g = this.iasapi;
if (!1 !== this.validateNumeric(i)) return s < 1 ? (e.val(''), !1) : n < 1 ? (a.val(''), !1) : void (
(s && n || o && r) &&
(i = g.getSelection()) &&
(
s = i.x1 + Math.round(s * h),
n = i.y1 + Math.round(n * h),
o = o === i.x1 ? i.x1 : Math.round(o * h),
i = r === i.y1 ? i.y1 : Math.round(r * h),
d < s &&
(o = 0, s = d, e.val(Math.round(s / h))),
l < n &&
(i = 0, n = l, a.val(Math.round(n / h))),
g.setSelection(o, i, s, n),
g.update(),
this.setCropSelection(t, g.getSelection())
)
)
},
round: function (t) {
var i;
return t = Math.round(t),
0.6 < this.hold.sizer ? t : '1' === (i = t.toString().slice( - 1)) ? t - 1 : '9' === i ? t + 1 : t
},
setRatioSelection: function (t, i, e) {
var a = this.intval(c('#imgedit-crop-width-' + t).val()),
o = this.intval(c('#imgedit-crop-height-' + t).val()),
r = c('#image-preview-' + t).height();
!1 === this.validateNumeric(e) ? this.iasapi.setOptions({
aspectRatio: null
}) : a &&
o &&
(
this.iasapi.setOptions({
aspectRatio: a + ':' + o
}),
e = this.iasapi.getSelection(!0)
) &&
(
r < (a = Math.ceil(e.y1 + (e.x2 - e.x1) / (a / o))) ? (
a = r,
o = n(
'Selected crop ratio exceeds the boundaries of the image. Try a different ratio.'
),
c('#imgedit-crop-' + t).prepend(
'<div class="notice notice-error" tabindex="-1" role="alert"><p>' + o + '</p></div>'
),
wp.a11y.speak(o, 'assertive'),
c(i ? '#imgedit-crop-height-' + t : '#imgedit-crop-width-' + t).val('')
) : void 0 !== (r = c('#imgedit-crop-' + t).find('.notice-error')) &&
r.remove(),
this.iasapi.setSelection(e.x1, e.y1, e.x2, a),
this.iasapi.update()
)
},
validateNumeric: function (t) {
if (!1 === this.intval(c(t).val())) return c(t).val(''),
!1
}
}
}(jQuery);
*/

View File

@@ -1,18 +0,0 @@
const inputElement = document.getElementById('mytext');
const sendButton = document.getElementById('mybutton');
sendButton.addEventListener('click', () => {
const inputValue = inputElement.value;
console.log("inputValue:");
console.log(inputValue);
PLGNTLS_ajax(inputValue, 'get_data')
.then((response) => response.json())
.then((data) => {
console.log("dataaa: ");
console.log(data);
})
.catch((error) => {
console.log("error: ");
console.log(error);
});
});

View File

@@ -1,23 +0,0 @@
<?php acf_form_head(); ?>
<?php get_header(); ?>
<div id="primary">
<div id="content" role="main">
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<p>My custom field: <?php the_field('my_custom_field'); ?></p>
<?php acf_form(); ?>
<?php endwhile; ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_footer(); ?>

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More