fixed pbm with field update prevention, but not sure if robust

This commit is contained in:
asus
2024-04-18 14:18:19 +02:00
parent 782d45f115
commit f2bcc51ec0

View File

@@ -10,16 +10,16 @@ if (!defined('ABSPATH')) {
/*
{"ID":43757,"key":"field_6617daff359b2","label":"rappels emails","name":"rappels_emails","aria-label":"","prefix":"acf", "type":"checkbox", "value":null,"menu_order":0,"instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"hide_group_for_fipfrole_cipf read_only_cipf","id":""},"choices":{"card_expiration \/ -30 days":"PROF EXPIRATION - rappel email 1 mois avant expiration de la carte","card_expiration \/ -7 days":"PROF EXPIRATION - rappel email 7 jours avant expiration de la carte","card_expired":"PROF EXPIRATION - email quand la carte a expir\u00e9","account_deletion \/ -30 days":"PROF SUPPRESSION - rappel email 1 mois avant suppression du compte","account_deletion \/ -7 days":"PROF SUPPRESSION - rappel email 7 jours avant suppression du compte","offer_expiration_1 \/ -7 days":"PARTENAIRE EXPIRATION 1 - rappel email 7 jours avant expiration d'une offre","offer_expiration_2 \/ -7 days":"PARTENAIRE EXPIRATION 2 - rappel email 7 jours avant expiration d'une offre","offer_expiration_3 \/ -7 days":"PARTENAIRE EXPIRATION 3 - rappel email 7 jours avant expiration d'une offre"},"default_value":[],"return_format":"label","allow_custom":0,"layout":"vertical","toggle":0,"save_custom":0,"custom_choice_button_text":"Add new choice","_name":"rappels_emails","_valid":1}
{"ID":43880,"key":"field_66200b6283912","label":"text_readonly","name":"text_readonly","aria-label":"","prefix":"acf", "type":"text", "value":null,"menu_order":1,"instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"default_value":"","maxlength":"","placeholder":"","prepend":"","append":"","_name":"text_readonly","_valid":1}
{"ID":43881,"key":"field_66200c4383914","label":"textarea_readonly","name":"textarea_readonly","aria-label":"","prefix":"acf","type":"textarea", "value":null,"menu_order":2,"instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"default_value":"","maxlength":"","rows":"","placeholder":"","new_lines":"","_name":"textarea_readonly","_valid":1}
{"ID":43882,"key":"field_66200b7f83913","label":"number_readonly","name":"number_readonly","aria-label":"","prefix":"acf", "type":"number", "value":null,"menu_order":3,"instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"default_value":"","min":"","max":"","placeholder":"","step":"","prepend":"","append":"","_name":"number_readonly","_valid":1}
{"ID":43883,"key":"field_66200d7583916","label":"range_readonly","name":"range_readonly","aria-label":"","prefix":"acf", "type":"range", "value":null,"menu_order":4,"instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"default_value":"","min":"","max":"","step":"","prepend":"","append":"","_name":"range_readonly","_valid":1}
{"ID":43884,"key":"field_66200da983917","label":"email_readonly","name":"email_readonly","aria-label":"","prefix":"acf", "type":"email", "value":null,"menu_order":5,"instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"default_value":"","placeholder":"","prepend":"","append":"","_name":"email_readonly","_valid":1}
{"ID":43885,"key":"field_66200dbd83918","label":"url_readonly","name":"url_readonly","aria-label":"","prefix":"acf", "type":"url", "value":null,"menu_order":6,"instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"default_value":"","placeholder":"","_name":"url_readonly","_valid":1}
{"ID":43886,"key":"field_66200dfb83919","label":"password_readonly","name":"password_readonly","aria-label":"","prefix":"acf","type":"password", "value":null,"menu_order":7,"instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"placeholder":"","prepend":"","append":"","_name":"password_readonly","_valid":1}
{"ID":43887,"key":"field_66200e0d8391a","label":"image_readonly","name":"image_readonly","aria-label":"","prefix":"acf", "type":"image", "value":null,"menu_order":8,"instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"return_format":"array","library":"all","min_width":"","min_height":"","min_size":"","max_width":"","max_height":"","max_size":"","mime_types":"","preview_size":"medium","_name":"image_readonly","_valid":1}
{"ID":43888,"key":"field_66201a805f90d","label":"file","name":"file","aria-label":"","prefix":"acf", "type":"file", "value":null,"menu_order":9,"instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"return_format":"array","library":"all","min_size":"","max_size":"","mime_types":"","_name":"file","_valid":1}
{"ID":43757,"key":"field_6617daff359b2","label":"rappels emails","name":"rappels_emails","aria-label":"","prefix":"acf", "type":"checkbox", "value":null,"menu_order":0, "instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"hide_group_for_fipfrole_cipf read_only_cipf","id":""},"choices":{"card_expiration \/ -30 days":"PROF EXPIRATION - rappel email 1 mois avant expiration de la carte","card_expiration \/ -7 days":"PROF EXPIRATION - rappel email 7 jours avant expiration de la carte","card_expired":"PROF EXPIRATION - email quand la carte a expir\u00e9","account_deletion \/ -30 days":"PROF SUPPRESSION - rappel email 1 mois avant suppression du compte","account_deletion \/ -7 days":"PROF SUPPRESSION - rappel email 7 jours avant suppression du compte","offer_expiration_1 \/ -7 days":"PARTENAIRE EXPIRATION 1 - rappel email 7 jours avant expiration d'une offre","offer_expiration_2 \/ -7 days":"PARTENAIRE EXPIRATION 2 - rappel email 7 jours avant expiration d'une offre","offer_expiration_3 \/ -7 days":"PARTENAIRE EXPIRATION 3 - rappel email 7 jours avant expiration d'une offre"},"default_value":[],"return_format":"label","allow_custom":0,"layout":"vertical","toggle":0,"save_custom":0,"custom_choice_button_text":"Add new choice","_name":"rappels_emails","_valid":1}
{"ID":43880,"key":"field_66200b6283912","label":"text_readonly","name":"text_readonly","aria-label":"","prefix":"acf", "type":"text", "value":null,"menu_order":1, "instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"default_value":"","maxlength":"","placeholder":"","prepend":"","append":"","_name":"text_readonly","_valid":1}
{"ID":43881,"key":"field_66200c4383914","label":"textarea_readonly","name":"textarea_readonly","aria-label":"","prefix":"acf","type":"textarea", "value":null,"menu_order":2, "instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"default_value":"","maxlength":"","rows":"","placeholder":"","new_lines":"","_name":"textarea_readonly","_valid":1}
{"ID":43882,"key":"field_66200b7f83913","label":"number_readonly","name":"number_readonly","aria-label":"","prefix":"acf", "type":"number", "value":null,"menu_order":3, "instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"default_value":"","min":"","max":"","placeholder":"","step":"","prepend":"","append":"","_name":"number_readonly","_valid":1}
{"ID":43883,"key":"field_66200d7583916","label":"range_readonly","name":"range_readonly","aria-label":"","prefix":"acf", "type":"range", "value":null,"menu_order":4, "instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"default_value":"","min":"","max":"","step":"","prepend":"","append":"","_name":"range_readonly","_valid":1}
{"ID":43884,"key":"field_66200da983917","label":"email_readonly","name":"email_readonly","aria-label":"","prefix":"acf", "type":"email", "value":null,"menu_order":5, "instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"default_value":"","placeholder":"","prepend":"","append":"","_name":"email_readonly","_valid":1}
{"ID":43885,"key":"field_66200dbd83918","label":"url_readonly","name":"url_readonly","aria-label":"","prefix":"acf", "type":"url", "value":null,"menu_order":6, "instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"default_value":"","placeholder":"","_name":"url_readonly","_valid":1}
{"ID":43886,"key":"field_66200dfb83919","label":"password_readonly","name":"password_readonly","aria-label":"","prefix":"acf","type":"password", "value":null,"menu_order":7, "instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"placeholder":"","prepend":"","append":"","_name":"password_readonly","_valid":1}
{"ID":43887,"key":"field_66200e0d8391a","label":"image_readonly","name":"image_readonly","aria-label":"","prefix":"acf", "type":"image", "value":null,"menu_order":8, "instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"return_format":"array","library":"all","min_width":"","min_height":"","min_size":"","max_width":"","max_height":"","max_size":"","mime_types":"","preview_size":"medium","_name":"image_readonly","_valid":1}
{"ID":43888,"key":"field_66201a805f90d","label":"file","name":"file","aria-label":"","prefix":"acf", "type":"file", "value":null,"menu_order":9, "instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"return_format":"array","library":"all","min_size":"","max_size":"","mime_types":"","_name":"file","_valid":1}
{"ID":43889,"key":"field_66201a955f90e","label":"wysiwyg","name":"wysiwyg","aria-label":"","prefix":"acf", "type":"wysiwyg", "value":null,"menu_order":10,"instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"default_value":"","tabs":"all","toolbar":"full","media_upload":1,"delay":0,"_name":"wysiwyg","_valid":1}
{"ID":43890,"key":"field_66201aa45f90f","label":"oembed","name":"oembed","aria-label":"","prefix":"acf", "type":"oembed", "value":null,"menu_order":11,"instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"width":"","height":"","_name":"oembed","_valid":1}
{"ID":43891,"key":"field_66201aad5f910","label":"select","name":"select","aria-label":"","prefix":"acf", "type":"select", "value":null,"menu_order":12,"instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"choices":{"one":"one","two":"two"},"default_value":false,"return_format":"value","multiple":0,"allow_null":0,"ui":0,"ajax":0,"placeholder":"","_name":"select","_valid":1}
@@ -92,16 +92,18 @@ if (!defined('ABSPATH')) {
/*
* checks if the acf field contains the class 'read_only_cipf'
* checks if the acf field wrapper contains the class 'read_only_cipf'
*
*/
function is_acf_field_disabled($field) {
function contains_class_disabled_CIPF($field) {
Plgntls::debug_infos();
if (!isset($field['wrapper'])) {
error_log("the acf field should have property field['wrapper']: " . json_encode($field));
return false;
}
if (!isset($field['wrapper']['class'])) {
error_log("the acf field should have property field['wrapper']['class']: " . json_encode($field));
return false;
}
$class = $field['wrapper']['class'];
@@ -112,25 +114,13 @@ function is_acf_field_disabled($field) {
return true;
}
/*
* if acf field has class to be disabled,
* -> add a disabled value to object after it is loaded
* -> the way to do it depends on the field type
* -> for the fields that dont have a default mechanisme :
* - add 'client_side_disabled'
* - then use other filters to complete the work : 'acf/field_wrapper_attributes' and 'acf/pre_update_value'
* checks if the acf field can be disabled
* by using a simple booleen 'disabled' property in the field object
*
*/
function disable_acf_field_CIPF($field) {
function acf_field_can_be_disabled_booleen_CIPF($field) {
Plgntls::debug_infos();
if (!is_acf_field_disabled($field)) {
return $field;
}
$type = $field['type'];
if (in_array($type, array(
'text',
@@ -143,12 +133,67 @@ function disable_acf_field_CIPF($field) {
'time_picker',
'select',
))) {
$field['disabled'] = 1;
return true;
}
else if (in_array($type, array(
return false;
}
/*
* checks if the acf field can be disabled
* by using an array as 'disabled' property in the field object
*
*/
function acf_field_can_be_disabled_array_CIPF($field) {
Plgntls::debug_infos();
$type = $field['type'];
if (in_array($type, array(
'checkbox',
'radio',
))) {
return true;
}
return false;
}
/*
* check if acf field can be disabled
* whatever the method
*
*/
function acf_field_can_be_disabled_CIPF($field) {
Plgntls::debug_infos();
if (acf_field_can_be_disabled_booleen_CIPF($field)) {
return true;
}
if (acf_field_can_be_disabled_array_CIPF($field)) {
return true;
}
return false;
}
/*
* if acf field has class to be disabled,
* -> add a disabled value to object after it is loaded
* -> the way to do it depends on the field type
* -> for the fields that dont have a default mechanisme :
* - add 'inert' class to wrapper if not alreadt there
* - then use other filters to complete the work : 'acf/field_wrapper_attributes' and 'acf/pre_update_value'
*
*/
function disable_acf_field_CIPF($field) {
Plgntls::debug_infos();
if (!contains_class_disabled_CIPF($field)) {
return $field;
}
if (acf_field_can_be_disabled_booleen_CIPF($field)) {
$field['disabled'] = 1;
}
else if (acf_field_can_be_disabled_array_CIPF($field)) {
if (!isset($field['choices'])) {
return $field;
}
@@ -158,9 +203,6 @@ function disable_acf_field_CIPF($field) {
$to_disable = array_map(function($e){return (string)$e;}, $to_disable);
$field['disabled'] = $to_disable;
}
else {
$field['client_side_disabled'] = 1;
}
return $field;
}
@@ -171,8 +213,7 @@ add_filter('acf/load_field', 'disable_acf_field_CIPF');
/*
* filter the wrapper of the acf field
* if it has the property 'client_side_disabled',
* if wrapper class contains 'inert',
* -> add inert attribute : it will prevent any action from front,
* -> but it will not prevent from being saved with form
* -> see filter 'acf/pre_update_value' for that
@@ -182,11 +223,13 @@ add_filter('acf/load_field', 'disable_acf_field_CIPF');
function change_acf_field_wrapper_CIPF($wrapper, $field) {
Plgntls::debug_infos();
if (!isset($field['client_side_disabled'])) {
if (!contains_class_disabled_CIPF($field)) {
return $wrapper;
}
if (acf_field_can_be_disabled_CIPF($field)) {
return $wrapper;
}
error_log("+field: " . json_encode($field));
$wrapper["inert"] = "true";
return $wrapper;
}
@@ -196,24 +239,28 @@ add_filter('acf/field_wrapper_attributes', 'change_acf_field_wrapper_CIPF', 10,
/*
* if acf field has class to be disabled
* -> and _POST[acf] is set : it means it comes from front
* -> dont update the values
* -> should work for all acf fields
* 200 : ../../../wordpress_docker/volumes/wp_volume/wp-content/plugins/advanced-custom-fields/includes/acf-value-functions.php
* this is the filter that prevent acf fields from beeing
*
* if _POST[acf] not set, field is not updated from front, so don't prevent update
* if field does not contains class 'disabled' (or whatever it is), don't prevent update
* if field can use a native acf way to be disabled, don't prevent update
*
* -> 200 : ../../../wordpress_docker/volumes/wp_volume/wp-content/plugins/advanced-custom-fields/includes/acf-value-functions.php
*
*/
function disable_all_acf_field_CIPF($null, $value, $post_id, $field) {
function prevent_acf_field_from_updating_CIPF($null, $value, $post_id, $field) {
Plgntls::debug_infos();
if (isset($field['client_side_disabled'])) {
return false;
if (!isset($_POST['acf'])) {
return $null;
}
if (!contains_class_disabled_CIPF($field)) {
return $null;
}
return $null;
return false;
}
add_filter('acf/pre_update_value', 'disable_all_acf_field_CIPF', 10, 4);
add_filter('acf/pre_update_value', 'prevent_acf_field_from_updating_CIPF', 10, 4);