fbatch dates new version only in front
This commit is contained in:
@@ -54,24 +54,24 @@ if (!defined('ABSPATH')) {
|
||||
* and if returned it will let the function go on to try to retrieve the value
|
||||
*
|
||||
*/
|
||||
function try_get_acf_date($value, $post_id, $field) {
|
||||
$acf_date_class = Fbpatch::ACF_DATE_CLASS;
|
||||
if ($field['type'] !== 'date_picker') {
|
||||
return $value;
|
||||
}
|
||||
if (!str_contains($field['wrapper']['class'], $acf_date_class)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$acf_date = Fbpatch::get_acf_date($post_id, $field['key']);
|
||||
if ($acf_date === false) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
return $acf_date;
|
||||
}
|
||||
add_filter('acf/load_value', __NAMESPACE__.'\try_get_acf_date', 10, 3);
|
||||
//add_filter('acf/pre_load_value', __NAMESPACE__.'\try_get_acf_date', 10, 3);
|
||||
//function try_get_acf_date($value, $post_id, $field) {
|
||||
// $acf_date_class = Fbpatch::ACF_DATE_CLASS;
|
||||
// if ($field['type'] !== 'date_picker') {
|
||||
// return $value;
|
||||
// }
|
||||
// if (!str_contains($field['wrapper']['class'], $acf_date_class)) {
|
||||
// return $value;
|
||||
// }
|
||||
//
|
||||
// $acf_date = Fbpatch::get_acf_date($post_id, $field['key']);
|
||||
// if ($acf_date === false) {
|
||||
// return $value;
|
||||
// }
|
||||
//
|
||||
// return $acf_date;
|
||||
//}
|
||||
//add_filter('acf/load_value', __NAMESPACE__.'\try_get_acf_date', 10, 3);
|
||||
////add_filter('acf/pre_load_value', __NAMESPACE__.'\try_get_acf_date', 10, 3);
|
||||
|
||||
|
||||
|
||||
@@ -98,7 +98,10 @@ function add_form_builder_dates_patch() {
|
||||
}
|
||||
add_action('wp_enqueue_scripts', __NAMESPACE__.'\add_form_builder_dates_patch', 22);
|
||||
|
||||
|
||||
function view_date_post($form_id, $post_array) {
|
||||
error_log("post_array: " . json_encode($post_array));
|
||||
}
|
||||
add_action('df_before_insert_post', __NAMESPACE__.'\view_date_post', 10, 2);
|
||||
|
||||
|
||||
|
||||
@@ -112,67 +115,67 @@ add_action('wp_enqueue_scripts', __NAMESPACE__.'\add_form_builder_dates_patch',
|
||||
* -> 845 : ../../../../wordpress_docker/volumes/wp_volume/wp-content/plugins/divi-form-builder/includes/DiviFormBuilder.php
|
||||
*
|
||||
*/
|
||||
function process_form_acf_dates($form_id, $post_array) {
|
||||
$acf_field_start = 'acf_date_hidden_for_';
|
||||
$acf_date_fields = \FBPATCH\array_has_keys_starting_with($acf_field_start, $post_array);
|
||||
if (empty($acf_date_fields)) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($acf_date_fields as $field) {
|
||||
$acf_date = $post_array[$field];
|
||||
$acf_field = substr($field, strlen($acf_field_start));
|
||||
$new_date_text = $post_array['meta_input'][$acf_field];
|
||||
$acf_key = $post_array['meta_input']['_'.$acf_field];
|
||||
\FBPATCH\add_date_to_acf_object_class($acf_key, $acf_date);
|
||||
Fbpatch::update_acf_date($post_array['ID'], $acf_key, $acf_date);
|
||||
}
|
||||
}
|
||||
add_action('df_before_insert_post', __NAMESPACE__.'\process_form_acf_dates', 10, 2);
|
||||
|
||||
|
||||
/*
|
||||
* 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) {
|
||||
$field = get_field_object($acf_id);
|
||||
$field_class = $field['wrapper']['class'];
|
||||
$field_classes = explode(' ', $field_class);
|
||||
$class = Fbpatch::ACF_DATE_CLASS;
|
||||
|
||||
$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);
|
||||
$field['wrapper']['class'] = $implode_class;
|
||||
acf_update_field($field);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* here i use it to check if there are hidden field for acf dates
|
||||
*
|
||||
*/
|
||||
function array_has_keys_starting_with($needle, &$haystack) {
|
||||
$keys = array();
|
||||
foreach ($haystack as $key => $value) {
|
||||
if (strpos($key, $needle) === 0) {
|
||||
$keys[] = $key;
|
||||
}
|
||||
}
|
||||
return $keys;
|
||||
}
|
||||
//function process_form_acf_dates($form_id, $post_array) {
|
||||
// $acf_field_start = 'acf_date_hidden_for_';
|
||||
// $acf_date_fields = \FBPATCH\array_has_keys_starting_with($acf_field_start, $post_array);
|
||||
// if (empty($acf_date_fields)) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// foreach ($acf_date_fields as $field) {
|
||||
// $acf_date = $post_array[$field];
|
||||
// $acf_field = substr($field, strlen($acf_field_start));
|
||||
// $new_date_text = $post_array['meta_input'][$acf_field];
|
||||
// $acf_key = $post_array['meta_input']['_'.$acf_field];
|
||||
// \FBPATCH\add_date_to_acf_object_class($acf_key, $acf_date);
|
||||
// Fbpatch::update_acf_date($post_array['ID'], $acf_key, $acf_date);
|
||||
// }
|
||||
//}
|
||||
//add_action('df_before_insert_post', __NAMESPACE__.'\process_form_acf_dates', 10, 2);
|
||||
//
|
||||
//
|
||||
///*
|
||||
//* 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) {
|
||||
// $field = get_field_object($acf_id);
|
||||
// $field_class = $field['wrapper']['class'];
|
||||
// $field_classes = explode(' ', $field_class);
|
||||
// $class = Fbpatch::ACF_DATE_CLASS;
|
||||
//
|
||||
// $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);
|
||||
// $field['wrapper']['class'] = $implode_class;
|
||||
// acf_update_field($field);
|
||||
//}
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
///*
|
||||
//* here i use it to check if there are hidden field for acf dates
|
||||
//*
|
||||
//*/
|
||||
//function array_has_keys_starting_with($needle, &$haystack) {
|
||||
// $keys = array();
|
||||
// foreach ($haystack as $key => $value) {
|
||||
// if (strpos($key, $needle) === 0) {
|
||||
// $keys[] = $key;
|
||||
// }
|
||||
// }
|
||||
// return $keys;
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user