PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / 6.4.0-beta2
Secure Custom Fields v6.4.0-beta2
6.9.5 6.9.4 6.9.3 6.9.2 6.9.1 6.9.0 6.8.9 6.8.7 6.8.8 6.8.6 6.8.4 6.8.5 trunk 6.4.0-beta1 6.4.0-beta2 6.4.1 6.4.1-beta3 6.4.1-beta4 6.4.1-beta5 6.4.1-beta6 6.4.1-beta7 6.4.2 6.5.0 6.5.1 6.5.2 6.5.3 6.5.4 6.5.5 6.5.6 6.5.7 6.6.0 6.7.0 6.7.1 6.8.0 6.8.1 6.8.2 6.8.3
secure-custom-fields / includes / fields / class-acf-field-date_time_picker.php
secure-custom-fields / includes / fields Last commit date
class-acf-field-accordion.php 1 year ago class-acf-field-button-group.php 1 year ago class-acf-field-checkbox.php 1 year ago class-acf-field-color_picker.php 1 year ago class-acf-field-date_picker.php 1 year ago class-acf-field-date_time_picker.php 1 year ago class-acf-field-email.php 1 year ago class-acf-field-file.php 1 year ago class-acf-field-google-map.php 1 year ago class-acf-field-group.php 1 year ago class-acf-field-icon_picker.php 1 year ago class-acf-field-image.php 1 year ago class-acf-field-link.php 1 year ago class-acf-field-message.php 1 year ago class-acf-field-number.php 1 year ago class-acf-field-oembed.php 1 year ago class-acf-field-output.php 1 year ago class-acf-field-page_link.php 1 year ago class-acf-field-password.php 1 year ago class-acf-field-post_object.php 1 year ago class-acf-field-radio.php 1 year ago class-acf-field-range.php 1 year ago class-acf-field-relationship.php 1 year ago class-acf-field-select.php 1 year ago class-acf-field-separator.php 1 year ago class-acf-field-tab.php 1 year ago class-acf-field-taxonomy.php 1 year ago class-acf-field-text.php 1 year ago class-acf-field-textarea.php 1 year ago class-acf-field-time_picker.php 1 year ago class-acf-field-true_false.php 1 year ago class-acf-field-url.php 1 year ago class-acf-field-user.php 1 year ago class-acf-field-wysiwyg.php 1 year ago class-acf-field.php 1 year ago index.php 1 year ago
class-acf-field-date_time_picker.php
276 lines
1 <?php
2
3 if ( ! class_exists( 'acf_field_date_and_time_picker' ) ) :
4
5 class acf_field_date_and_time_picker extends acf_field {
6
7
8 /**
9 * This function will setup the field type data
10 *
11 * @type function
12 * @date 5/03/2014
13 * @since 5.0.0
14 *
15 * @param n/a
16 * @return n/a
17 */
18 function initialize() {
19
20 // vars
21 $this->name = 'date_time_picker';
22 $this->label = __( 'Date Time Picker', 'acf' );
23 $this->category = 'advanced';
24 $this->description = __( 'An interactive UI for picking a date and time. The date return format can be customized using the field settings.', 'acf' );
25 $this->preview_image = acf_get_url() . '/assets/images/field-type-previews/field-preview-date-time.png';
26 $this->doc_url = 'https://www.advancedcustomfields.com/resources/date-time-picker/';
27 $this->defaults = array(
28 'display_format' => 'd/m/Y g:i a',
29 'return_format' => 'd/m/Y g:i a',
30 'first_day' => 1,
31 );
32 }
33
34
35 /**
36 * description
37 *
38 * @type function
39 * @date 16/12/2015
40 * @since 5.3.2
41 *
42 * @param $post_id (int)
43 * @return $post_id (int)
44 */
45 function input_admin_enqueue_scripts() {
46
47 // bail early if no enqueue
48 if ( ! acf_get_setting( 'enqueue_datetimepicker' ) ) {
49 return;
50 }
51
52 // vars
53 $version = '1.6.1';
54
55 // script
56 wp_enqueue_script( 'acf-timepicker', acf_get_url( 'assets/inc/timepicker/jquery-ui-timepicker-addon.min.js' ), array( 'jquery-ui-datepicker' ), $version );
57
58 // style
59 wp_enqueue_style( 'acf-timepicker', acf_get_url( 'assets/inc/timepicker/jquery-ui-timepicker-addon.min.css' ), '', $version );
60
61 // localize
62 acf_localize_data(
63 array(
64 'dateTimePickerL10n' => array(
65 'timeOnlyTitle' => _x( 'Choose Time', 'Date Time Picker JS timeOnlyTitle', 'acf' ),
66 'timeText' => _x( 'Time', 'Date Time Picker JS timeText', 'acf' ),
67 'hourText' => _x( 'Hour', 'Date Time Picker JS hourText', 'acf' ),
68 'minuteText' => _x( 'Minute', 'Date Time Picker JS minuteText', 'acf' ),
69 'secondText' => _x( 'Second', 'Date Time Picker JS secondText', 'acf' ),
70 'millisecText' => _x( 'Millisecond', 'Date Time Picker JS millisecText', 'acf' ),
71 'microsecText' => _x( 'Microsecond', 'Date Time Picker JS microsecText', 'acf' ),
72 'timezoneText' => _x( 'Time Zone', 'Date Time Picker JS timezoneText', 'acf' ),
73 'currentText' => _x( 'Now', 'Date Time Picker JS currentText', 'acf' ),
74 'closeText' => _x( 'Done', 'Date Time Picker JS closeText', 'acf' ),
75 'selectText' => _x( 'Select', 'Date Time Picker JS selectText', 'acf' ),
76 'amNames' => array(
77 _x( 'AM', 'Date Time Picker JS amText', 'acf' ),
78 _x( 'A', 'Date Time Picker JS amTextShort', 'acf' ),
79 ),
80 'pmNames' => array(
81 _x( 'PM', 'Date Time Picker JS pmText', 'acf' ),
82 _x( 'P', 'Date Time Picker JS pmTextShort', 'acf' ),
83 ),
84 ),
85 )
86 );
87 }
88
89
90 /**
91 * Create the HTML interface for your field
92 *
93 * @param $field - an array holding all the field's data
94 *
95 * @type action
96 * @since 3.6
97 * @date 23/01/13
98 */
99 function render_field( $field ) {
100
101 // Set value.
102 $hidden_value = '';
103 $display_value = '';
104
105 if ( $field['value'] ) {
106 $hidden_value = acf_format_date( $field['value'], 'Y-m-d H:i:s' );
107 $display_value = acf_format_date( $field['value'], $field['display_format'] );
108 }
109
110 // Convert "display_format" setting to individual date and time formats.
111 $formats = acf_split_date_time( $field['display_format'] );
112
113 // Elements.
114 $div = array(
115 'class' => 'acf-date-time-picker acf-input-wrap',
116 'data-date_format' => acf_convert_date_to_js( $formats['date'] ),
117 'data-time_format' => acf_convert_time_to_js( $formats['time'] ),
118 'data-first_day' => $field['first_day'],
119 );
120 $hidden_input = array(
121 'id' => $field['id'],
122 'class' => 'input-alt',
123 'name' => $field['name'],
124 'value' => $hidden_value,
125 );
126 $text_input = array(
127 'class' => $field['class'] . ' input',
128 'value' => $display_value,
129 );
130 foreach ( array( 'readonly', 'disabled' ) as $k ) {
131 if ( ! empty( $field[ $k ] ) ) {
132 $hidden_input[ $k ] = $k;
133 $text_input[ $k ] = $k;
134 }
135 }
136
137 // Output.
138 ?>
139 <div <?php echo acf_esc_attrs( $div ); ?>>
140 <?php acf_hidden_input( $hidden_input ); ?>
141 <?php acf_text_input( $text_input ); ?>
142 </div>
143 <?php
144 }
145
146
147 /**
148 * Create extra options for your field. This is rendered when editing a field.
149 * The value of $field['name'] can be used (like bellow) to save extra data to the $field
150 *
151 * @type action
152 * @since 3.6
153 * @date 23/01/13
154 *
155 * @param $field - an array holding all the field's data
156 */
157 function render_field_settings( $field ) {
158 global $wp_locale;
159
160 $d_m_Y = date_i18n( 'd/m/Y g:i a' );
161 $m_d_Y = date_i18n( 'm/d/Y g:i a' );
162 $F_j_Y = date_i18n( 'F j, Y g:i a' );
163 $Ymd = date_i18n( 'Y-m-d H:i:s' );
164
165 echo '<div class="acf-field-settings-split">';
166
167 acf_render_field_setting(
168 $field,
169 array(
170 'label' => __( 'Display Format', 'acf' ),
171 'hint' => __( 'The format displayed when editing a post', 'acf' ),
172 'type' => 'radio',
173 'name' => 'display_format',
174 'other_choice' => 1,
175 'choices' => array(
176 'd/m/Y g:i a' => '<span>' . $d_m_Y . '</span><code>d/m/Y g:i a</code>',
177 'm/d/Y g:i a' => '<span>' . $m_d_Y . '</span><code>m/d/Y g:i a</code>',
178 'F j, Y g:i a' => '<span>' . $F_j_Y . '</span><code>F j, Y g:i a</code>',
179 'Y-m-d H:i:s' => '<span>' . $Ymd . '</span><code>Y-m-d H:i:s</code>',
180 'other' => '<span>' . __( 'Custom:', 'acf' ) . '</span>',
181 ),
182 )
183 );
184
185 acf_render_field_setting(
186 $field,
187 array(
188 'label' => __( 'Return Format', 'acf' ),
189 'hint' => __( 'The format returned via template functions', 'acf' ),
190 'type' => 'radio',
191 'name' => 'return_format',
192 'other_choice' => 1,
193 'choices' => array(
194 'd/m/Y g:i a' => '<span>' . $d_m_Y . '</span><code>d/m/Y g:i a</code>',
195 'm/d/Y g:i a' => '<span>' . $m_d_Y . '</span><code>m/d/Y g:i a</code>',
196 'F j, Y g:i a' => '<span>' . $F_j_Y . '</span><code>F j, Y g:i a</code>',
197 'Y-m-d H:i:s' => '<span>' . $Ymd . '</span><code>Y-m-d H:i:s</code>',
198 'other' => '<span>' . __( 'Custom:', 'acf' ) . '</span>',
199 ),
200 )
201 );
202
203 echo '</div>';
204
205 acf_render_field_setting(
206 $field,
207 array(
208 'label' => __( 'Week Starts On', 'acf' ),
209 'instructions' => '',
210 'type' => 'select',
211 'name' => 'first_day',
212 'choices' => array_values( $wp_locale->weekday ),
213 )
214 );
215 }
216
217 /**
218 * This filter is appied to the $value after it is loaded from the db and before it is returned to the template
219 *
220 * @type filter
221 * @since 3.6
222 *
223 * @param mixed $value The value which was loaded from the database
224 * @param mixed $post_id The post_id from which the value was loaded
225 * @param array $field The field array holding all the field options
226 * @return mixed $value The modified value
227 */
228 public function format_value( $value, $post_id, $field ) {
229 return acf_format_date( $value, $field['return_format'] );
230 }
231
232
233 /**
234 * This filter is applied to the $field after it is loaded from the database
235 * and ensures the return and display values are set.
236 *
237 * @type filter
238 * @since 5.11.0
239 *
240 * @param array $field The field array holding all the field options.
241 * @return array
242 */
243 public function load_field( $field ) {
244 if ( empty( $field['display_format'] ) ) {
245 $field['display_format'] = $this->defaults['display_format'];
246 }
247
248 if ( empty( $field['return_format'] ) ) {
249 $field['return_format'] = $this->defaults['return_format'];
250 }
251
252 return $field;
253 }
254
255 /**
256 * Return the schema array for the REST API.
257 *
258 * @param array $field
259 * @return array
260 */
261 public function get_rest_schema( array $field ) {
262 return array(
263 'type' => array( 'string', 'null' ),
264 'description' => 'A `Y-m-d H:i:s` formatted date string.',
265 'required' => ! empty( $field['required'] ),
266 );
267 }
268 }
269
270
271 // initialize
272 acf_register_field_type( 'acf_field_date_and_time_picker' );
273 endif; // class_exists check
274
275 ?>
276