@@ -58,7 +58,7 @@ function add() {
58
58
}
59
59
60
60
/**
61
- * Creates a block repeater item
61
+ * Creates a block repeater items
62
62
* Similar to a set, but each block can expand to hold many items
63
63
*/
64
64
class cf_input_block {
@@ -217,8 +217,10 @@ function save_group($post) {
217
217
foreach ($ post [$ this ->config ['prefix ' ].'blocks ' ][$ this ->config ['name ' ]] as $ value ) {
218
218
// keep items where all values are empty from being saved
219
219
$ control = '' ;
220
- foreach ($ value as $ item ) { $ control .= $ item ; }
221
- if (strlen (trim ($ control )) > 0 ) {
220
+ foreach ($ value as $ item ) {
221
+ $ control .= $ item ;
222
+ }
223
+ if (strlen (trim ($ control )) > 0 ) {
222
224
$ save_array [] = $ value ;
223
225
}
224
226
}
@@ -274,9 +276,9 @@ function cf_input($conf) {
274
276
* verify presence of data and throw any necessary errors
275
277
*/
276
278
function save () {
277
- if (isset ($ _POST [$ this ->get_name ()])) {
279
+ if (isset ($ _POST [$ this ->get_name ()])) {
278
280
// check required
279
- if ($ _POST [$ this ->get_name ()] == '' && $ this ->required ) {
281
+ if ($ _POST [$ this ->get_name ()] = == '' && $ this ->required ) {
280
282
$ this ->error = 'required ' ;
281
283
return false ;
282
284
}
@@ -285,7 +287,8 @@ function save() {
285
287
286
288
// write to db
287
289
return $ this ->save_data ($ _POST [$ this ->get_name ()]);
288
- } else {
290
+ }
291
+ else {
289
292
delete_post_meta ($ this ->post_id ,$ this ->get_name ());
290
293
}
291
294
return false ;
@@ -297,7 +300,7 @@ function save() {
297
300
function save_data ($ value ) {
298
301
$ value = apply_filters ('cfinput_save_data ' , $ value , $ this ->config ['name ' ], $ this ->config );
299
302
// delete meta entry on empty value
300
- if ($ value == '' ) {
303
+ if ($ value = == '' ) {
301
304
return delete_post_meta ($ this ->post_id ,$ this ->config ['name ' ]);
302
305
}
303
306
else {
@@ -339,7 +342,7 @@ function get_input( $value = false ) {
339
342
$ value = ($ value ) ? $ value : $ this ->get_value ();
340
343
$ class = isset ($ this ->config ['label ' ]) ? null : 'class="full" ' ;
341
344
342
- return '<input type=" ' .$ this ->config ['type ' ].'" name=" ' .$ this ->get_id ().'" id=" ' .$ this ->get_id ().'" value=" ' .htmlspecialchars ($ value ).'" ' .$ this ->attributes ().$ class .'/> ' ;
345
+ return '<input type=" ' .$ this ->config ['type ' ].'" name=" ' .$ this ->get_id ().'" id=" ' .$ this ->get_id ().'" value=" ' .esc_attr ($ value ).'" ' .$ this ->attributes ().$ class .'/> ' ;
343
346
}
344
347
345
348
function attributes () {
@@ -407,7 +410,7 @@ function get_value() {
407
410
}
408
411
}
409
412
410
- if (! empty ( $ value) ) {
413
+ if ( $ value !== '' ) {
411
414
$ this ->value = $ value ;
412
415
}
413
416
else if (!empty ($ this ->config ['default_value ' ]) && !in_array ($ this ->config ['type ' ], array ('checkbox ' ))) {
@@ -601,9 +604,45 @@ function get_input( $value = false ) {
601
604
}
602
605
603
606
class cf_input_file extends cf_input {
604
- function cf_input_text ($ conf ) {
607
+ function cf_input_file ($ conf ) {
605
608
return cf_input::cf_input ($ conf );
606
609
}
607
610
}
611
+
612
+ class cf_input_date extends cf_input {
613
+ function cf_input_date ($ conf ) {
614
+ // We want to enqueue the jQuery datepicker for this.
615
+ wp_enqueue_script ('jquery-ui-datepicker ' );
616
+ // May need to review how we want the jquery ui styles enqueued
617
+ wp_enqueue_style ('jquery-ui ' , 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css ' );
618
+ return cf_input::cf_input ($ conf );
619
+ }
620
+
621
+ function get_input () {
622
+ $ output = parent ::get_input ();
623
+ $ output .= '
624
+ <script type="text/javascript">
625
+ jQuery(document).ready(function($) {
626
+ $("# ' .$ this ->get_id ().'").datepicker({
627
+ "dateFormat": "yy-mm-dd", // This should not be changed, it is set for compatibility with §5.6 of RFC3339 regarding date inputs
628
+ }).prop("placeholder", "yyyy-mm-dd");
629
+ });
630
+ </script>
631
+ ' ;
632
+ return $ output ;
633
+ }
634
+
635
+ // This clears the meta then resaves if it was passed in. This will also normalize the date format in case, by some method, it was not submitted in yyyy-mm-dd format.
636
+ function save () {
637
+ if (empty ($ _POST [$ this ->get_name ()])) {
638
+ return delete_post_meta ($ this ->config ['post_id ' ], $ this ->get_name ());
639
+ }
640
+ else {
641
+ // Because JS may not have been enabled on the user's system, let's do our best to ensure the submitted date is in the proper format.
642
+ $ meta_value = date ('Y-m-d ' , strtotime ($ _POST [$ this ->get_name ()]));
643
+ return update_post_meta ($ this ->config ['post_id ' ], $ this ->config ['name ' ], $ meta_value );
644
+ }
645
+ }
646
+ }
608
647
609
648
?>
0 commit comments