for the moment dates have the apporpriate text output

This commit is contained in:
asus
2024-04-23 13:26:16 +02:00
parent 1447fdbc8e
commit 343f34a15a
2 changed files with 12 additions and 28 deletions

View File

@@ -20,7 +20,7 @@ class Fbpatch {
const OPTION_TOGGLE_MENU = ['_name'=>'toggle_admin_menu_option_fbpatch', 'show'=>'show', 'hide'=>'hide']; const OPTION_TOGGLE_MENU = ['_name'=>'toggle_admin_menu_option_fbpatch', 'show'=>'show', 'hide'=>'hide'];
const NONCE = ['_name'=>'nonce_name', '_action'=>'action_name']; const NONCE = ['_name'=>'nonce_name', '_action'=>'action_name'];
const ADMIN_POST_PATCH_CHOICE = 'add_patches'; 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 * get path an url from plugin root

View File

@@ -43,11 +43,11 @@ jquery date picker :
* *
*/ */
function prevent_format_for_acf_date_picker($null, $value, $post_id, $field, $escape_html) { 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') { if ($field['type'] !== 'date_picker') {
return $null; return $null;
} }
if (!str_contains($field['wrapper']['class'], $prefix)) { if (!str_contains($field['wrapper']['class'], $acf_date_class)) {
return $null; return $null;
} }
return false; 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(); $keys = array();
foreach ($haystack as $key => $value) { foreach ($haystack as $key => $value) {
if (strpos($key, $needle) === 0) { if (strpos($key, $needle) === 0) {
$keys[] = $key; $keys[] = $key;
if ($remove) {
unset($haystack[$key]);
}
} }
} }
return $keys; 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() ) {} * function acf_update_field( $field, $specific = array() ) {}
* 980 : ../../../../wordpress_docker/volumes/wp_volume/wp-content/plugins/advanced-custom-fields/includes/acf-field-functions.php * 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) { function add_date_to_acf_object_class($acf_id) {
$prefix = Fbpatch::ACF_DATE_PREFIX;
$field = get_field_object($acf_id); $field = get_field_object($acf_id);
$field_class = $field['wrapper']['class']; $field_class = $field['wrapper']['class'];
$field_classes = explode(' ', $field_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); $field_classes = array_filter($field_classes, function($value) {
$previous_date = reset($dates_class); $class = Fbpatch::ACF_DATE_CLASS;
if (empty($date) && !empty($previous_date)) { if (strpos($value, $class) !== 0) {
$class = $previous_date; return $value;
} }
});
$field_classes[] = $class; $field_classes[] = $class;
$implode_class = implode(' ', $field_classes); $implode_class = implode(' ', $field_classes);