From 8f426bf07a079e3487fc9e09cd9ee243e84541ef Mon Sep 17 00:00:00 2001 From: Toby McKes Date: Fri, 25 Jul 2014 11:32:46 -0700 Subject: [PATCH 1/2] Changing order of operations in _sanitize_field_value, so custom sanitize callback can be executed before date conversion happens --- custom_metadata.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/custom_metadata.php b/custom_metadata.php index 6aa50aa..5980ef8 100644 --- a/custom_metadata.php +++ b/custom_metadata.php @@ -1063,14 +1063,14 @@ function _sanitize_field_value( $field_slug, $field, $object_type, $object_id, $ $sanitize_callback = $this->get_sanitize_callback( $field, $object_type ); + if ( $sanitize_callback ) + return call_user_func( $sanitize_callback, $field_slug, $field, $object_type, $object_id, $value ); + // convert date to unix timestamp if ( in_array( $field->field_type, array( 'datepicker', 'datetimepicker', 'timepicker' ) ) ) { $value = strtotime( $value ); } - if ( $sanitize_callback ) - return call_user_func( $sanitize_callback, $field_slug, $field, $object_type, $object_id, $value ); - return $value; } From 0fc909c01fbe59bee81281d3a403e9f688afb540 Mon Sep 17 00:00:00 2001 From: Toby McKes Date: Sat, 2 Aug 2014 10:10:29 -0400 Subject: [PATCH 2/2] Checking if is an array, stepping through if it is and sanitizing each value --- custom_metadata.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/custom_metadata.php b/custom_metadata.php index 5980ef8..afe827f 100644 --- a/custom_metadata.php +++ b/custom_metadata.php @@ -1068,7 +1068,17 @@ function _sanitize_field_value( $field_slug, $field, $object_type, $object_id, $ // convert date to unix timestamp if ( in_array( $field->field_type, array( 'datepicker', 'datetimepicker', 'timepicker' ) ) ) { - $value = strtotime( $value ); + + // if $value is an array, we need to sanitize every value in the array + if( is_array( $value ) ) { + $result = array(); + foreach ( $value as $val ) { + $result[] = strtotime( $val ); + } + $value = $result; + } else { + $value = strtotime( $value ); + } } return $value;