- added role at registration with xootix

- cleaned folder
This commit is contained in:
asus
2024-03-02 16:14:36 +01:00
parent 8aeef1dca8
commit 7738ad1863
22 changed files with 19 additions and 804 deletions

View File

@@ -1,225 +0,0 @@
<?php
/*
* the wp_footer hook fire on the front end just before the closing body tag
* this function depends on the names of acf fields :
* - afficher_offre_*
* - -> Masquer / *
* - offre_x* (image, titre, txt)
*/
function my_custom_js_function_PLGNTLS() {
if (!is_singular("project"))
return ;
error_log("------");
// list all acf fields of the current post
$acf_group_fields = get_fields();
// list offers to mask
$offers_to_mask = array_filter($acf_group_fields, function($value, $key){
if (!str_starts_with($key, "afficher_offre_"))
return false;
if ($value === "Masquer")
return true;
}, ARRAY_FILTER_USE_BOTH);
foreach($offers_to_mask as $key => $value){
$needle = str_replace( "afficher_", "",$key);
}
error_log("needle");
error_log($needle);
$to_mask = array_filter($acf_group_fields, function($value, $key){
if (str_starts_with($key, $needle))
return true;
}, ARRAY_FILTER_USE_BOTH);
// select only the acf fields "afficher_offre_*"
// $acf_offers = array_filter($acf_group_fields, function($field){
// $field_name = $field['name'];
// return str_starts_with($field_name, "afficher_offre_");
// });
// list of "afficher_offre_" for current post that are on "Masquer"
// error_log("---");
// $to_mask = array();
// foreach($acf_offers as $offer){
// $key = $offer['key'];
// error_log("key:");
// error_log($key);
// $field_value = get_field($key);
// error_log("field_value:");
// error_log($field_value);
// if ($field_value === 'Masquer') {
// $to_mask[] = $offer;
// }
// }
$output = $to_mask;
$fipfcard_project = new PLGNTLS_class();
return $fipfcard_project->add_to_front(
array(
"css/partenaires/partenaires.css",
"js/partenaires/switch_offers.js",
),
compact(
"output",
)
);
}
add_action('wp_footer', 'my_custom_js_function_PLGNTLS');
/*
in my_custom_df_form_handler
form_id
crea_partenaire
post_array
{
"post_status":"publish",
"field_title":
[
"Nom commercial",
"Votre site Internet",
"Dans quelle rubrique devez-vous para\u00eetre ? ",
"L\\'accroche en t\u00eate de page",
"Pr\u00e9sentez-vous",
"Votre logo ",
"Image principale",
"Titre",
"Texte de l\\'offre",
"Image (facultatif)",
"Voulez-vous ajouter une offre ?",
"Voulez-vous afficher cette offre ?",
"Titre",
"Texte de l\\'offre",
"Image (facultatif)",
"Voulez-vous ajouter une offre ?",
"Voulez-vous afficher l\\'offre ?",
"Titre",
"Texte de l\\'offre",
"Image (facultatif)"
],
"post_title":"test",
"meta_input":
[
"de_fb_url_partenaire",
"de_fb_logo_partenaire",
"de_fb_offre_1_titre",
"de_fb_offre_1_txt",
"de_fb_offre_1_image",
"de_fb_ajouter_offre_2",
"de_fb_afficher_offre_2",
"de_fb_offre_2_titre",
"de_fb_offre_2_txt",
"de_fb_offre_2_image",
"de_fb_ajouter_offre_3",
"de_fb_afficher_offre_3",
"de_fb_offre_3_titre",
"de_fb_offre_3_txt",
"de_fb_offre_3_image"
],
"url_partenaire":"",
"tax_input":["de_fb_project_category"],
"project_category":"hebergement",
"post_excerpt":"test",
"post_content":"test",
"_ajax_linking_nonce":"0e855ae1a9",
"logo_partenaire":"38157",
"post_thumbnail":"38156",
"offre_1_titre":"test",
"offre_1_txt":"test",
"offre_1_image":"",
"ajouter_offre_2":"Oui",
"afficher_offre_2":"Masquer",
"offre_2_titre":"test",
"offre_2_txt":"test",
"offre_2_image":"",
"ajouter_offre_3":"Non",
"offre_3_image":"",
"ID":"38158",
"form_type_confirm":""
}
form_type
project
-------------
in PLGNTLS_df_after_insert_post_handler
form_id
crea_partenaire
post_id
38158
post_array
{
"post_status":"publish",
"field_title":
[
1. "Nom commercial",
2. "Votre site Internet",
3. "Dans quelle rubrique devez-vous para\u00eetre ? ",
4. "L\\'accroche en t\u00eate de page",
5. "Pr\u00e9sentez-vous",
6. "Votre logo ",
7. "Image principale",
8. "Titre",
9. "Texte de l\\'offre",
10. "Image (facultatif)",
11. "Voulez-vous ajouter une offre ?",
12. "Voulez-vous afficher cette offre ?",
13. "Titre","Texte de l\\'offre",
14. "Image (facultatif)",
15. "Voulez-vous ajouter une offre ?",
16. "Voulez-vous afficher l\\'offre ?",
17. "Titre",
18. "Texte de l\\'offre",
19. "Image (facultatif)"
],
"post_title":"test",
"meta_input":
{
1. "url_partenaire":"",
2. "_url_partenaire":"field_65cb83096d020",
3. "logo_partenaire":"38157",
4. "_logo_partenaire":"field_65cb79150ac4f",
5. "offre_1_titre":"test",
6. "_offre_1_titre":"field_65d8bbf6b4651",
7. "offre_1_txt":"test",
8. "_offre_1_txt":"field_65d8bc395bf88",
9. "offre_1_image":"",
10. "_offre_1_image":"field_65d8bc5d5bf8b",
11. "ajouter_offre_2":"Oui",
12. "_ajouter_offre_2":"field_65d8c834e1ac9",
13. "afficher_offre_2":"Masquer",
14. "_afficher_offre_2":"field_65d8cf09395a5",
15. "offre_2_titre":"test",
16. "_offre_2_titre":"field_65d8bc201740b",
17. "offre_2_txt":"test",
18. "_offre_2_txt":"field_65d8bc4c5bf89",
19. "offre_2_image":"",
20. "_offre_2_image":"field_65d8bc6e5bf8c",
21. "ajouter_offre_3":"Non",
22. "_ajouter_offre_3":"field_65d8c880fb783",
23. "afficher_offre_3":[],
24. "offre_3_titre":[],
25. "offre_3_txt":[],
26. "offre_3_image":"",
27. "_offre_3_image":"field_65d8bc8c5bf8e"
},
"tax_input":{"project_category":[39]},
"post_excerpt":"test",
"post_content":"test",
"_ajax_linking_nonce":"0e855ae1a9",
"post_thumbnail":"38156",
"ID":"38158",
"form_type_confirm":"",
"post_type":"project",
"post_date":"2024-02-28 18:57:20"
}
*/
?>

