wip trying to force the acf id that formbuilder will use

This commit is contained in:
asus
2024-03-14 23:28:37 +01:00
parent 70888d384c
commit 9ebce56025
6 changed files with 149 additions and 35 deletions

View File

@@ -12,6 +12,106 @@ if (!defined('ABSPATH')) {
// 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