From 2397b24b579197b582a8d93bb838c6bf70aff5de Mon Sep 17 00:00:00 2001 From: asus Date: Wed, 24 Apr 2024 11:17:35 +0200 Subject: [PATCH] fbpatch better version of dates patch --- plugins/fbpatch/php/patches/dates.php | 98 +++++++-------------------- ç | 28 ++++++++ 2 files changed, 53 insertions(+), 73 deletions(-) create mode 100644 ç diff --git a/plugins/fbpatch/php/patches/dates.php b/plugins/fbpatch/php/patches/dates.php index 51710e9..af7ff5a 100644 --- a/plugins/fbpatch/php/patches/dates.php +++ b/plugins/fbpatch/php/patches/dates.php @@ -10,6 +10,26 @@ if (!defined('ABSPATH')) { +/* +* what I did : +* - in front, keep the acf date input with text date, +* but add a second hidden field with acf format date 'Ymd' +* - in back, saving the text date in the acf field, +* but keeping the acf date 'Ymd' in an option +* - in the same time, adding a class to the field group +* (available to all instances of this field) +* to maek it as using a text field +* - this way, if accessed the date with metadata, +* we get the text date +* - then, filter the value when loading, +* to use the acf format date 'Ymd' instead of the text date +* -> except id accessed by divi +* - and finally filter the format step +* (which is not triggered by admin output) +* to prevent formating if accessed by divi +* (so it will print the metadata instead) +* +*/ @@ -35,48 +55,11 @@ function try_format_acf_date($value, $post_id, $field) { return $value; } - if (\FBPATCH\is_get_field_from_divi()) { - return $value; - } - return $acf_date; } add_filter('acf/load_value', __NAMESPACE__.'\try_format_acf_date', 10, 3); -/* -* 2. this function will prevent format date when output, if get field is from divi -* -* the acf field value is now the right format Ymd, but the metadata is still the date text -* if the field is called by divi, returns false and divi will use the metadata -* -* 147 : ../../../../wordpress_docker/volumes/wp_volume/wp-content/plugins/advanced-custom-fields/includes/acf-value-functions.php -* -> the 'dfb_date' class is automatically added when submiting diviFormBuilder datepicker form -* -*/ -function prevent_format_for_acf_date_picker($null, $value, $post_id, $field, $escape_html) { - $acf_date_class = Fbpatch::ACF_DATE_CLASS; - if ($field['type'] !== 'date_picker') { - return $null; - } - if (!str_contains($field['wrapper']['class'], $acf_date_class)) { - return $null; - } - - if (!\FBPATCH\is_get_field_from_divi()) { - return $null; - } - - return false; -} -add_filter('acf/pre_format_value', __NAMESPACE__.'\prevent_format_for_acf_date_picker', 10, 5); - - - - - - - @@ -102,13 +85,8 @@ add_action('wp_enqueue_scripts', __NAMESPACE__.'\add_form_builder_dates_patch', - - - - - /* -* modify the submited post before inserting +* action about the submited post before inserting (we cannot modify it unfortunately) * - find any datepicker * - add class to their object to identify they are used by form builder * - save the date in acf format 'Ymd' in the options @@ -137,8 +115,9 @@ add_action('df_before_insert_post', __NAMESPACE__.'\process_form_acf_dates', 10, /* -* function acf_update_field( $field, $specific = array() ) -* 980 : ../../../../wordpress_docker/volumes/wp_volume/wp-content/plugins/advanced-custom-fields/includes/acf-field-functions.php +* to update a field object (so, globally) +* using `acf_update_field` +* -> 980 : ../../../../wordpress_docker/volumes/wp_volume/wp-content/plugins/advanced-custom-fields/includes/acf-field-functions.php * */ function add_date_to_acf_object_class($acf_id) { @@ -164,37 +143,10 @@ function add_date_to_acf_object_class($acf_id) { - - - - - - - /* -* utility functions +* here i use it to check if there are hidden field for acf dates * */ - -function is_get_field_from_divi() { - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); - $get_field_file = null; - - foreach ($backtrace as $trace) { - if ($trace['function'] === "get_field" || $trace['function'] === "get_field_object") { - $get_field_file = $trace['file']; - break; - } - } - - if (str_contains($get_field_file, '/Divi/')) { - return true; - } - else { - return false; - } -} - function array_has_keys_starting_with($needle, &$haystack) { $keys = array(); foreach ($haystack as $key => $value) { diff --git a/ç b/ç new file mode 100644 index 0000000..d49a76b --- /dev/null +++ b/ç @@ -0,0 +1,28 @@ +## list of errors in divi form builder + +1. [-] editing a post only work with the post title in the edit form (it can be an hidden field) +2. [-] edit post form dont remember a choice if the acf field has a value of 0 : `0 : label` +3. [-] multistep form effects and height calculation +4. [-] file upload icon on firefox +5. [ ] acf date not initialized is array, but dfb dont check it, which creates a php-notice array to string conversion -> `wordpress_docker/volumes/wp_volume/wp-content/plugins/divi-form-builder/includes/modules/FormField/FormField.php` +6. [ ] acf date don't output well and consistently, because acf will try to format it +7. [ ] acf date is not saved in acf format in the database +8. [ ] it's not a front error, but it made things really complicated to not have a filter of the `post_array` before saving it to the database : we can only filter the array with the wp hook `update_post_metadata`, but it does not have all the informations we need from the `post_array` + +--- + +1. when chossing a date in formbuilder, if the date format is not in format yymmdd (or Ymd in acf convention) it will not work +2. divi form builder, contact form, prof delete account, delete user, email confirmation, logged in user -> not working +3. when creating an hidden input email mapped with the email of the user, it deleted the email of the user +4. form email confirmation only sent if email notification are enabled +6. when choosing edit for author and admin only, admin can edit the post, but it changes its author +7. calculation total disapear when validating +8. in form, when chosing a conditional logic to output an element based on the value of another field, it does not work if this other field is automatically detecting fields from mapped value + - 434 : ../../../../wordpress_docker/volumes/wp_volume/wp-content/plugins/divi-form-builder/includes/DiviFormBuilder.php + - those lines : + ``` + if ( !isset( $post_array['meta_input'][$meta_input_rname] ) ) { + $post_array['meta_input'][$meta_input_rname] = array(); + }t + ``` + - they keep the field in the array that will be used to create the new post, but with an empty value : it empty the acf field at post creation. Instead, just don't keep the value ! -> it will not be in the new post, without emptying the acf field