226 lines
5.3 KiB
PHP
226 lines
5.3 KiB
PHP
<?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"
|
|
}
|
|
*/
|
|
|
|
?>
|