- 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,7 +0,0 @@
.first_el_to_change {
border: 1px solid red;
}
#model_plugin_shortcode {
border: 1px solid blue;
padding: 10px;
}

View File

@@ -27,17 +27,12 @@ PLGNTLS_class::set_root_dir( plugin_dir_path(__FILE__), plugin_dir_url(__FILE__)
/*
* general inclusions
*/
include_once(PLGNTLS_class::get_path() . '/php/utils/globals.php');
include_once(PLGNTLS_class::get_path() . '/php/utils/console_log.php');
//include_once(PLGNTLS_class::get_path() . '/php/images/image_edit_shortcode.php');
//include_once(PLGNTLS_class::get_path() . '/php/images/image-edit.php');
//include_once(PLGNTLS_class::get_path() . '/php/test_cache.php');
include_once(PLGNTLS_class::get_path() . '/utils/globals.php');
include_once(PLGNTLS_class::get_path() . '/utils/console_log.php');
include_once(PLGNTLS_class::get_path() . '/php/paypal/paypal.php');
include_once(PLGNTLS_class::get_path() . '/php/partenaires/partenaires.php');
include_once(PLGNTLS_class::get_path() . '/php/register/partenaires.php');

View File

@@ -1,70 +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>get_field('user_email') :</p>
<p>
<?php echo $user_email ?>
</p>
<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 @@
<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;

View File

@@ -1,2 +0,0 @@
console.log("PLGNTLS_data.output :");
console.log(PLGNTLS_data.output);

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,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,117 +0,0 @@
/**
* function that create an ajax post action
* - PLGNTLS_data.ajax_nonce and PLGNTLS_data.ajax_url
* are passed from the class PLGNTLS_class
*/
/*
// OLD VERSION
console.log("PLGNTLS_data");
console.log(PLGNTLS_data);
*/
function PLGNTLS_ajax(action, data_obj) {
const data = new FormData();
data.append("action", action);
data.append("_ajax_nonce", PLGNTLS_data.ajax_nonce);
// for (const key in data_obj)
// {
// data.append(key, data_obj[key]);
// }
// console.log("data:", data);
data.append(data_obj);
return fetch(PLGNTLS_data.ajax_url, {
method: "POST",
credentials: "same-origin",
hedears: {"Content-Type": "application/json"},
body: JSON.stringify(data),
});
}
// https://stackoverflow.com/q/52657814/9497573
function is_plain_object(obj)
{
if (!obj)
return false;
if (obj.constructor !== Object)
return false;
if (Object.getPrototypeOf(obj) !== Object.prototype)
return false;
return true;
}
/*
function PLGNTLS_fetch(src = null, options = null)
{
if (src === null)
return null;
if (options === null)
{
const data = new FormData();
data.append('action', src);
data.append('_ajax_nonce', PLGNTLS_data.ajax_nonce);
options = {
method: 'POST',
credentials: 'same-origin',
body: data,
};
}
else if (is_plain_object(options))
{
// check for method, default POST
if (!Object.hasOwn(options, 'method'))
options.method = 'POST';
// check for credentials, default same-origin
if (!Object.hasOwn(options, 'credentials'))
options.credentials = 'same-origin';
// check for body, default contains action and nonce
if (!Object.hasOwn(options, 'body'))
options.body = new FormData();
// add action and nonce in options.body
if (options.body instanceof FormData)
{
// dont check if action and nonce already exist, need new anyway
options.body.set('action', src);
options.body.set('_ajax_nonce', PLGNTLS_data.ajax_nonce);
}
else
{
// should think a better strategy : https://stackoverflow.com/q/20295080/9497573
// const data = {};
// if (is_plain_object(options.body))
// {
// for (const key in options.body)
// data[key] = options.body[key];
// }
// else
// data.data = options.body;
// data.action = src;
// data._ajax_nonce = PLGNTLS_data.ajax_nonce;
// options.body = JSON.stringify(data);
// cannot work if fetch use :
// headers: {"Content-Type": "application/json"},
const data = new FormData( );
data.append( 'action', src );
data.append( '_ajax_nonce', PLGNTLS_data.ajax_nonce );
if ( is_plain_object( options.body ) )
{
for ( const key in options.body )
data.append( key, JSON.stringify(options.body[key]) );
}
// is string : https://stackoverflow.com/q/4059147/9497573
else if ( typeof options.body === 'string' || options.body instanceof String )
data.append( 'data', options.body );
else
data.append('data', JSON.stringify(options.body));
options.body = data;
}
}
else
throw new Error('options not plain object or formData');
return fetch(PLGNTLS_data.ajax_url, options);
}
*/

Submodule private updated: 8bb03bf518...8b8c17b979