View File

@@ -0,0 +1,15 @@
<?php
function add_partenaires_PLGNTLS($customer_data){
$current_url = $_SERVER['HTTP_REFERER'];
$path_brut = parse_url($current_url, PHP_URL_PATH);
$path = trim($path_brut, '/');
if ($path === 'creation-du-compte-partenaire')
$customer_data['role'] = 'partenaire';
return $customer_data;
}
add_filter( 'xoo_el_register_new_customer_data', 'add_partenaires_PLGNTLS', 10, 1 );
?>

View File

@@ -1,33 +0,0 @@
<?php
/**
* it means someone outside wp is accessing the file, in this case kill it.
*/
if (!defined('ABSPATH')) {
die('You can not access this file!');
}
function prevent_page_caching( $headers ) {
error_log("in prevent_page_caching");
if (is_page('test-form-modals')) {
error_log("in test-form-modals");
$headers['Cache-Control'] = 'no-cache, no-store, must-revalidate';
$headers['Pragma'] = 'no-cache';
$headers['Expires'] = '0';
}
return $headers;
}
add_filter( 'nocache_headers', 'prevent_page_caching' );
function add_custom_meta_tags() {
error_log("add_custom_meta_tags");
echo '<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">';
echo '<meta http-equiv="Pragma" content="no-cache">';
echo '<meta http-equiv="Expires" content="0">';
}
add_action('wp_head', 'add_custom_meta_tags');
?>

