added a way to disable any acf fields

This commit is contained in:
asus
2024-04-18 10:58:53 +02:00
parent b059101f15
commit 782d45f115
3 changed files with 158 additions and 296 deletions

View File

@@ -8,6 +8,87 @@ 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":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}
{"ID":43892,"key":"field_66201ac05f911","label":"checkbox","name":"checkbox","aria-label":"","prefix":"acf", "type":"checkbox", "value":null,"menu_order":13,"instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"choices":{"one":"one","two":"two"},"default_value":[],"return_format":"value","allow_custom":0,"layout":"vertical","toggle":0,"save_custom":0,"custom_choice_button_text":"Add new choice","_name":"checkbox","_valid":1}
{"ID":43893,"key":"field_66201ad25f912","label":"radio","name":"radio","aria-label":"","prefix":"acf", "type":"radio", "value":null,"menu_order":14,"instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"choices":{"one":"one","two":"two"},"default_value":"","return_format":"value","allow_null":0,"other_choice":0,"layout":"vertical","save_other_choice":0,"_name":"radio","_valid":1}
{"ID":43894,"key":"field_66201adb5f913","label":"button group","name":"button_group","aria-label":"","prefix":"acf", "type":"button_group","value":null,"menu_order":15,"instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"choices":{"one":"one","two":"two"},"default_value":"","return_format":"value","allow_null":0,"layout":"horizontal","_name":"button_group","_valid":1}
{"ID":43895,"key":"field_66201ae95f914","label":"true-false","name":"true-false","aria-label":"","prefix":"acf", "type":"true_false", "value":null,"menu_order":16,"instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"message":"message","default_value":0,"ui":0,"ui_on_text":"","ui_off_text":"","_name":"true-false","_valid":1}
{"ID":43896,"key":"field_66201af35f915","label":"link","name":"link","aria-label":"","prefix":"acf", "type":"link", "value":null,"menu_order":17,"instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"return_format":"array","_name":"link","_valid":1}
{"ID":43897,"key":"field_66201b015f916","label":"post object","name":"post_object","aria-label":"","prefix":"acf", "type":"post_object", "value":null,"menu_order":18,"instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"post_type":"","post_status":"","taxonomy":"","return_format":"object","multiple":0,"allow_null":0,"bidirectional":0,"ui":1,"bidirectional_target":[],"_name":"post_object","_valid":1}
{"ID":43898,"key":"field_66201b0c5f917","label":"page link","name":"page_link","aria-label":"","prefix":"acf", "type":"page_link", "value":null,"menu_order":19,"instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"post_type":"","post_status":"","taxonomy":"","allow_archives":1,"multiple":0,"allow_null":0,"_name":"page_link","_valid":1}
{"ID":43899,"key":"field_66201b1a5f918","label":"relationship","name":"relationship","aria-label":"","prefix":"acf", "type":"relationship","value":null,"menu_order":20,"instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"post_type":"","post_status":"","taxonomy":"","filters":["search","post_type","taxonomy"],"return_format":"object","min":"","max":"","elements":"","bidirectional":0,"bidirectional_target":[],"_name":"relationship","_valid":1}
{"ID":43900,"key":"field_66201b275f919","label":"taxonomy","name":"taxonomy","aria-label":"","prefix":"acf", "type":"taxonomy", "value":null,"menu_order":21,"instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"taxonomy":"category","add_term":1,"save_terms":0,"load_terms":0,"return_format":"id","field_type":"checkbox","bidirectional":0,"multiple":0,"allow_null":0,"bidirectional_target":[],"_name":"taxonomy","_valid":1}
{"ID":43901,"key":"field_66201b335f91a","label":"user","name":"user","aria-label":"","prefix":"acf", "type":"user", "value":null,"menu_order":22,"instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"role":"","return_format":"array","multiple":0,"allow_null":0,"bidirectional":0,"bidirectional_target":[],"_name":"user","_valid":1}
{"ID":43902,"key":"field_66201b3f5f91b","label":"gmap","name":"gmap","aria-label":"","prefix":"acf", "type":"google_map", "value":null,"menu_order":23,"instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"center_lat":-37,"center_lng":144,"zoom":"","height":"","_name":"gmap","_valid":1}
{"ID":43903,"key":"field_66201b4c5f91c","label":"date picker","name":"date_picker","aria-label":"","prefix":"acf", "type":"date_picker", "value":null,"menu_order":24,"instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"display_format":"d\/m\/Y","return_format":"d\/m\/Y","first_day":1,"_name":"date_picker","_valid":1}
{"ID":43904,"key":"field_66201b565f91d","label":"ate time picker","name":"ate_time_picker","aria-label":"","prefix":"acf", "type":"date_picker", "value":null,"menu_order":25,"instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"display_format":"d\/m\/Y","return_format":"d\/m\/Y","first_day":1,"_name":"ate_time_picker","_valid":1}
{"ID":43905,"key":"field_66201b5e5f91e","label":"time picker","name":"time_picker","aria-label":"","prefix":"acf", "type":"time_picker", "value":null,"menu_order":26,"instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"display_format":"g:i a","return_format":"g:i a","_name":"time_picker","_valid":1}
{"ID":43906,"key":"field_66201b685f91f","label":"color picker","name":"color_picker","aria-label":"","prefix":"acf", "type":"color_picker","value":null,"menu_order":27,"instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"default_value":"","enable_opacity":0,"return_format":"string","_name":"color_picker","_valid":1}
{"ID":43907,"key":"field_66201b745f920","label":"message","name":"","aria-label":"","prefix":"acf", "type":"message", "value":false,"menu_order":28,"instructions":"","required":0,"id":"","class":"","conditional_logic":0,"parent":43775,"wrapper":{"width":"","class":"read_only_cipf","id":""},"message":"message","new_lines":"wpautop","esc_html":0,"_name":"","_valid":1}
-> $field['disabled'] = 1;
27. [/] text class-acf-field-text.php* : <input type="text" id="acf-field_66200b6283912" name="acf[field_66200b6283912]">
28. [/] textarea class-acf-field-textarea.php* : <textarea id="acf-field_66200c4383914" name="acf[field_66200c4383914]" rows="8"></textarea>
14. [/] number class-acf-field-number.php* : <input type="number" id="acf-field_66200b7f83913" name="acf[field_66200b7f83913]" step="any">
7. [/] email class-acf-field-email.php* : <input type="email" id="acf-field_66200da983917" name="acf[field_66200da983917]">
31. [/] url class-acf-field-url.php* : <input type="url" id="acf-field_66200dbd83918" name="acf[field_66200dbd83918]">
18. [x] password (text) class-acf-field-password.php* : <input type="password" id="acf-field_66200dfb83919" name="acf[field_66200dfb83919]">
5. [/] date_picker class-acf-field-date_picker.php* : <input type="text" class="input hasDatepicker" value="" id="dp1713386193796">
6. [/] date_picker class-acf-field-date_time_picker.php* : <input type="text" class="input hasDatepicker" value="" id="dp1713386193797">
29. [/] time_picker class-acf-field-time_picker.php* : <input type="text" class="input hasDatepicker" value="" id="dp1713386193798">
23. [/] select class-acf-field-select.php* : <select id="acf-field_66201aad5f910" class="" name="acf[field_66201aad5f910]" data-ui="0" data-ajax="0" data-multiple="0" data-placeholder="Select" data-allow_null="0"></select>
-> has the option
3. [/] checkbox class-acf-field-checkbox.php* : <input type="checkbox" id="acf-field_66201ac05f911-one" name="acf[field_66201ac05f911][]" value="one">
20. [/] radio class-acf-field-radio.php* : <input type="radio" id="acf-field_66201ad25f912-one" name="acf[field_66201ad25f912]" value="one">
-> has elements
21. [/] range class-acf-field-range.php* : <input type="range" id="acf-field_66200d7583916" name="acf[field_66200d7583916]" value="0" min="0" max="100" step="1"><input type="number" id="acf-field_66200d7583916-alt" value="0" step="1" style="width: 3.9em;">
2. [x] button_group class-acf-field-button-group.php* : <input type="radio" name="acf[field_66201adb5f913]" value="one">
4. [x] color_picker class-acf-field-color_picker.php* : <button type="button" class="button wp-color-result et-wp-color-result-updated" aria-expanded="false" title="Select Color" data-legacy_title="Select" data-current="Current Color" style="height: 24px; margin: 0px 6px 6px 0px; padding: 0px 0px 0px 30px; font-size: 11px;"></button>
17. [x] page_link class-acf-field-page_link.php* : <select id="acf-field_66201b0c5f917" class="select2-hidden-accessible" name="acf[field_66201b0c5f917]" data-ui="1" data-multiple="0" data-placeholder="Select" data-allow_null="0" data-select2-id="acf-field_66201b0c5f917" tabindex="-1" aria-hidden="true" data-ajax="1"></select>
19. [x] post_object class-acf-field-post_object.php* : <select id="acf-field_66201b015f916" class="select2-hidden-accessible" name="acf[field_66201b015f916]" data-ui="1" data-multiple="0" data-placeholder="Select" data-allow_null="0" data-select2-id="acf-field_66201b015f916" tabindex="-1" aria-hidden="true" data-ajax="1"></select>
26. [x] taxonomy class-acf-field-taxonomy.php* : <input type="checkbox" name="acf[field_66201b275f919][]" value="1">
30. [x] true_false class-acf-field-true_false.php* : <input type="checkbox" id="acf-field_66201ae95f914" name="acf[field_66201ae95f914]" value="1" class="" autocomplete="off" checked="checked">
32. [x] user class-acf-field-user.php* : <select id="acf-field_66201b335f91a" class="select2-hidden-accessible" name="acf[field_66201b335f91a]" data-ui="1" data-multiple="0" data-placeholder="Select" data-allow_null="0" data-query-nonce="1340e351c6" data-select2-id="acf-field_66201b335f91a" tabindex="-1" aria-hidden="true" data-ajax="1"></select>
33. [x] wysiwyg class-acf-field-wysiwyg.php* : <textarea id="acf-editor-87" class="wp-editor-area" name="acf[field_66201a955f90e]" style="height:300px;"></textarea>
-> no need
13. [x] message class-acf-field-message.php* : /
1. [x] class-acf-field-accordion.php* : /
25. [x] class-acf-field-tab.php* : /
10. [x] class-acf-field-group.php* : /
8. [x] file class-acf-field-file.php* : /
9. [x] google_map class-acf-field-google-map.php* : /
11. [x] image class-acf-field-image.php* : /
12. [x] link class-acf-field-link.php* : /
15. [x] oembed class-acf-field-oembed.php* : /
22. [x] relationship class-acf-field-relationship.php* : /
*/
/*
@@ -34,8 +115,12 @@ function is_acf_field_disabled($field) {
/*
* if acf field has class to be disabled
* -> add the 'disabled' value to object after it is loaded
* 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'
*
*/
function disable_acf_field_CIPF($field) {
@@ -45,8 +130,37 @@ function disable_acf_field_CIPF($field) {
return $field;
}
$field['disabled'] = 1;
//$field['readonly'] = 1;
$type = $field['type'];
if (in_array($type, array(
'text',
'textarea',
'number',
'email',
'url',
'password',
'date_picker',
'time_picker',
'select',
))) {
$field['disabled'] = 1;
}
else if (in_array($type, array(
'checkbox',
'radio',
))) {
if (!isset($field['choices'])) {
return $field;
}
$choices = $field['choices'];
$to_disable = array_keys($choices);
// acf cast the strings (line 128 : ../../../wordpress_docker/volumes/wp_volume/wp-content/plugins/advanced-custom-fields/includes/fields/class-acf-field-radio.php)
$to_disable = array_map(function($e){return (string)$e;}, $to_disable);
$field['disabled'] = $to_disable;
}
else {
$field['client_side_disabled'] = 1;
}
return $field;
}
@@ -54,8 +168,36 @@ add_filter('acf/load_field', 'disable_acf_field_CIPF');
/*
* filter the wrapper of the acf field
* if it has the property 'client_side_disabled',
* -> 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
* 737 : ../../../wordpress_docker/volumes/wp_volume/wp-content/plugins/advanced-custom-fields/includes/acf-field-functions.php
*
*/
function change_acf_field_wrapper_CIPF($wrapper, $field) {
Plgntls::debug_infos();
if (!isset($field['client_side_disabled'])) {
return $wrapper;
}
error_log("+field: " . json_encode($field));
$wrapper["inert"] = "true";
return $wrapper;
}
add_filter('acf/field_wrapper_attributes', 'change_acf_field_wrapper_CIPF', 10, 2);
/*
* 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
@@ -64,17 +206,21 @@ add_filter('acf/load_field', 'disable_acf_field_CIPF');
function disable_all_acf_field_CIPF($null, $value, $post_id, $field) {
Plgntls::debug_infos();
if (!isset($_POST['acf'])) {
return $null;
}
if (!is_acf_field_disabled($field)) {
return $null;
if (isset($field['client_side_disabled'])) {
return false;
}
return false;
return $null;
}
add_filter('acf/pre_update_value', 'disable_all_acf_field_CIPF', 10, 4);
?>