1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Carbon_Fields\Field; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Date picker field class. |
7
|
|
|
*/ |
8
|
|
|
class Date_Field extends Field { |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Datepicker options |
12
|
|
|
*/ |
13
|
|
|
public $datepicker_options = array(); |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Returns an array that holds the field data, suitable for JSON representation. |
17
|
|
|
* This data will be available in the Underscore template and the Backbone Model. |
18
|
|
|
* |
19
|
|
|
* @param bool $load Should the value be loaded from the database or use the value from the current instance. |
20
|
|
|
* @return array |
21
|
|
|
*/ |
22
|
|
|
public function to_json( $load ) { |
23
|
|
|
$field_data = parent::to_json( $load ); |
24
|
|
|
|
25
|
|
|
$field_data = array_merge( $field_data, array( |
26
|
|
|
'options' => $this->datepicker_options, |
27
|
|
|
) ); |
28
|
|
|
|
29
|
|
|
return $field_data; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* The Underscore template of this field |
34
|
|
|
**/ |
35
|
|
|
public function template() { |
36
|
|
|
?> |
37
|
|
|
<div class="input-with-button"> |
38
|
|
|
<input id="{{{ id }}}" type="text" name="{{{ name }}}" value="{{ value }}" class="regular-text carbon-datepicker" /> |
39
|
|
|
<span class="carbon-datepicker-trigger button icon-button hide-if-no-js"><?php _e( 'Date', 'carbon_fields' ); ?></span> |
40
|
|
|
</div> |
41
|
|
|
<?php |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Hook administration scripts and styles. |
46
|
|
|
*/ |
47
|
|
|
public function admin_enqueue_scripts() { |
48
|
|
|
wp_enqueue_script( 'jquery-ui-datepicker' ); |
49
|
|
|
|
50
|
|
|
wp_enqueue_style( 'jquery-ui', '//code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.min.css' ); |
51
|
|
|
wp_enqueue_style( 'carbon-jquery-ui', \Carbon_Fields\URL . '/assets/css/jquery-ui.css' ); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* This function is depratected since it conflicts with the options concept in predefined option fields. |
56
|
|
|
* @deprecated |
57
|
|
|
*/ |
58
|
|
|
public function set_options( $options ) { |
59
|
|
|
return $this->set_datepicker_options( $options ); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Set datepicker options |
64
|
|
|
*/ |
65
|
|
|
public function set_datepicker_options( $options ) { |
66
|
|
|
$this->datepicker_options = $options; |
67
|
|
|
|
68
|
|
|
return $this; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|