Version Description
- Adds option to store the date and time field as a UNIX timestamp or not.
Download this release
Release Info
Developer | PerS |
Plugin | Date and Time Picker Field |
Version | 2.0.8 |
Comparing to | |
See all releases |
Code changes from version 2.0.7 to 2.0.8
- acf-date_time_picker.php +2 -2
- date_time_picker-v3.php +42 -12
- date_time_picker-v4.php +43 -14
- readme.txt +4 -3
acf-date_time_picker.php
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
<?php
|
2 |
/*
|
3 |
-
Plugin Name: Advanced Custom Fields:
|
4 |
Plugin URI: https://github.com/soderlind/acf-field-date-time-picker
|
5 |
Description: Date and Time Picker field for Advanced Custom Fields
|
6 |
-
Version: 2.0.
|
7 |
Author: Per Soderlind
|
8 |
Author URI: http://soderlind.no
|
9 |
License: GPLv2 or later
|
1 |
<?php
|
2 |
/*
|
3 |
+
Plugin Name: Advanced Custom Fields: Date and Time Picker
|
4 |
Plugin URI: https://github.com/soderlind/acf-field-date-time-picker
|
5 |
Description: Date and Time Picker field for Advanced Custom Fields
|
6 |
+
Version: 2.0.8
|
7 |
Author: Per Soderlind
|
8 |
Author URI: http://soderlind.no
|
9 |
License: GPLv2 or later
|
date_time_picker-v3.php
CHANGED
@@ -28,19 +28,20 @@ class acf_field_date_time_picker extends acf_Field {
|
|
28 |
$this->title = __( 'Date and Time Picker' );
|
29 |
$this->domain = 'acf-date_time_picker';
|
30 |
$this->defaults = array(
|
31 |
-
'value'
|
32 |
-
, 'label'
|
33 |
-
, 'time_format'
|
34 |
-
, 'show_date'
|
35 |
-
, 'date_format'
|
36 |
-
, 'show_week_number'
|
37 |
-
, 'picker'
|
|
|
38 |
);
|
39 |
|
40 |
$this->settings = array(
|
41 |
'path' => $this->helpers_get_path( __FILE__ )
|
42 |
, 'dir' => $this->helpers_get_dir( __FILE__ )
|
43 |
-
, 'version' => '2.0.
|
44 |
);
|
45 |
}
|
46 |
|
@@ -209,7 +210,26 @@ class acf_field_date_time_picker extends acf_Field {
|
|
209 |
?>
|
210 |
</td>
|
211 |
</tr>
|
212 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
213 |
<?php
|
214 |
|
215 |
}
|
@@ -255,7 +275,16 @@ class acf_field_date_time_picker extends acf_Field {
|
|
255 |
*-------------------------------------------------------------------------------------*/
|
256 |
|
257 |
function update_value($post_id, $field, $value) {
|
258 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
259 |
parent::update_value($post_id, $field, $value);
|
260 |
}
|
261 |
|
@@ -276,9 +305,10 @@ class acf_field_date_time_picker extends acf_Field {
|
|
276 |
*-------------------------------------------------------------------------------------*/
|
277 |
|
278 |
function get_value($post_id, $field){
|
|
|
279 |
$value = parent::get_value($post_id, $field);
|
280 |
|
281 |
-
if ($value != '' && $this->isValidTimeStamp($value)) {
|
282 |
if ( $field['show_date'] == 'true') {
|
283 |
$value = date(sprintf("%s %s",$this->js_to_php_dateformat($field['date_format']),$this->js_to_php_timeformat($field['time_format'])), $value);
|
284 |
} else {
|
@@ -292,7 +322,7 @@ class acf_field_date_time_picker extends acf_Field {
|
|
292 |
function js_to_php_dateformat($date_format) {
|
293 |
$chars = array(
|
294 |
// Day
|
295 |
-
'dd' => 'd', 'd' => 'j', 'DD' => 'l', 'o' => 'z',
|
296 |
// Month
|
297 |
'mm' => 'm', 'm' => 'n', 'MM' => 'F', 'M' => 'M',
|
298 |
// Year
|
28 |
$this->title = __( 'Date and Time Picker' );
|
29 |
$this->domain = 'acf-date_time_picker';
|
30 |
$this->defaults = array(
|
31 |
+
'value' => ''
|
32 |
+
, 'label' => __( 'Choose Time', $this->domain )
|
33 |
+
, 'time_format' => 'hh:mm'
|
34 |
+
, 'show_date' => 'true'
|
35 |
+
, 'date_format' => 'yy-mm-dd'
|
36 |
+
, 'show_week_number' => 'false'
|
37 |
+
, 'picker' => 'slider'
|
38 |
+
, 'save_as_timestamp' => 'true'
|
39 |
);
|
40 |
|
41 |
$this->settings = array(
|
42 |
'path' => $this->helpers_get_path( __FILE__ )
|
43 |
, 'dir' => $this->helpers_get_dir( __FILE__ )
|
44 |
+
, 'version' => '2.0.8'
|
45 |
);
|
46 |
}
|
47 |
|
210 |
?>
|
211 |
</td>
|
212 |
</tr>
|
213 |
+
<tr class="field_option field_option_<?php echo $this->name; ?> timepicker_week_number">
|
214 |
+
<td class="label">
|
215 |
+
<label for=""><?php _e( "Save as timestamp?", $this->domain ); ?></label>
|
216 |
+
<p class="description"><?php printf( __( "Most users should leave this untouched, only set it to \"No\" if you need a date and time format not supported by <a href=\"%s\" target=\"_blank\">strtotime</a>", $this->domain ), "http://php.net/manual/en/function.strtotime.php" );?></p>
|
217 |
+
</td>
|
218 |
+
<td>
|
219 |
+
<?php
|
220 |
+
$this->parent->create_field( array(
|
221 |
+
'type' => 'radio'
|
222 |
+
, 'name' => 'fields['.$key.'][save_as_timestamp]'
|
223 |
+
, 'value' => $field['save_as_timestamp']
|
224 |
+
, 'layout' => 'horizontal'
|
225 |
+
, 'choices' => array(
|
226 |
+
'true' => __( 'Yes', $this->domain )
|
227 |
+
, 'false' => __( 'No', $this->domain )
|
228 |
+
)
|
229 |
+
) );
|
230 |
+
?>
|
231 |
+
</td>
|
232 |
+
</tr>
|
233 |
<?php
|
234 |
|
235 |
}
|
275 |
*-------------------------------------------------------------------------------------*/
|
276 |
|
277 |
function update_value($post_id, $field, $value) {
|
278 |
+
$field = array_merge($this->defaults, $field);
|
279 |
+
if ($value != '' && $field['save_as_timestamp'] == 'true') {
|
280 |
+
if ( $field['show_date'] == 'true') {
|
281 |
+
$date = DateTime::createFromFormat(sprintf("%s %s",$this->js_to_php_dateformat($field['date_format']),$this->js_to_php_timeformat($field['time_format'])), $value);
|
282 |
+
} else {
|
283 |
+
$date = DateTime::createFromFormat(sprintf("%s",$this->js_to_php_timeformat($field['time_format'])), $value);
|
284 |
+
}
|
285 |
+
$value = $date->getTimestamp();
|
286 |
+
}
|
287 |
+
|
288 |
parent::update_value($post_id, $field, $value);
|
289 |
}
|
290 |
|
305 |
*-------------------------------------------------------------------------------------*/
|
306 |
|
307 |
function get_value($post_id, $field){
|
308 |
+
$field = array_merge($this->defaults, $field);
|
309 |
$value = parent::get_value($post_id, $field);
|
310 |
|
311 |
+
if ($value != '' && $field['save_as_timestamp'] == 'true' && $this->isValidTimeStamp($value)) {
|
312 |
if ( $field['show_date'] == 'true') {
|
313 |
$value = date(sprintf("%s %s",$this->js_to_php_dateformat($field['date_format']),$this->js_to_php_timeformat($field['time_format'])), $value);
|
314 |
} else {
|
322 |
function js_to_php_dateformat($date_format) {
|
323 |
$chars = array(
|
324 |
// Day
|
325 |
+
'dd' => 'd', 'd' => 'j', 'DD' => 'l', 'D' => 'D', 'o' => 'z',
|
326 |
// Month
|
327 |
'mm' => 'm', 'm' => 'n', 'MM' => 'F', 'M' => 'M',
|
328 |
// Year
|
date_time_picker-v4.php
CHANGED
@@ -25,14 +25,14 @@ class acf_field_date_time_picker extends acf_field
|
|
25 |
$this->category = __("jQuery", $this->domain); // Basic, Content, Choice, etc
|
26 |
$this->domain = 'acf-date_time_picker';
|
27 |
$this->defaults = array(
|
28 |
-
'value'
|
29 |
-
, 'label'
|
30 |
-
, 'time_format'
|
31 |
-
, 'show_date'
|
32 |
-
, 'date_format'
|
33 |
-
, 'show_week_number'
|
34 |
-
, 'picker'
|
35 |
-
, '
|
36 |
);
|
37 |
|
38 |
|
@@ -45,7 +45,7 @@ class acf_field_date_time_picker extends acf_field
|
|
45 |
$this->settings = array(
|
46 |
'path' => apply_filters('acf/helpers/get_path', __FILE__)
|
47 |
, 'dir' => apply_filters('acf/helpers/get_dir', __FILE__)
|
48 |
-
, 'version' => '2.0.
|
49 |
);
|
50 |
|
51 |
}
|
@@ -156,6 +156,26 @@ class acf_field_date_time_picker extends acf_field
|
|
156 |
?>
|
157 |
</td>
|
158 |
</tr>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
<?php
|
160 |
}
|
161 |
|
@@ -201,9 +221,11 @@ class acf_field_date_time_picker extends acf_field
|
|
201 |
*/
|
202 |
|
203 |
function load_value( $value, $post_id, $field ) {
|
204 |
-
|
|
|
205 |
if ( $field['show_date'] == 'true') {
|
206 |
$value = date(sprintf("%s %s",$this->js_to_php_dateformat($field['date_format']),$this->js_to_php_timeformat($field['time_format'])), $value);
|
|
|
207 |
} else {
|
208 |
$value = date(sprintf("%s",$this->js_to_php_timeformat($field['time_format'])), $value);
|
209 |
}
|
@@ -215,7 +237,7 @@ class acf_field_date_time_picker extends acf_field
|
|
215 |
function js_to_php_dateformat($date_format) {
|
216 |
$chars = array(
|
217 |
// Day
|
218 |
-
'dd' => 'd', 'd' => 'j', 'DD' => 'l', 'o' => 'z',
|
219 |
// Month
|
220 |
'mm' => 'm', 'm' => 'n', 'MM' => 'F', 'M' => 'M',
|
221 |
// Year
|
@@ -242,7 +264,7 @@ class acf_field_date_time_picker extends acf_field
|
|
242 |
return strtr((string)$time_format, $chars);
|
243 |
}
|
244 |
|
245 |
-
|
246 |
function isValidTimeStamp($timestamp) { //from http://stackoverflow.com/a/2524761/1434155
|
247 |
return ((string) (int) $timestamp === $timestamp)
|
248 |
&& ($timestamp <= PHP_INT_MAX)
|
@@ -265,8 +287,15 @@ class acf_field_date_time_picker extends acf_field
|
|
265 |
*/
|
266 |
|
267 |
function update_value( $value, $post_id, $field ) {
|
268 |
-
|
269 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
270 |
return $value;
|
271 |
}
|
272 |
|
25 |
$this->category = __("jQuery", $this->domain); // Basic, Content, Choice, etc
|
26 |
$this->domain = 'acf-date_time_picker';
|
27 |
$this->defaults = array(
|
28 |
+
'value' => ''
|
29 |
+
, 'label' => __( 'Choose Time', $this->domain )
|
30 |
+
, 'time_format' => 'hh:mm'
|
31 |
+
, 'show_date' => 'true'
|
32 |
+
, 'date_format' => 'yy-mm-dd'
|
33 |
+
, 'show_week_number' => 'false'
|
34 |
+
, 'picker' => 'slider'
|
35 |
+
, 'save_as_timestamp' => 'true'
|
36 |
);
|
37 |
|
38 |
|
45 |
$this->settings = array(
|
46 |
'path' => apply_filters('acf/helpers/get_path', __FILE__)
|
47 |
, 'dir' => apply_filters('acf/helpers/get_dir', __FILE__)
|
48 |
+
, 'version' => '2.0.8'
|
49 |
);
|
50 |
|
51 |
}
|
156 |
?>
|
157 |
</td>
|
158 |
</tr>
|
159 |
+
<tr class="field_option field_option_<?php echo $this->name; ?> timepicker_week_number">
|
160 |
+
<td class="label">
|
161 |
+
<label for=""><?php _e( "Save as timestamp?", $this->domain ); ?></label>
|
162 |
+
<p class="description"><?php printf( __( "Most users should leave this untouched, only set it to \"No\" if you need a date and time format not supported by <a href=\"%s\" target=\"_blank\">strtotime</a>", $this->domain ), "http://php.net/manual/en/function.strtotime.php" );?></p>
|
163 |
+
</td>
|
164 |
+
<td>
|
165 |
+
<?php
|
166 |
+
do_action('acf/create_field', array(
|
167 |
+
'type' => 'radio'
|
168 |
+
, 'name' => 'fields['.$key.'][save_as_timestamp]'
|
169 |
+
, 'value' => $field['save_as_timestamp']
|
170 |
+
, 'layout' => 'horizontal'
|
171 |
+
, 'choices' => array(
|
172 |
+
'true' => __( 'Yes', $this->domain )
|
173 |
+
, 'false' => __( 'No', $this->domain )
|
174 |
+
)
|
175 |
+
) );
|
176 |
+
?>
|
177 |
+
</td>
|
178 |
+
</tr>
|
179 |
<?php
|
180 |
}
|
181 |
|
221 |
*/
|
222 |
|
223 |
function load_value( $value, $post_id, $field ) {
|
224 |
+
$field = array_merge($this->defaults, $field);
|
225 |
+
if ($value != '' && $field['save_as_timestamp'] == 'true' && $this->isValidTimeStamp($value)) {
|
226 |
if ( $field['show_date'] == 'true') {
|
227 |
$value = date(sprintf("%s %s",$this->js_to_php_dateformat($field['date_format']),$this->js_to_php_timeformat($field['time_format'])), $value);
|
228 |
+
//$value = sprintf("%s %s",$this->js_day_to_strftimeformat($field['date_format']),$this->js_time_to_strftimeformat($field['time_format']));
|
229 |
} else {
|
230 |
$value = date(sprintf("%s",$this->js_to_php_timeformat($field['time_format'])), $value);
|
231 |
}
|
237 |
function js_to_php_dateformat($date_format) {
|
238 |
$chars = array(
|
239 |
// Day
|
240 |
+
'dd' => 'd', 'd' => 'j', 'DD' => 'l','D' => 'D', 'o' => 'z',
|
241 |
// Month
|
242 |
'mm' => 'm', 'm' => 'n', 'MM' => 'F', 'M' => 'M',
|
243 |
// Year
|
264 |
return strtr((string)$time_format, $chars);
|
265 |
}
|
266 |
|
267 |
+
|
268 |
function isValidTimeStamp($timestamp) { //from http://stackoverflow.com/a/2524761/1434155
|
269 |
return ((string) (int) $timestamp === $timestamp)
|
270 |
&& ($timestamp <= PHP_INT_MAX)
|
287 |
*/
|
288 |
|
289 |
function update_value( $value, $post_id, $field ) {
|
290 |
+
$field = array_merge($this->defaults, $field);
|
291 |
+
if ($value != '' && $field['save_as_timestamp'] == 'true') {
|
292 |
+
if ( $field['show_date'] == 'true') {
|
293 |
+
$date = DateTime::createFromFormat(sprintf("%s %s",$this->js_to_php_dateformat($field['date_format']),$this->js_to_php_timeformat($field['time_format'])), $value);
|
294 |
+
} else {
|
295 |
+
$date = DateTime::createFromFormat(sprintf("%s",$this->js_to_php_timeformat($field['time_format'])), $value);
|
296 |
+
}
|
297 |
+
return $date->getTimestamp();
|
298 |
+
}
|
299 |
return $value;
|
300 |
}
|
301 |
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: http://soderlind.no/donate/
|
|
4 |
Tags: acf, custom field,datepicker,timepicker
|
5 |
Requires at least: 3.4
|
6 |
Tested up to: 3.5.1
|
7 |
-
Stable tag: 2.0.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -21,7 +21,7 @@ This is an add-on for the [Advanced Custom Fields](http://wordpress.org/extend/p
|
|
21 |
|
22 |
This add-on will work with:
|
23 |
|
24 |
-
* Advanced Custom Fields version 4 and up
|
25 |
* Advanced Custom Fields version 3 and bellow
|
26 |
|
27 |
= More Information =
|
@@ -110,7 +110,8 @@ TT AM or PM for AM/PM
|
|
110 |
The Date and Time Picker field is saved as an UNIX timestamp. Use the PHP [date](http://php.net/manual/en/function.date.php) function when you use it in your theme.
|
111 |
|
112 |
== Changelog ==
|
113 |
-
|
|
|
114 |
= 2.0.7 =
|
115 |
* Bug fix. 2.0.6 assumed that the stored date and time was in UNIX timestamp format. 2.0.7 will check and only convert if the date and time is.
|
116 |
= 2.0.6 =
|
4 |
Tags: acf, custom field,datepicker,timepicker
|
5 |
Requires at least: 3.4
|
6 |
Tested up to: 3.5.1
|
7 |
+
Stable tag: 2.0.8
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
21 |
|
22 |
This add-on will work with:
|
23 |
|
24 |
+
* Advanced Custom Fields version 4 and up. **NOTE, There's an issue with ACF 4.1.5 and up, and custom fields. Please use [ACF 4.1.4](http://downloads.wordpress.org/plugin/advanced-custom-fields.4.1.4.zip)**
|
25 |
* Advanced Custom Fields version 3 and bellow
|
26 |
|
27 |
= More Information =
|
110 |
The Date and Time Picker field is saved as an UNIX timestamp. Use the PHP [date](http://php.net/manual/en/function.date.php) function when you use it in your theme.
|
111 |
|
112 |
== Changelog ==
|
113 |
+
= 2.0.8 =
|
114 |
+
* Adds option to store the date and time field as a UNIX timestamp or not.
|
115 |
= 2.0.7 =
|
116 |
* Bug fix. 2.0.6 assumed that the stored date and time was in UNIX timestamp format. 2.0.7 will check and only convert if the date and time is.
|
117 |
= 2.0.6 =
|