View File

@@ -1,74 +0,0 @@
<?php
/**
* it means someone outside wp is accessing the file, in this case kill it.
*/
if (!defined('ABSPATH')) {
die('You can not access this file!');
}
function fipfcard_test_class_tools()
{
$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();
$user_email = get_field('user_email', 'MarieM');
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",
"user_email",
"names",
"ages",
)
);
}
?>

View File

@@ -1,163 +0,0 @@
<?php
/**
* it means someone outside wp is accessing the file, in this case kill it.
*/
if (!defined('ABSPATH')) {
die('You can not access this file!');
}
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
function that add the ajax script to front
no real needs to check if already included :
- $handle is uniq so it will not be re-enqueued
the first enqueued version would be kept
- if we used add_var_to_front() (which use wp_add_inline_script())
the vars would be added twice
leading to js syntaxe error (redeclaraiton of 'let' or 'const')
- but we use wp_localize_script() so the object will be overwritten
it's not a real pbm
(what is more efficient, check for double or overwritte object ?)
*/
function fipfcard_add_ajax_post() {
global $fipfcard_first_script;
global $fipfcard_ajax_file;
$file = fipfcard_init_file($fipfcard_ajax_file);
// // check if ajax script was already enqueued
// global $wp_scripts;
// $already_enqueued = array_search($file->handle, $wp_scripts->queue);
// if ($already_enqueued !== false)
// return ;
$fipfcard_first_script = $file->handle;
wp_enqueue_script( $file->handle, $file->url, '', $file->version, true);
$_url = admin_url( 'admin-ajax.php' );
$_nonce = wp_create_nonce( 'wp-pageviews-nonce' );
$vars = compact("_url","_nonce",);
// add_var_to_front($vars);
$object_name = "fipfcard_ajax";
wp_localize_script($file->handle, $object_name, $vars);
}
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
@param string : name of the file, with its path from its extension directory
- from js/ root for .js files
- from css/ root for .css files
@return object / null :
- null if file is not js or css
- or an object with all the necessary infos :
- ext : name.js -> "js"
- basename : name.js -> "name"
- handle : name.js -> "name_js"
- url : url to file in wordpress
- path : path to file in server
- version : used to avoid browser caching
*/
function fipfcard_init_file($file_name) {
$file = (object)[];
$file->ext = pathinfo($file_name, PATHINFO_EXTENSION);
if ($file->ext === "js")
$dir_path = 'js/';
else if ($file->ext === "css")
$dir_path = 'css/';
else
return null;
$file->basename = pathinfo($file_name, PATHINFO_FILENAME);
$file->handle = str_replace(".", "_", $file_name);
$file->url = FIPFCARD_PLUGIN_URL.$dir_path.$file_name;
$file->path = FIPFCARD_PLUGIN_DIR.$dir_path.$file_name;
$file->version = date("ymd-Gis", filemtime($file->path));
return $file;
}
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
@param array : list of files :
- with their path from root of their type of file (ex: from js/ to .js files)
- and with their extension
@param boolean
- to add ajax script and variables
- default to true
*/
function fipfcard_add_files_to_front($files_arr, $add_ajax = true) {
//wp_enqueue_script(<give_it_a_name>, /url/to/file, [depends on], version, defer? );
//wp_enqueue_style( <give_it_a_name>, /url/to/file, [depends on], version, media );
global $fipfcard_first_script;
if ($add_ajax === true)
fipfcard_add_ajax_post();
$previous_css_basename = '';
$previous_js_basename = '';
foreach ($files_arr as $file_name) {
$file = fipfcard_init_file($file_name);
if ($file->ext === "js") {
if (is_null($fipfcard_first_script))
$fipfcard_first_script = $file->handle;
wp_enqueue_script( $file->handle, $file->url, $previous_js_basename, $file->version, true);
$previous_js_basename = $file->basename;
}
else if ($file->ext === "css") {
wp_enqueue_style( $file->handle, $file->url, $previous_css_basename, $file->version, '');
$previous_css_basename = $file->basename;
}
}
}
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
pass variables to js front as global variables
@param array : list of key => value
with the key being name of the variable, like this :
'my_var' => 'value',
simpler way to do it is to use compact when calling the function :
add_var_to_front(compact("var1", "var2", "var3"));
@param string (optionnal) : name of first embended script that need these variables
(it will be available to this script and all followings)
this name is the filename + "_" + extension :
init.js -> init_js
*/
function fipfcard_add_var_to_front($vars, $handle = null) {
if (is_null($handle)) {
global $fipfcard_first_script;
$handle = $fipfcard_first_script;
}
extract($vars);
foreach ($vars as $key => $var)
{
$js_var = 'let '.$key.' = '.json_encode($var).';';
wp_add_inline_script($handle, $js_var, 'before');
}
// the other way with localize has multiple incidences :
// - it creates an object from wich you can access the variables
// - so if you call it again wiht the same name, it will overwrite the previous
// {
// $handle = pathinfo($handle, PATHINFO_FILENAME);
// $object_name = "php_data";
//
// wp_localize_script($handle, $object_name, $vars);
// }
}
?>

