Files
2024_WEBSITE_fipf/plugins/cipf_plugin/php/admin_modif_prof.php

287 lines
7.6 KiB
PHP

<?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 into the ACF field retrieval process
/*
function test_acfs_CIPF($fields, $id) {
error_log("--- fields");
error_log("fields");
error_log(json_encode($fields));
error_log("id");
error_log($id);
return $fields;
}
function test_acf_CIPF($field, $id) {
error_log("--- " . $field['name']);
if ($field['name'] !== 'compte-actif')
return $field;
error_log("acf hook");
error_log("field");
error_log(json_encode($field));
error_log("_GET");
error_log(json_encode($_GET));
// // Check if we are targeting a specific ACF field and user
// if ($field_key === 'your_field_key' && isset($_GET['user_id'])) {
// $user_id = $_GET['user_id']; // Get the user ID from the query parameters
//
// // Retrieve the ACF field object for the specified user
// $user_field = get_field_object($field_key, 'user_' . $user_id);
//
// if ($user_field) {
// return $user_field; // Return the ACF field object for the specified user
// }
// }
//
// // If not targeting a specific user, return the original field
return $field;
}
add_filter('acf/pre_render_field', 'test_acf_CIPF', 10, 2);
add_filter('acf/pre_render_fields', 'test_acfs_CIPF', 10, 2);
*/
/*
add_filter('acf/load_field', 'test_acf_CIPF');
*/
/*
{"ID":40341,"key":"field_65e8acd5c2065","label":"Activation du compte","name":"compte-actif","aria-label":"","prefix":"acf","type":"radio","value":null,"menu_order":1,"instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":34538,"wrapper":{"width":"","class":"","id":""},"choices":{"Actif":"Actif","Inactif":"Inactif"},"default_value":"","return_format":"value","allow_null":0,"other_choice":0,"layout":"vertical","save_other_choice":0,"_name":"compte-actif","_valid":1}
*/
function test_acf_CIPF($acf_id, $id) {
PLGNTLS_class::debug_infos();
error_log("acf_id: " . $acf_id . ", id : " . $id);
if ($id === null) {
return null;
}
return 'user_'.$id;
}
function choose_acf_id_CIPF($options) {
PLGNTLS_class::debug_infos();
$shortcode_choose_acf_id = PLGNTLS_class::SHORTCODE_CHOOSE_ACF_ID;
$option = reset($options);
if (!is_string($option)) {
return;
}
if ($option === $shortcode_choose_acf_id['logged_in']) {
$id = get_current_user_id();
}
else if ($option === $shortcode_choose_acf_id['post_creator']) {
$id = get_queried_object_id();
}
else if ($option === $shortcode_choose_acf_id['off']) {
$id = null;
}
else
return;
/*
* this filter is called by acf to find the id to use
* with functions like get_field()
*
*/
add_filter('acf/pre_load_post_id', function($null, $acf_id) use ($id) {
return test_acf_CIPF($acf_id, $id);
}, 10, 2);
}
add_shortcode('cipf_choose_acf_id', 'choose_acf_id_CIPF');
// $new_body = preg_replace_callback($pattern, function($matches) use ($id) {
// return replace_words_CIPF($matches, $id);
/*
* custom action in php on custom form submission
* custom forms are not processed by divi form builder
* so they don't change between hooks before and after process
*
*/
function admin_validate_prof_CIPF($data) {
PLGNTLS_class::debug_infos();
$acf_prof_is_activ = PLGNTLS_class::ACF_PROF_IS_ACTIV;
if (empty($data))
redirection_profil_CIPF();
error_log("---");
error_log("data");
error_log(json_encode($data));
if (!isset($data[$acf_prof_is_activ['_name']]))
redirection_profil_CIPF();
$is_activ = $data[$acf_prof_is_activ['_name']];
error_log("is_activ");
error_log($is_activ);
}
/*
* version 3 : ABANDONNED
* calling the action to validate from the FormBuilder hook
*
function custom_form_admin_validate_prof_CIPF($form_id, $post_array, $form_type) {
PLGNTLS_class::debug_infos();
$admin_validate_prof_field = PLGNTLS_class::ADMIN_VALIDATE_PROF_FIELD;
if ($form_type !== 'custom')
return;
$field_id = $post_array['field_id'];
$contains_id = in_array($admin_validate_prof_field, $field_id);
if ($contains_id === false)
return;
admin_validate_prof_CIPF($post_array);
}
add_action('df_before_process', 'custom_form_admin_validate_prof_CIPF', 10, 3);
*/
/*
* version 4 :
* calling the action to validate from the url query
*
*/
//function url_custom_form_admin_validate_prof_CIPF() {
// PLGNTLS_class::debug_infos();
// $slug_admin_validate_prof = PLGNTLS_class::SLUG_ADMIN_VALIDATE_PROF;
//
// if (!isset($_GET['q']))
// return;
//
// /*
// * check the request /path/
// * for url : https://url.com/path/to/file/?query=value
// * -> $_GET: {"q":"/path/to/file/","query":"value"}
// *
// */
// $get_path = trim($_GET['q'], '/');
// if ($get_path !== $slug_admin_validate_prof)
// return;
//
// admin_validate_prof_CIPF($_POST);
//}
//add_action('init', 'url_custom_form_admin_validate_prof_CIPF');
/*
_POST :
{"field_title":["\u00c9tat du compte"],"field_name":["compte-actif"],"field_id":["cipf_admin_activate_prof"],"compte-actif":"Inactif","form_key":"40781-1","unique_id":"91eed9aa-2b92-4da7-a0b4-e94f24515223","form_type":"custom","divi-form-submit":"yes","form_id":"","form_type_confirm":""}
{
"field_title":["\u00c9tat du compte"],
"field_name":["compte-actif"],
"field_id":["cipf_admin_activate_prof"],
"compte-actif":"Inactif",
- "form_key":"40781-1",
- "unique_id":"91eed9aa-2b92-4da7-a0b4-e94f24515223",
- "form_type":"custom",
- "divi-form-submit":"yes",
- "form_id":"",
"form_type_confirm":""
}
---
post_array :
{"field_title":["\u00c9tat du compte"],"field_name":["compte-actif"],"field_id":["cipf_admin_activate_prof"],"compte-actif":"Inactif","form_type_confirm":""}
{
"field_title":["\u00c9tat du compte"],
"field_name":["compte-actif"],
"field_id":["cipf_admin_activate_prof"],
"compte-actif":"Inactif",
"form_type_confirm":""
}
*/
/*
* version 2 : ABANDONNED
* tried to receive the form in ajax from front with wp REST API
* but I cannot verify if the user is logged in
* so it does not work
*
*/
//function admin_validate_prof_form_CIPF($request) {
// PLGNTLS_class::debug_infos();
// $slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION;
//
// error_log("-----");
// error_log("inside admin_validate_prof_form_CIPF");
// error_log("request");
// error_log(json_encode($request));
// error_log("_POST");
// error_log(json_encode($_POST));
// // _POST : {"field_title":["\u00c9tat du compte"],"field_name":["compte-actif"],"field_id":["cipf_admin_activate_prof"],"form_key":"40781-1","unique_id":"91eed9aa-2b92-4da7-a0b4-e94f24515223","form_type":"custom","divi-form-submit":"yes","form_id":"","form_type_confirm":""}
//
// // Set up nocache headers before redirecting : https://developer.wordpress.org/reference/functions/wp_safe_redirect/#user-contributed-notes
// nocache_headers();
// $redirect_url = home_url() . '/' . $slug_page_redirection;
// wp_redirect($redirect_url, 301);
// exit;
//}
//function endpoint_form_admin_activate_prof_CIPF() {
// PLGNTLS_class::debug_infos();
// $base_rest_route = PLGNTLS_class::URL_BASE_REST_ROUTE;
//
// register_rest_route($base_rest_route, '/admin_prof_activate_form', array(
// 'methods' => 'POST',
// 'callback' => 'admin_validate_prof_form_CIPF',
// ));
//};
//add_action('rest_api_init', 'endpoint_form_admin_activate_prof_CIPF');
/*
* version 1 : ABANDONNED
* enqueue script that should prevent the form to submit, but does not work
*
*/
//function admin_validate_prof_prevent_CIPF() {
// PLGNTLS_class::debug_infos();
// $handle = 'admin_prevent_submit';
// $url = PLGNTLS_class::root_url() . 'js/admin_prevent_submit.js';
// $dependencies = array();
// $version = null;
// $defer = true;
// wp_enqueue_script($handle, $url, $dependencies, $version, $defer);
//}
//add_action('wp_enqueue_scripts', 'admin_validate_prof_prevent_CIPF');
?>