70 lines
1.8 KiB
PHP
70 lines
1.8 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');
|
|
*/
|
|
|
|
|
|
?>
|