From 343f34a15aea487ccd31936b2b80aa2fac0122a1 Mon Sep 17 00:00:00 2001 From: asus Date: Tue, 23 Apr 2024 13:26:16 +0200 Subject: [PATCH] for the moment dates have the apporpriate text output --- plugins/fbpatch/php/fbpatch_class.php | 2 +- plugins/fbpatch/php/patches/dates.php | 38 ++++++++------------------- 2 files changed, 12 insertions(+), 28 deletions(-) diff --git a/plugins/fbpatch/php/fbpatch_class.php b/plugins/fbpatch/php/fbpatch_class.php index 178ac4d..75d2e4a 100644 --- a/plugins/fbpatch/php/fbpatch_class.php +++ b/plugins/fbpatch/php/fbpatch_class.php @@ -20,7 +20,7 @@ class Fbpatch { const OPTION_TOGGLE_MENU = ['_name'=>'toggle_admin_menu_option_fbpatch', 'show'=>'show', 'hide'=>'hide']; const NONCE = ['_name'=>'nonce_name', '_action'=>'action_name']; const ADMIN_POST_PATCH_CHOICE = 'add_patches'; - const ACF_DATE_PREFIX = 'dfb_date_'; + const ACF_DATE_CLASS = 'dfb_date'; /* * get path an url from plugin root diff --git a/plugins/fbpatch/php/patches/dates.php b/plugins/fbpatch/php/patches/dates.php index 218d7e3..727f46d 100644 --- a/plugins/fbpatch/php/patches/dates.php +++ b/plugins/fbpatch/php/patches/dates.php @@ -43,11 +43,11 @@ jquery date picker : * */ function prevent_format_for_acf_date_picker($null, $value, $post_id, $field, $escape_html) { - $prefix = Fbpatch::ACF_DATE_PREFIX; + $acf_date_class = Fbpatch::ACF_DATE_CLASS; if ($field['type'] !== 'date_picker') { return $null; } - if (!str_contains($field['wrapper']['class'], $prefix)) { + if (!str_contains($field['wrapper']['class'], $acf_date_class)) { return $null; } return false; @@ -77,50 +77,34 @@ add_action('wp_enqueue_scripts', __NAMESPACE__.'\add_form_builder_dates_patch', -function array_has_keys_starting_with($needle, &$haystack, $remove = false) { +function array_has_keys_starting_with($needle, &$haystack) { $keys = array(); foreach ($haystack as $key => $value) { if (strpos($key, $needle) === 0) { $keys[] = $key; - if ($remove) { - unset($haystack[$key]); - } } } return $keys; } -function array_has_values_starting_with($needle, &$haystack, $remove = false) { - $keys = array(); - foreach ($haystack as $key => $value) { - if (strpos($value, $needle) === 0) { - $values[] = $value; - if ($remove) { - unset($haystack[$key]); - } - } - } - return $values; -} - /* * function acf_update_field( $field, $specific = array() ) {} * 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, $date) { - $prefix = Fbpatch::ACF_DATE_PREFIX; +function add_date_to_acf_object_class($acf_id) { $field = get_field_object($acf_id); $field_class = $field['wrapper']['class']; $field_classes = explode(' ', $field_class); - $class = $prefix . $date; + $class = Fbpatch::ACF_DATE_CLASS; - $dates_class = array_has_values_starting_with($prefix, $field_classes, true); - $previous_date = reset($dates_class); - if (empty($date) && !empty($previous_date)) { - $class = $previous_date; - } + $field_classes = array_filter($field_classes, function($value) { + $class = Fbpatch::ACF_DATE_CLASS; + if (strpos($value, $class) !== 0) { + return $value; + } + }); $field_classes[] = $class; $implode_class = implode(' ', $field_classes);