View File

@@ -1,26 +0,0 @@
<?php
/**
* it means someone outside wp is accessing the file, in this case kill it.
*/
if (!defined('ABSPATH')) {
die('You can not access this file!');
}
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
https://stackify.com/how-to-log-to-console-in-php/
*/
function console_log(...$outputs) {
if (FIPFCARD_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

@@ -1,46 +0,0 @@
<?php
/**
* it means someone outside wp is accessing the file, in this case kill it.
*/
if (!defined('ABSPATH')) {
die('You can not access this file!');
}
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
@param two arguments :
1. html files to include in front
- can be a string of 1 filename
- or an array of strings of filenames
( https://stackoverflow.com/q/4747876/9497573 )
- it's probably better to only add 1 file, and let it include other files
2. list of variables to make available to this files
- in the form of key => val
- recommanded to do it with compact()
ex: create_html( "file.html", compact("var1","var2",) );
ex: create_html( array("file1.html", "file2.html"), array("var1"=>"value") );
@return a string of html code
using ob_start() and ob_get_clean()
allows to have php expansion inside the html loaded
in opposition to the methode file_get_contents()
https://stackoverflow.com/a/4402045/9497573
*/
function fipfcard_create_html($files, $vars = null) {
$files = (array)$files;
$html_dir = FIPFCARD_PLUGIN_DIR.'html/';
if (!is_null($vars))
extract($vars);
ob_start();
foreach($files as $file) {
include($html_dir.$file);
}
$html = ob_get_clean();
return $html;
}
?>

View File

@@ -1,55 +0,0 @@
<?php
/**
* it means someone outside wp is accessing the file, in this case kill it.
*/
if (!defined('ABSPATH')) {
die('You can not access this file!');
}
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
globals variables
const vs define : https://stackoverflow.com/questions/2447791/php-define-vs-const
*/
/* switch console_log
const CONSOLE_OFF = true;
*/
const FIPFCARD_CONSOLE_OFF = false;
/**
* a variable that will contain the name of the first script enqueued
*/
$fipfcard_first_script = null;
/**
* path to ajax.js file, from root of js dir
*/
$fipfcard_ajax_file = "utils/ajax.js";
/**
* 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";
?>